1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright 2009 Sun Microsystems
4
* Copyright (C) 2009 Sun Microsystems, Inc.
70
70
int64_t Item_func_sleep::val_int()
74
72
/* int time in seconds, decimal allowed */
77
struct timespec abstime;
81
Session *session= current_session;
75
Session &session(getSession());
83
77
if ((arg_count != 1) || ! (dtime= args[0]->val_real()))
98
92
if (dtime < 0.00001)
101
/* need to obtain time value for passing to cond_timedwait */
102
set_timespec_nsec(abstime, (uint64_t)(dtime * 1000000000ULL));
104
pthread_mutex_init(&LOCK_sleep, MY_MUTEX_INIT_FAST);
105
pthread_cond_init(&cond, NULL);
107
/* don't run if not killed */
108
pthread_mutex_lock(&LOCK_sleep);
109
while (not session->getKilled())
111
error= pthread_cond_timedwait(&cond, &LOCK_sleep, &abstime);
112
if (error == ETIMEDOUT || error == ETIME)
96
boost::this_thread::restore_interruption dl(session.getThreadInterupt());
100
xtime_get(&xt, boost::TIME_UTC);
101
xt.nsec += (uint64_t)(dtime * 1000000000ULL);
102
session.getThread()->sleep(xt);
104
catch(boost::thread_interrupted const& error)
106
my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
118
pthread_mutex_unlock(&LOCK_sleep);
120
/* relenquish pthread cond */
121
pthread_cond_destroy(&cond);
122
pthread_mutex_destroy(&LOCK_sleep);
124
114
null_value= false;
126
116
return (int64_t) 0;
129
plugin::Create_function<Item_func_sleep> *sleep_udf= NULL;
131
119
static int sleep_plugin_init(drizzled::module::Context &context)
133
sleep_udf= new plugin::Create_function<Item_func_sleep>("sleep");
134
context.add(sleep_udf);
121
context.add(new plugin::Create_function<Item_func_sleep>("sleep"));