From 998a40938b0a14890239693acc6b2f658c9c1f18 Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Wed, 21 May 2014 11:50:00 +0930 Subject: [PATCH] Be more careful setting alarm times --- fdqueue.c | 5 +++-- fdqueue.h | 2 ++ msp_client.c | 11 ++++++----- msp_proxy.c | 8 +++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/fdqueue.c b/fdqueue.c index d0127dc1..45bb239e 100644 --- a/fdqueue.c +++ b/fdqueue.c @@ -288,7 +288,7 @@ int fd_poll() { IN(); int i, r=0; - int ms=60000; + time_ms_t ms=60000; time_ms_t now = gettime_ms(); if (!next_alarm && !next_deadline && fdcount==0) @@ -317,7 +317,8 @@ int fd_poll() call_stats.totals=&poll_stats; fd_func_enter(__HERE__, &call_stats); if (fdcount==0){ - sleep_ms(ms); + if (ms) + sleep_ms(ms); }else{ r = poll(fds, fdcount, ms); if (config.debug.io) { diff --git a/fdqueue.h b/fdqueue.h index 316d84c7..3b9a3f8c 100644 --- a/fdqueue.h +++ b/fdqueue.h @@ -123,4 +123,6 @@ unsigned fd_depth(); #define RETURNNULL(X) do { X; OUT(); return (NULL); } while (0) #define RETURNVOID do { OUT(); return; } while (0) +void list_alarms(); + #endif // __SERVAL_DNA__FDQUEUE_H diff --git a/msp_client.c b/msp_client.c index 7b6569df..dcb6708d 100644 --- a/msp_client.c +++ b/msp_client.c @@ -657,16 +657,16 @@ static int process_sock(struct msp_sock *sock) int msp_processing(time_ms_t *next_action) { - *next_action=TIME_MS_NEVER_WILL; + time_ms_t next=TIME_MS_NEVER_WILL; struct msp_sock *sock = root; while(sock){ if (!(sock->state & MSP_STATE_CLOSED)) { // this might cause the socket to be closed // remember the time of the next thing we need to do. - if (process_sock(sock)==0 && sock->next_action < *next_action) - *next_action=sock->next_action; - }else if (sock->next_action < *next_action) - *next_action=sock->next_action; + if (process_sock(sock)==0 && sock->next_action < next) + next=sock->next_action; + }else if (sock->next_action < next) + next=sock->next_action; if (sock->state & MSP_STATE_CLOSED){ struct msp_sock *s = sock->_next; msp_free(sock); @@ -675,6 +675,7 @@ int msp_processing(time_ms_t *next_action) sock = sock->_next; } } + *next_action=next; return 0; } diff --git a/msp_proxy.c b/msp_proxy.c index 12f048a0..c2af27a8 100644 --- a/msp_proxy.c +++ b/msp_proxy.c @@ -305,13 +305,15 @@ static void msp_poll(struct sched_ent *alarm) msp_recv(alarm->poll.fd); // do any timed actions that need to be done, either in response to receiving or due to a timed alarm. - msp_processing(&alarm->alarm); - if (alarm->alarm){ + time_ms_t next; + msp_processing(&next); + unschedule(alarm); + if (next != TIME_MS_NEVER_WILL){ time_ms_t now = gettime_ms(); + alarm->alarm=next; if (alarm->alarm < now) alarm->alarm = now; alarm->deadline = alarm->alarm +10; - unschedule(alarm); schedule(alarm); } }