Browse Source

move thread loop functions out of main.c

pull/81/head
Richard Fuchs 11 years ago
parent
commit
26137d2b4d
6 changed files with 44 additions and 49 deletions
  1. +3
    -0
      daemon/call.h
  2. +14
    -0
      daemon/graphite.c
  3. +1
    -0
      daemon/graphite.h
  4. +4
    -30
      daemon/main.c
  5. +20
    -18
      daemon/poller.c
  6. +2
    -1
      daemon/poller.h

+ 3
- 0
daemon/call.h View File

@ -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 {


+ 14
- 0
daemon/graphite.c View File

@ -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
}

+ 1
- 0
daemon/graphite.h View File

@ -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_ */

+ 4
- 30
daemon/main.c View File

@ -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);


+ 20
- 18
daemon/poller.c View File

@ -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);
}

+ 2
- 1
daemon/poller.h View File

@ -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 *);


Loading…
Cancel
Save