153
155
int error; // Used when debugging
154
157
if (shutdown_in_progress && !abort_loop)
160
164
while ((error= sigwait(&set,&sig)) == EINTR) ;
161
167
if (cleanup_done)
163
169
internal::my_thread_end();
164
170
signal_thread_in_use= false;
195
201
SignalHandler(const SignalHandler &);
196
202
SignalHandler& operator=(const SignalHandler &);
203
boost::thread thread;
199
: drizzled::plugin::Daemon("Signal Handler")
207
drizzled::plugin::Daemon("Signal Handler")
202
pthread_attr_t thr_attr;
203
size_t my_thread_stack_size= 65536;
205
(void) pthread_attr_init(&thr_attr);
206
pthread_attr_setscope(&thr_attr, PTHREAD_SCOPE_SYSTEM);
207
(void) pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED);
209
struct sched_param tmp_sched_param;
211
memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
212
tmp_sched_param.sched_priority= INTERRUPT_PRIOR;
213
(void)pthread_attr_setschedparam(&thr_attr, &tmp_sched_param);
215
#if defined(__ia64__) || defined(__ia64)
217
Peculiar things with ia64 platforms - it seems we only have half the
218
stack size in reality, so we have to double it here
220
pthread_attr_setstacksize(&thr_attr, my_thread_stack_size*2);
222
pthread_attr_setstacksize(&thr_attr, my_thread_stack_size);
225
209
// @todo fix spurious wakeup issue
226
(void) LOCK_thread_count.lock();
227
if ((error= pthread_create(&signal_thread, &thr_attr, signal_hand, 0)))
229
errmsg_printf(ERRMSG_LVL_ERROR,
230
_("Can't create interrupt-thread (error %d, errno: %d)"),
234
pthread_cond_wait(COND_thread_count.native_handle(), LOCK_thread_count.native_handle());
235
LOCK_thread_count.unlock();
237
(void) pthread_attr_destroy(&thr_attr);
210
boost::mutex::scoped_lock scopedLock(LOCK_thread_count);
211
thread= boost::thread(signal_hand);
212
signal_thread= thread.native_handle();
213
COND_thread_count.wait(scopedLock);
247
223
Wait up to 100000 micro-seconds for signal thread to die. We use this mainly to
248
224
avoid getting warnings that internal::my_thread_end has not been called
250
for (uint32_t i= 0 ; i < 100 && signal_thread_in_use; i++)
252
if (pthread_kill(signal_thread, SIGTERM) != ESRCH)
259
nanosleep(&tm, NULL); // Give it time to die
226
pthread_kill(signal_thread, SIGTERM);
265
231
static int init(drizzled::module::Context& context)
267
SignalHandler *handler= new SignalHandler;
268
context.add(handler);
233
context.add(new SignalHandler);