static void run_fun(iochan_man_t man, IOCHAN p) { if (p->this_event) { if (man->sel_thread) { yaz_log(man->log_level, "eventl: work add chan=%p name=%s event=%d", p, p->name ? p->name : "", p->this_event); p->thread_users++; sel_thread_add(man->sel_thread, p); } else work_handler(p); } }
static void system_activity_monitor(void) { struct sigaction act; sigset_t sigmask; /* * Setup for gathering system's statistic. */ sysstat_init(); /* * In addition to the SIGQUIT, SIGINT and SIGTERM signals already * being handled, this thread also needs to handle SIGHUP, SIGALRM * and SIGTHAW signals. */ (void) sigemptyset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = alarm_handler; (void) sigaction(SIGALRM, &act, NULL); act.sa_handler = work_handler; (void) sigaction(SIGHUP, &act, NULL); act.sa_handler = thaw_handler; (void) sigaction(SIGTHAW, &act, NULL); /* * Invoke work_handler with a dummy SIGHUP signal to read * cpr config file, get autoshutdown properties and schedule * an alarm if needed. */ work_handler(SIGHUP); /* * Wait for signal to read file */ (void) thr_sigsetmask(0, 0, &sigmask); (void) sigdelset(&sigmask, SIGHUP); (void) sigdelset(&sigmask, SIGALRM); (void) sigdelset(&sigmask, SIGTHAW); (void) thr_sigsetmask(SIG_SETMASK, &sigmask, NULL); do { (void) sigsuspend(&sigmask); } while (errno == EINTR); }
static void * eq_worker_th(void *eqwptr) { Lisp_Object ljob = Qnil; worker_job_t job = NULL; eq_worker_t eqw = eqwptr; work_handler_t hdl; struct gcpro gcpro1; eq_worker_th_blksig(); GCPRO1(ljob); listen: eq_queue_synch(delegate_eq); EQUEUE_DEBUG_WORKER("dequeuing thread: 0x%lx\n", (long unsigned int)pthread_self()); /* fetch one event now */ refetch: ljob = Qnil; eq_dequeue_pro(&ljob, delegate_eq); if (NILP(ljob)) { EQUEUE_DEBUG_WORKER("No event on the queue. " "Who dared to wake me up?! >8(\n"); goto listen; } eq_lock_meself(eqw); job = XWORKER_JOB(ljob); hdl = XWORKER_JOB_HANDLER(ljob); EQUEUE_DEBUG_WORKER("escrowing event 0x%lx in worker 0x%lx.\n", (long unsigned int)job, (long unsigned int)eqw); /* maybe it's a eat-yourself ticket? */ if (hdl == &eat_yerself) { /* awww ... we gotta exit :( */ EQUEUE_DEBUG_WORKER( "Worker 0x%lx commits suicide...\n", (long unsigned int)eqw); eq_unlock_meself(eqw); eq_worker_eaten_myself(eqw); UNGCPRO; pthread_exit(NULL); return NULL; } /* help the job a bit with local resources */ EQUEUE_DEBUG_SCRATCH("inherit scratch buffer 0x%lx of size %ld\n", (long unsigned int)eq_worker_scratch(eqw), eq_worker_scratch_alloc_size(eqw)); worker_job_buffer(job) = eq_worker_scratch(eqw); worker_job_buffer_alloc_size(job) = eq_worker_scratch_alloc_size(eqw); /* generate a started event and update job state */ worker_job_state(job) = WORKER_JOB_RUNNING; eq_worker_work_started(ljob); /* ... otherwise handle the event */ work_handler(hdl)(job); /* generate a `finished' event, * sentinel code shall be injected in the routine * called by eq_worker_handle_event() */ worker_job_state(job) = WORKER_JOB_FINISHED; eq_worker_work_finished(ljob); eq_unlock_meself(eqw); EQUEUE_DEBUG_WORKER("enqueuing thread: 0x%lx\n", (long unsigned int)pthread_self()); goto refetch; /* not reached */ return NULL; }