diff --git a/daemon/call.h b/daemon/call.h index 3849308ba..f70d7e032 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -431,6 +431,9 @@ struct callmaster_config { char *b2b_url; unsigned char default_tos; enum xmlrpc_format fmt; + u_int32_t graphite_ip; + u_int16_t graphite_port; + int graphite_interval; }; struct callmaster { diff --git a/daemon/graphite.c b/daemon/graphite.c index c571bcf8d..efba17e4e 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -157,3 +157,17 @@ void graphite_loop_run(struct callmaster* callmaster, int seconds) { sleep: usleep(100000); } + +void graphite_loop(void *d) { + struct callmaster *cm = d; + + if (!cm->conf.graphite_interval) { + ilog(LOG_WARNING,"Graphite send interval was not set. Setting it to 1 second."); + cm->conf.graphite_interval=1; + } + + connect_to_graphite_server(cm->conf.graphite_ip,graphite_port); + + while (!g_shutdown) + graphite_loop_run(cm,cm->conf.graphite_interval); // time in seconds +} diff --git a/daemon/graphite.h b/daemon/graphite.h index 0b51e7b9a..f00532a8f 100644 --- a/daemon/graphite.h +++ b/daemon/graphite.h @@ -13,5 +13,6 @@ int connect_to_graphite_server(u_int32_t ipaddress, int port); int send_graphite_data(); void graphite_loop_run(struct callmaster* cm, int seconds); +void graphite_loop(void *d); #endif /* GRAPHITE_H_ */ diff --git a/daemon/main.c b/daemon/main.c index 699e6cbab..99afb65f1 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -564,6 +564,9 @@ no_kernel: mc.default_tos = tos; mc.b2b_url = b2b_url; mc.fmt = xmlrpc_fmt; + mc.graphite_port = graphite_port; + mc.graphite_ip = graphite_ip; + mc.graphite_interval = graphite_interval; ct = NULL; if (listenport) { @@ -623,35 +626,6 @@ no_kernel: die("Refusing to continue without working Redis database"); } -/* XXX move loop functions */ -static void timer_loop(void *d) { - struct poller *p = d; - - while (!g_shutdown) - poller_timers_wait_run(p, 100); -} - -static void graphite_loop(void *d) { - struct callmaster *cm = d; - - if (!graphite_interval) { - ilog(LOG_WARNING,"Graphite send interval was not set. Setting it to 1 second."); - graphite_interval=1; - } - - connect_to_graphite_server(graphite_ip,graphite_port); - - while (!g_shutdown) - graphite_loop_run(cm,graphite_interval); // time in seconds -} - -static void poller_loop(void *d) { - struct poller *p = d; - - while (!g_shutdown) - poller_poll(p, 100); -} - int main(int argc, char **argv) { struct main_context ctx; int idx=0; @@ -663,7 +637,7 @@ int main(int argc, char **argv) { ilog(LOG_INFO, "Startup complete, version %s", RTPENGINE_VERSION); thread_create_detach(sighandler, NULL); - thread_create_detach(timer_loop, ctx.p); + thread_create_detach(poller_timer_loop, ctx.p); if (graphite_ip) thread_create_detach(graphite_loop, ctx.m); thread_create_detach(ice_thread_run, NULL); diff --git a/daemon/poller.c b/daemon/poller.c index 5d0830a6d..d437e0f4f 100644 --- a/daemon/poller.c +++ b/daemon/poller.c @@ -474,28 +474,30 @@ int poller_add_timer(struct poller *p, void (*f)(void *), struct obj *o) { } /* run in thread separate from poller_poll() */ -void poller_timers_wait_run(struct poller *p, int max) { +void poller_timer_loop(void *d) { + struct poller *p = d; struct timeval tv; int wt; - int i = 0; - max *= 1000; + while (!g_shutdown) { + gettimeofday(&tv, NULL); + if (tv.tv_sec != poller_now) + goto now; -retry: - gettimeofday(&tv, NULL); - if (tv.tv_sec != poller_now) - goto now; - if (i) - return; - - wt = 1000000 - tv.tv_usec; - if (max >= 0 && max < wt) - wt = max; - usleep(wt); - i = 1; - goto retry; + wt = 1000000 - tv.tv_usec; + wt = MIN(wt, 100000); + usleep(wt); + continue; now: - gettimeofday(&g_now, NULL); - poller_timers_run(p); + gettimeofday(&g_now, NULL); + poller_timers_run(p); + } +} + +void poller_loop(void *d) { + struct poller *p = d; + + while (!g_shutdown) + poller_poll(p, 100); } diff --git a/daemon/poller.h b/daemon/poller.h index 0bc6d9485..41a29e751 100644 --- a/daemon/poller.h +++ b/daemon/poller.h @@ -43,7 +43,8 @@ int poller_isblocked(struct poller *, int); void poller_error(struct poller *, int); int poller_poll(struct poller *, int); -void poller_timers_wait_run(struct poller *, int max); +void poller_timer_loop(void *); +void poller_loop(void *); int poller_add_timer(struct poller *, void (*)(void *), struct obj *); int poller_del_timer(struct poller *, void (*)(void *), struct obj *);