X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Feventl.c;h=0f7ef31f2a5dadfa64d6ede8868c13f8bf72583c;hb=cac958d5914b46a2248479f9ece1f8e1f8b2515a;hp=3a74751a28db7e6dfe0be461392a3cf8e0844816;hpb=80efa0b009565fd772664f177dcd56af81e186a1;p=pazpar2-moved-to-github.git diff --git a/src/eventl.c b/src/eventl.c index 3a74751..0f7ef31 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -59,16 +59,18 @@ struct iochan_man_s { IOCHAN channel_list; sel_thread_t sel_thread; int sel_fd; - int use_threads; + int no_threads; + int log_level; }; -iochan_man_t iochan_man_create(int use_threads) +iochan_man_t iochan_man_create(int no_threads) { iochan_man_t man = xmalloc(sizeof(*man)); man->channel_list = 0; man->sel_thread = 0; /* can't create sel_thread yet because we may fork */ man->sel_fd = -1; - man->use_threads = use_threads; + man->no_threads = no_threads; + man->log_level = YLOG_DEBUG; return man; } @@ -123,7 +125,7 @@ static void run_fun(iochan_man_t man, IOCHAN p, int event) p->this_event = event; if (man->sel_thread) { - yaz_log(YLOG_LOG, "eventl: add fun chan=%p event=%d", + yaz_log(man->log_level, "eventl: add fun chan=%p event=%d", p, event); p->thread_users++; sel_thread_add(man->sel_thread, p); @@ -177,12 +179,12 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) { if (man->sel_fd > max) max = man->sel_fd; - yaz_log(YLOG_LOG, "select on sel fd=%d", man->sel_fd); + yaz_log(man->log_level, "select on sel fd=%d", man->sel_fd); FD_SET(man->sel_fd, &in); } - yaz_log(YLOG_LOG, "select begin"); + yaz_log(man->log_level, "select begin"); res = select(max + 1, &in, &out, &except, timeout); - yaz_log(YLOG_LOG, "select returned res=%d", res); + yaz_log(man->log_level, "select returned res=%d", res); if (res < 0) { if (errno == EINTR) @@ -199,11 +201,11 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) { IOCHAN chan; - yaz_log(YLOG_LOG, "eventl: sel input on sel_fd=%d", + yaz_log(man->log_level, "eventl: sel input on sel_fd=%d", man->sel_fd); while ((chan = sel_thread_result(man->sel_thread))) { - yaz_log(YLOG_LOG, "eventl: got thread result p=%p", + yaz_log(man->log_level, "eventl: got thread result p=%p", chan); chan->thread_users--; } @@ -275,11 +277,12 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) void iochan_man_events(iochan_man_t man) { - if (man->use_threads && !man->sel_thread) + if (man->no_threads > 0 && !man->sel_thread) { man->sel_thread = sel_thread_create( - work_handler, 0 /*work_destroy */, &man->sel_fd, 10); - yaz_log(YLOG_LOG, "iochan_man_events. sel_thread started"); + work_handler, 0 /*work_destroy */, &man->sel_fd, man->no_threads); + yaz_log(man->log_level, "iochan_man_events. Using %d threads", + man->no_threads); } event_loop(man, &man->channel_list); }