Changeset 57cd7b0a283390410c6f4deca487bd80097826ee

Show
Ignore:
Timestamp:
09/18/09 00:22:31 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1253233351 +0000
git-parent:

[b12c278e4aca659c533fa1c8e51d9192d19fe1ba]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1253233351 +0000
Message:

some convenience functions for scheduling timed events

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/eventer/eventer.h

    rb9a4230 r57cd7b0  
    142142API_EXPORT(int) eventer_get_epoch(struct timeval *epoch); 
    143143 
     144/* Helpers to schedule timed events */ 
     145#define eventer_add_at(func, cl, t) do { \ 
     146  eventer_t e = eventer_alloc(); \ 
     147  e->whence = t; \ 
     148  e->mask = EVENTER_TIMER; \ 
     149  e->callback = func; \ 
     150  e->closure = cl; \ 
     151  eventer_add(e); \ 
     152} while(0) 
     153#define eventer_add_in(func, cl, t) do { \ 
     154  struct timeval __now; \ 
     155  eventer_t e = eventer_alloc(); \ 
     156  gettimeofday(&__now, NULL); \ 
     157  add_timeval(__now, t, &e->whence); \ 
     158  e->mask = EVENTER_TIMER; \ 
     159  e->callback = func; \ 
     160  e->closure = cl; \ 
     161  eventer_add(e); \ 
     162} while(0) 
     163#define eventer_add_in_s_us(func, cl, s, us) do { \ 
     164  struct timeval __now, diff = { s, us }; \ 
     165  eventer_t e = eventer_alloc(); \ 
     166  gettimeofday(&__now, NULL); \ 
     167  add_timeval(__now, diff, &e->whence); \ 
     168  e->mask = EVENTER_TIMER; \ 
     169  e->callback = func; \ 
     170  e->closure = cl; \ 
     171  eventer_add(e); \ 
     172} while(0) 
     173 
    144174/* Helpers to set sockets non-blocking / blocking */ 
    145175API_EXPORT(int) eventer_set_fd_nonblocking(int fd);