/* Initialize EVENT thread */ static int ovs_db_event_thread_init(ovs_db_t *pdb) { pdb->event_thread.tid = (pthread_t){0}; /* init event thread condition variable */ if (pthread_cond_init(&pdb->event_thread.cond, NULL)) { return -1; } /* init event thread mutex */ if (pthread_mutex_init(&pdb->event_thread.mutex, NULL)) { pthread_cond_destroy(&pdb->event_thread.cond); return -1; } /* Hold the event thread mutex. It ensures that no events * will be lost while thread is still starting. Once event * thread is started and ready to accept events, it will release * the mutex */ if (pthread_mutex_lock(&pdb->event_thread.mutex)) { pthread_mutex_destroy(&pdb->event_thread.mutex); pthread_cond_destroy(&pdb->event_thread.cond); return -1; } /* start event thread */ pthread_t tid; if (plugin_thread_create(&tid, NULL, ovs_event_worker, pdb, "utils_ovs:event") != 0) { pthread_mutex_unlock(&pdb->event_thread.mutex); pthread_mutex_destroy(&pdb->event_thread.mutex); pthread_cond_destroy(&pdb->event_thread.cond); return -1; } pdb->event_thread.tid = tid; return 0; }
static int camqp_subscribe_init (camqp_config_t *conf) /* {{{ */ { int status; pthread_t *tmp; tmp = realloc (subscriber_threads, sizeof (*subscriber_threads) * (subscriber_threads_num + 1)); if (tmp == NULL) { ERROR ("amqp plugin: realloc failed."); camqp_config_free (conf); return (ENOMEM); } subscriber_threads = tmp; tmp = subscriber_threads + subscriber_threads_num; memset (tmp, 0, sizeof (*tmp)); status = plugin_thread_create (tmp, /* attr = */ NULL, camqp_subscribe_thread, conf); if (status != 0) { char errbuf[1024]; ERROR ("amqp plugin: pthread_create failed: %s", sstrerror (status, errbuf, sizeof (errbuf))); camqp_config_free (conf); return (status); } subscriber_threads_num++; return (0); } /* }}} int camqp_subscribe_init */
static int start_thread (void) /* {{{ */ { int status; pthread_mutex_lock (&ping_lock); if (ping_thread_loop != 0) { pthread_mutex_unlock (&ping_lock); return (-1); } ping_thread_loop = 1; ping_thread_error = 0; status = plugin_thread_create (&ping_thread_id, /* attr = */ NULL, ping_thread, /* arg = */ (void *) 0); if (status != 0) { ping_thread_loop = 0; ERROR ("ping plugin: Starting thread failed."); pthread_mutex_unlock (&ping_lock); return (-1); } pthread_mutex_unlock (&ping_lock); return (0); } /* }}} int start_thread */
static int camqp_subscribe_init(camqp_config_t *conf) /* {{{ */ { int status; pthread_t *tmp; tmp = realloc(subscriber_threads, sizeof(*subscriber_threads) * (subscriber_threads_num + 1)); if (tmp == NULL) { ERROR("amqp plugin: realloc failed."); sfree(subscriber_threads); return ENOMEM; } subscriber_threads = tmp; tmp = subscriber_threads + subscriber_threads_num; memset(tmp, 0, sizeof(*tmp)); status = plugin_thread_create(tmp, /* attr = */ NULL, camqp_subscribe_thread, conf, "amqp subscribe"); if (status != 0) { ERROR("amqp plugin: pthread_create failed: %s", STRERROR(status)); return status; } subscriber_threads_num++; return 0; } /* }}} int camqp_subscribe_init */
/* Initialize POLL thread */ static int ovs_db_poll_thread_init(ovs_db_t *pdb) { pdb->poll_thread.tid = (pthread_t){0}; /* init event thread mutex */ if (pthread_mutex_init(&pdb->poll_thread.mutex, NULL)) { return -1; } /* start poll thread */ pthread_t tid; pdb->poll_thread.state = OVS_DB_POLL_STATE_RUNNING; if (plugin_thread_create(&tid, NULL, ovs_poll_worker, pdb, "utils_ovs:poll") != 0) { pthread_mutex_destroy(&pdb->poll_thread.mutex); return -1; } pdb->poll_thread.tid = tid; return 0; }
static int statsd_init (void) /* {{{ */ { int thread_num = 0; for (thread_num = 0; thread_num < statsd_threads_num; thread_num++) { int status = 0; status = plugin_thread_create (&statsd_threads[thread_num].thr, /* attr = */ NULL, statsd_network_thread, statsd_threads[thread_num].conf); if (status != 0) { char errbuf[1024] = {0}; ERROR ("statsd plugin: pthread_create failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); return (status); } } return (0); } /* }}} int statsd_init */
static int mc_receive_thread_start(void) /* {{{ */ { int status; if (mc_receive_thread_running != 0) return (-1); mc_receive_thread_loop = 1; status = plugin_thread_create(&mc_receive_thread_id, /* attr = */ NULL, mc_receive_thread, /* args = */ NULL, "gmond recv"); if (status != 0) { ERROR("gmond plugin: Starting receive thread failed."); mc_receive_thread_loop = 0; return (-1); } mc_receive_thread_running = 1; return (0); } /* }}} int start_receive_thread */
/** * Init. */ static int cgps_init (void) { int status; if (cgps_thread_running == CGPS_TRUE) { DEBUG ("gps plugin: error gps thread already running ... "); return 0; } DEBUG ("gps plugin: config{host: \"%s\", port: \"%s\", timeout: %.6f sec., pause connect: %.3f sec.}", cgps_config_data.host, cgps_config_data.port, CDTIME_T_TO_DOUBLE (cgps_config_data.timeout), CDTIME_T_TO_DOUBLE (cgps_config_data.pause_connect)); status = plugin_thread_create (&cgps_thread_id, NULL, cgps_thread, NULL); if (status != 0) { ERROR ("gps plugin: pthread_create() failed."); return (-1); } return (0); }