eventer_t eventer_alloc() { eventer_t e; e = calloc(1, sizeof(*e)); e->thr_owner = pthread_self(); e->opset = eventer_POSIX_fd_opset; e->refcnt = 1; mtev_atomic_inc64(&ealloccnt); mtev_atomic_inc64(&ealloctotal); return e; }
static void distribute_message_with_interests(caql_cnt_t *interests, noit_metric_message_t *message) { mtev_atomic_inc64(&number_of_messages_received); int i; for(i = 0; i < nthreads; i++) { if(interests[i] > 0) { ck_fifo_spsc_t *fifo = (ck_fifo_spsc_t *) thread_queues[i]; ck_fifo_spsc_entry_t *fifo_entry; ck_fifo_spsc_enqueue_lock(fifo); fifo_entry = ck_fifo_spsc_recycle(fifo); if(!fifo_entry) fifo_entry = malloc(sizeof(ck_fifo_spsc_entry_t)); noit_metric_director_message_ref(message); ck_fifo_spsc_enqueue(fifo, fifo_entry, message); ck_fifo_spsc_enqueue_unlock(fifo); mtev_atomic_inc64(&number_of_messages_distributed); } } }
static iep_thread_driver_t *noit_rabbimq_allocate(mtev_conf_section_t conf) { char *hostname = NULL, *cp, *brk; struct amqp_driver *dr = NULL; int i; pthread_mutex_lock(&driver_lock); for(i=0; i<MAX_HOSTS; i++) { if(stats.thread_states[i].owner == (pthread_t)(intptr_t)NULL) { stats.thread_states[i].owner = pthread_self(); dr = &stats.thread_states[i]; break; } } pthread_mutex_unlock(&driver_lock); if(!dr) return NULL; dr->nconnects = rand(); #define GETCONFSTR(w) mtev_conf_get_stringbuf(conf, #w, dr->w, sizeof(dr->w)) GETCONFSTR(exchange); if(!GETCONFSTR(routingkey)) dr->routingkey[0] = '\0'; GETCONFSTR(username); GETCONFSTR(password); if(!GETCONFSTR(vhost)) { dr->vhost[0] = '/'; dr->vhost[1] = '\0'; } if(!mtev_conf_get_int(conf, "heartbeat", &dr->heartbeat)) dr->heartbeat = 5000; dr->heartbeat = (dr->heartbeat + 999) / 1000; (void)mtev_conf_get_string(conf, "hostname", &hostname); if(!hostname) hostname = strdup("127.0.0.1"); for(cp = hostname; cp; cp = strchr(cp+1, ',')) dr->nhosts++; if(dr->nhosts > MAX_HOSTS) dr->nhosts = MAX_HOSTS; for(i = 0, cp = strtok_r(hostname, ",", &brk); cp; cp = strtok_r(NULL, ",", &brk), i++) strlcpy(dr->hostname[i], cp, sizeof(dr->hostname[i])); free(hostname); if(!mtev_conf_get_int(conf, "port", &dr->port)) dr->port = 5672; mtev_atomic_inc64(&stats.concurrency); return (iep_thread_driver_t *)dr; }