static void iv_work_thread(void *_thr) { struct work_pool_thread *thr = _thr; struct work_pool_priv *pool = thr->pool; iv_init(); INIT_IV_LIST_HEAD(&thr->list); thr->kicked = 0; IV_EVENT_INIT(&thr->kick); thr->kick.cookie = thr; thr->kick.handler = iv_work_thread_got_event; iv_event_register(&thr->kick); IV_TIMER_INIT(&thr->idle_timer); thr->idle_timer.cookie = thr; thr->idle_timer.handler = iv_work_thread_idle_timeout; if (pool->thread_start != NULL) pool->thread_start(pool->cookie); iv_event_post(&thr->kick); iv_main(); iv_deinit(); }
static void log_threaded_dest_driver_worker_thread_main(gpointer arg) { LogThrDestDriver *self = (LogThrDestDriver *)arg; iv_init(); msg_debug("Worker thread started", evt_tag_str("driver", self->super.super.id), NULL); log_queue_set_use_backlog(self->queue, TRUE); log_threaded_dest_driver_init_watches(self); log_threaded_dest_driver_start_watches(self); if (self->worker.thread_init) self->worker.thread_init(self); iv_main(); __disconnect(self); if (self->worker.thread_deinit) self->worker.thread_deinit(self); msg_debug("Worker thread finished", evt_tag_str("driver", self->super.super.id), NULL); iv_deinit(); }
static gpointer _threaded_consume(gpointer st) { LogQueue *q = (LogQueue *) st; LogMessage *msg; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; gint loops = 0; gint msg_count = 0; /* just to make sure time is properly cached */ iv_init(); while (msg_count < MESSAGES_SUM) { gint slept = 0; msg = NULL; while((msg = log_queue_pop_head(q, &path_options)) == NULL) { struct timespec ns; /* sleep 1 msec */ ns.tv_sec = 0; ns.tv_nsec = 1000000; nanosleep(&ns, NULL); slept++; if (slept > 10000) { /* slept for more than 10 seconds */ fprintf(stderr, "The wait for messages took too much time, loops=%d, msg_count=%d\n", loops, msg_count); return GUINT_TO_POINTER(1); } } if ((loops % 10) == 0) { /* push the message back to the queue */ log_queue_push_head(q, msg, &path_options); } else { log_msg_ack(msg, &path_options, AT_PROCESSED); log_msg_unref(msg); msg_count++; } loops++; } iv_deinit(); return NULL; }
void app_shutdown(void) { run_application_hook(AH_SHUTDOWN); log_template_global_deinit(); log_tags_deinit(); log_msg_global_deinit(); stats_destroy(); dns_cache_destroy(); child_manager_deinit(); g_list_foreach(application_hooks, (GFunc) g_free, NULL); g_list_free(application_hooks); msg_deinit(); iv_deinit(); }
int main() { struct req req[NUM]; int i; iv_init(); for (i = 0; i < NUM; i++) open_child_request(&req[i]); iv_main(); iv_deinit(); return 0; }
int main() { iv_init(); IV_EVENT_RAW_INIT(&ev0); ev0.handler = gotev0; iv_event_raw_register(&ev0); iv_event_raw_post(&ev0); iv_main(); iv_deinit(); return 0; }
static void thr_child(void *_dummy) { iv_init(); IV_EVENT_INIT(&ev_child); ev_child.handler = got_ev_child; iv_event_register(&ev_child); iv_validate_now(); tim_start = iv_now; iv_event_post(&ev_parent); iv_main(); iv_deinit(); }
gpointer threaded_feed(gpointer args) { LogQueue *q = args; char *msg_str = "<155>2006-02-11T10:34:56+01:00 bzorp syslog-ng[23323]: árvíztűrőtükörfúrógép"; gint msg_len = strlen(msg_str); gint i; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; LogMessage *msg, *tmpl; GTimeVal start, end; GSockAddr *sa; glong diff; iv_init(); /* emulate main loop for LogQueue */ main_loop_worker_thread_start(NULL); sa = g_sockaddr_inet_new("10.10.10.10", 1010); tmpl = log_msg_new(msg_str, msg_len, sa, &parse_options); g_sockaddr_unref(sa); g_get_current_time(&start); for (i = 0; i < MESSAGES_PER_FEEDER; i++) { msg = log_msg_clone_cow(tmpl, &path_options); log_msg_add_ack(msg, &path_options); msg->ack_func = test_ack; log_queue_push_tail(q, msg, &path_options); if ((i & 0xFF) == 0) main_loop_worker_invoke_batch_callbacks(); } main_loop_worker_invoke_batch_callbacks(); g_get_current_time(&end); diff = g_time_val_diff(&end, &start); g_static_mutex_lock(&tlock); sum_time += diff; g_static_mutex_unlock(&tlock); log_msg_unref(tmpl); iv_deinit(); main_loop_worker_thread_stop(); return NULL; }
int main() { iv_init(); iv_thread_set_debug_state(1); iv_thread_create("return", thr_return, NULL); iv_thread_create("selfcancel", thr_selfcancel, NULL); iv_thread_create("exit", thr_exit, NULL); iv_thread_list_children(); iv_main(); iv_deinit(); return 0; }
int main() { iv_init(); iv_thread_set_debug_state(1); IV_WORK_POOL_INIT(&pool); pool.max_threads = 8; iv_work_pool_create(&pool); IV_WORK_ITEM_INIT(&item_a); item_a.cookie = "a"; item_a.work = work; item_a.completion = work_complete; iv_work_pool_submit_work(&pool, &item_a); IV_WORK_ITEM_INIT(&item_b); item_b.cookie = "b"; item_b.work = work; item_b.completion = work_complete; iv_work_pool_submit_work(&pool, &item_b); IV_WORK_ITEM_INIT(&item_c); item_c.cookie = "c"; item_c.work = work; item_c.completion = work_complete; iv_work_pool_submit_work(&pool, &item_c); IV_WORK_ITEM_INIT(&item_d); item_d.cookie = "d"; item_d.work = work; item_d.completion = work_complete; iv_work_pool_submit_work(&pool, &item_d); item_count = 4; iv_main(); iv_deinit(); return 0; }
int main() { long long nsec; iv_init(); #ifdef USE_SIGNAL signal(SIGALRM, got_signal_timeout); alarm(5); #else IV_TIMER_INIT(&timeout); iv_validate_now(); timeout.expires = iv_now; timeout.expires.tv_sec += 5; timeout.handler = got_timer_timeout; iv_timer_register(&timeout); #endif IV_SIGNAL_INIT(&is); is.signum = SIGUSR1; is.handler = got_sig; iv_signal_register(&is); iv_validate_now(); tim_start = iv_now; raise(SIGUSR1); iv_main(); iv_deinit(); nsec = 1000000000ULL * (tim_end.tv_sec - tim_start.tv_sec) + (tim_end.tv_nsec - tim_start.tv_nsec); printf("%s: %d in %ld nsec => %d/sec\n", iv_poll_method_name(), sig_received, (long)nsec, (int)(1000000000ULL * sig_received / nsec)); return 0; }
static gpointer _threaded_feed(gpointer args) { LogQueue *q = args; gint i; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; LogMessage *msg, *tmpl; GTimeVal start, end; glong diff; iv_init(); /* emulate main loop for LogQueue */ main_loop_worker_thread_start(NULL); tmpl = log_msg_new_empty(); g_get_current_time(&start); for (i = 0; i < MESSAGES_PER_FEEDER; i++) { msg = log_msg_clone_cow(tmpl, &path_options); log_msg_add_ack(msg, &path_options); msg->ack_func = test_ack; log_queue_push_tail(q, msg, &path_options); if ((i & 0xFF) == 0) main_loop_worker_invoke_batch_callbacks(); } main_loop_worker_invoke_batch_callbacks(); g_get_current_time(&end); diff = g_time_val_diff(&end, &start); g_static_mutex_lock(&tlock); sum_time += diff; g_static_mutex_unlock(&tlock); log_msg_unref(tmpl); main_loop_worker_thread_stop(); iv_deinit(); return NULL; }
int main() { long long nsec; iv_init(); #ifdef USE_SIGNAL signal(SIGALRM, got_signal_timeout); alarm(5); #else IV_TIMER_INIT(&timeout); iv_validate_now(); timeout.expires = iv_now; timeout.expires.tv_sec += 5; timeout.handler = got_timer_timeout; iv_timer_register(&timeout); #endif IV_EVENT_RAW_INIT(&ev); ev.handler = got_ev; iv_event_raw_register(&ev); iv_validate_now(); tim_start = iv_now; iv_event_raw_post(&ev); iv_main(); iv_deinit(); nsec = 1000000000ULL * (tim_end.tv_sec - tim_start.tv_sec) + (tim_end.tv_nsec - tim_start.tv_nsec); printf("%s: %d in %ld nsec => %d/sec\n", iv_poll_method_name(), ev_received, (long)nsec, (int)(1000000000ULL * ev_received / nsec)); return 0; }
int main() { alarm(5); iv_init(); IV_TASK_INIT(&task); task.handler = handler_task; iv_task_register(&task); IV_TIMER_INIT(&timer); iv_validate_now(); timer.expires = iv_now; timer.expires.tv_sec--; timer.handler = handler_timer; iv_main(); iv_deinit(); return !success; }
int main(int argc, char **argv) { struct iv_inotify inotify; int i; if (argc < 2) { fprintf(stderr, "Usage: %s FILE...\n", argv[0]); return 1; } iv_init(); IV_INOTIFY_INIT(&inotify); iv_inotify_register(&inotify); for (i = 1; i < argc; i++) { struct iv_inotify_watch *w; w = malloc(sizeof(*w)); if (w == NULL) { perror("malloc"); return 1; } IV_INOTIFY_WATCH_INIT(w); w->inotify = &inotify; w->pathname = argv[i]; w->mask = IN_ALL_EVENTS; w->cookie = w; w->handler = test_handler; iv_inotify_watch_register(w); } iv_main(); iv_deinit(); return 0; }