Skip to content
Browse files

Event poll timeout is setting to closest timer's time of execution

  • Loading branch information...
1 parent 042739e commit 0773323089b94721741c05a98800e7c3432a5b4f @harmer harmer committed with paraboul May 23, 2010
Showing with 15 additions and 2 deletions.
  1. +2 −2 src/sock.c
  2. +12 −0 src/ticks.c
  3. +1 −0 src/ticks.h
View
4 src/sock.c
@@ -294,9 +294,9 @@ unsigned int sockroutine(acetables *g_ape)
#endif
gettimeofday(&t_start, NULL);
while (server_is_running) {
- // int timeout_to_hang = MAX((1000/TICKS_RATE)-ticks, 1);
/* Linux 2.6.25 provides a fd-driven timer system. It could be usefull to implement */
- nfds = events_poll(g_ape->events, 1);
+ int timeout_to_hang = get_first_timer_ms (g_ape);
+ nfds = events_poll(g_ape->events, timeout_to_hang);
if (nfds < 0) {
ape_log(APE_ERR, __FILE__, __LINE__, g_ape,
View
12 src/ticks.c
@@ -143,3 +143,15 @@ void del_timer_identifier(unsigned int identifier, acetables *g_ape)
}
}
+/* Returns closest timer execution time (in ms) */
+int get_first_timer_ms (acetables *g_ape)
+{
+ struct _ticks_callback *timers = g_ape->timers.timers;
+
+ if (timers != NULL) {
+ return timers->delta;
+ }
+
+ return -1;
+}
+
View
1 src/ticks.h
@@ -45,6 +45,7 @@ struct _ticks_callback *add_timeout(unsigned int msec, void *callback, void *par
struct _ticks_callback *add_periodical(unsigned int msec, int times, void *callback, void *params, acetables *g_ape);
void del_timer_identifier(unsigned int identifier, acetables *g_ape);
struct _ticks_callback *get_timer_identifier(unsigned int identifier, acetables *g_ape);
+int get_first_timer_ms (acetables *g_ape);
#define add_ticked(x, y) add_periodical(VTICKS_RATE, 0, x, y, g_ape)

0 comments on commit 0773323

Please sign in to comment.
Something went wrong with that request. Please try again.