~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/sleep/sleep.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 * Copyright 2009 Sun Microsystems
 
4
 * Copyright (C) 2009 Sun Microsystems, Inc.
5
5
 *
6
6
 * Authors:
7
7
 *
69
69
 
70
70
int64_t Item_func_sleep::val_int()
71
71
{
72
 
  int error= 0;
73
 
 
74
72
  /* int time in seconds, decimal allowed */
75
73
  double dtime;
76
74
 
77
 
  struct timespec abstime;
78
 
 
79
 
  pthread_cond_t cond;
80
 
 
81
 
  Session *session= current_session;
 
75
  Session &session(getSession());
82
76
 
83
77
  if ((arg_count != 1) || ! (dtime= args[0]->val_real()))
84
78
  {
98
92
  if (dtime < 0.00001)
99
93
    return 0;
100
94
 
101
 
  /* need to obtain time value for passing to cond_timedwait */
102
 
  set_timespec_nsec(abstime, (uint64_t)(dtime * 1000000000ULL));
103
 
 
104
 
  pthread_mutex_init(&LOCK_sleep, MY_MUTEX_INIT_FAST);
105
 
  pthread_cond_init(&cond, NULL);
106
 
 
107
 
  /* don't run if not killed */
108
 
  pthread_mutex_lock(&LOCK_sleep);
109
 
  while (not session->getKilled())
110
95
  {
111
 
    error= pthread_cond_timedwait(&cond, &LOCK_sleep, &abstime);
112
 
    if (error == ETIMEDOUT || error == ETIME)
 
96
    boost::this_thread::restore_interruption dl(session.getThreadInterupt());
 
97
 
 
98
    try {
 
99
      boost::xtime xt; 
 
100
      xtime_get(&xt, boost::TIME_UTC); 
 
101
      xt.nsec += (uint64_t)(dtime * 1000000000ULL); 
 
102
      session.getThread()->sleep(xt);
 
103
    }
 
104
    catch(boost::thread_interrupted const& error)
113
105
    {
114
 
      break;
 
106
      my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
 
107
      null_value= true;
 
108
 
 
109
      return 0;
115
110
    }
116
 
    error= 0;
117
111
  }
118
 
  pthread_mutex_unlock(&LOCK_sleep);
119
112
 
120
 
  /* relenquish pthread cond */
121
 
  pthread_cond_destroy(&cond);
122
 
  pthread_mutex_destroy(&LOCK_sleep);
123
113
 
124
114
  null_value= false;
125
115
 
126
116
  return (int64_t) 0;
127
117
}
128
118
 
129
 
plugin::Create_function<Item_func_sleep> *sleep_udf= NULL;
130
 
 
131
119
static int sleep_plugin_init(drizzled::module::Context &context)
132
120
{
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"));
135
122
 
136
123
  return 0;
137
124
}