Example #1
0
/* returns true if callback was called directly */
static gboolean collect_insert_func(liServer *srv, liWorker *ctx, liCollectInfo *ci) {
	guint i;
	for (i = 0; i < srv->worker_count; i++) {
		liWorker *wrk;
		wrk = g_array_index(srv->workers, liWorker*, i);
		if (wrk == ctx) {
			/* we are in the destiation context */
			g_ptr_array_index(ci->results, wrk->ndx) = ci->func(wrk, ci->fdata);
			if (collect_send_result(wrk, ci)) return TRUE;
		} else {
			collect_job *j = g_slice_new(collect_job);
			j->type = COLLECT_FUNC;
			j->ci = ci;
			g_async_queue_push(wrk->collect_queue, j);
			li_event_async_send(&wrk->collect_watcher);
		}
	}
	return FALSE;
}
Example #2
0
void li_collect_watcher_cb(liEventBase *watcher, int events) {
	liWorker *wrk = LI_CONTAINER_OF(li_event_async_from(watcher), liWorker, collect_watcher);
	collect_job *j;
	UNUSED(events);

	while (NULL != (j = (collect_job*) g_async_queue_try_pop(wrk->collect_queue))) {
		liCollectInfo *ci = j->ci;
		switch (j->type) {
		case COLLECT_FUNC:
			g_ptr_array_index(ci->results, wrk->ndx) = ci->func(wrk, ci->fdata);
			collect_send_result(wrk, ci);
			break;
		case COLLECT_CB:
			ci->cb(ci->cbdata, ci->fdata, ci->results, !ci->stopped);
			collect_info_free(ci);
			break;
		}
		g_slice_free(collect_job, j);
	}
}
Example #3
0
void li_collect_watcher_cb(struct ev_loop *loop, ev_async *w, int revents) {
	liWorker *wrk = (liWorker*) w->data;
	collect_job *j;
	UNUSED(loop);
	UNUSED(revents);

	while (NULL != (j = (collect_job*) g_async_queue_try_pop(wrk->collect_queue))) {
		liCollectInfo *ci = j->ci;
		switch (j->type) {
		case COLLECT_FUNC:
			g_ptr_array_index(ci->results, wrk->ndx) = ci->func(wrk, ci->fdata);
			collect_send_result(wrk, ci);
			break;
		case COLLECT_CB:
			ci->cb(ci->cbdata, ci->fdata, ci->results, !ci->stopped);
			collect_info_free(ci);
			break;
		}
		g_slice_free(collect_job, j);
	}
}