static void *service_thread(void *data) { struct sched_context *con = data; cw_mutex_lock(&con->lock); pthread_cleanup_push((void (*)(void *))cw_mutex_unlock, &con->lock); for (;;) { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); if (con->schedq) { struct timespec tick; tick.tv_sec = con->schedq->when.tv_sec; tick.tv_nsec = 1000 * con->schedq->when.tv_usec; while (cw_cond_timedwait(&con->service, &con->lock, &tick) < 0 && errno == EINTR); } else { while (cw_cond_wait(&con->service, &con->lock) < 0 && errno == EINTR); } pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); cw_sched_runq(con); } pthread_cleanup_pop(1); return NULL; }
static void *database_queue_thread_main(void *data) { cw_mutex_lock(&db_condition_lock); for ( ;; ) { if ( db_list_head ) { //cw_log(LOG_ERROR,"DB DO SAVE OUR LIST\n"); database_flush_cache(); sleep( CACHE_COMMIT_INTERVAL ); } else { cw_cond_wait(&db_condition_save, &db_condition_lock); /* //cw_log(LOG_ERROR,"DB SAVE CONDITION RECEIVED\n"); db_list_t *e = db_list_head; cw_log(LOG_ERROR,"QUEUE NOW IS:\n"); while ( e ) { if ( e->sql ) cw_log(LOG_ERROR,"ITEM: %s\n",e->sql); e = e->next; } */ } } cw_mutex_unlock(&db_condition_lock); return NULL; }
static void *icd_distributor__match_agent_run(void *that) { icd_distributor *dist; icd_status result; assert(that != NULL); assert(((icd_distributor *)that)->customers != NULL); assert(((icd_distributor *)that)->agents != NULL); dist = (icd_distributor *)that; while (dist->thread_state != ICD_THREAD_STATE_FINISHED) { if (dist->thread_state == ICD_THREAD_STATE_RUNNING) { result = icd_distributor__lock(dist); /* Distribute callers if we can, or pause until some are added */ while(icd_distributor__get_added_callers_number(dist) > 0){ icd_distributor__reset_added_callers_number(dist); if (icd_distributor__customers_pending(dist) && icd_distributor__agents_pending(dist)) { result = icd_distributor__unlock(dist); /* func ptr to the icd_distributor__link_callers_via_?? note may also come from custom * function eg from icd_mod_?? installed using icd_distributor__set_link_callers_fn */ if (icd_verbose > 4) cw_verbose(VERBOSE_PREFIX_3 "Distributor__run [%s] link_fn[%p] \n", icd_distributor__get_name(dist), dist->link_fn); result = dist->link_fn(dist, dist->link_fn_extra); result = icd_distributor__lock(dist); } } /* All distributor links are now created wait for changes of customer or agent list */ cw_cond_wait(&(dist->wakeup), &(dist->lock)); /* wait until signal received */ result = icd_distributor__unlock(dist); if (icd_verbose > 4) cw_verbose(VERBOSE_PREFIX_3 "Distributor__run [%s] wait \n", icd_distributor__get_name(dist)); } else { /* TBD - Make paused thread work better. * - Use pthread_cond_wait() * - Use same or different condition variable? */ } /* Play nice */ sched_yield(); } /* Do any cleanup here */ return NULL; }