Show
Ignore:
Timestamp:
03/04/08 18:13:56 (10 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1204654436 +0000
git-parent:

[bffc38f9be526436b3f50da8d06bb6987008a7f1]

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

refactor shared code, add module dependency detection and start splitting out libs in configure

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_check_tools.c

    rce72dc2 r9a6060c  
    66#include "noit_defines.h" 
    77#include "noit_check_tools.h" 
     8 
     9#include <assert.h> 
     10 
     11typedef struct { 
     12  noit_module_t *self; 
     13  noit_check_t *check; 
     14  dispatch_func_t dispatch; 
     15} recur_closure_t; 
    816 
    917int 
     
    5563} 
    5664 
     65static int 
     66noit_check_recur_handler(eventer_t e, int mask, void *closure, 
     67                              struct timeval *now) { 
     68  recur_closure_t *rcl = closure; 
     69  rcl->check->fire_event = NULL; /* This is us, we get free post-return */ 
     70  noit_check_schedule_next(rcl->self, &e->whence, rcl->check, now, 
     71                           rcl->dispatch); 
     72  rcl->dispatch(rcl->self, rcl->check); 
     73  free(rcl); 
     74  return 0; 
     75} 
     76 
     77int 
     78noit_check_schedule_next(noit_module_t *self, 
     79                         struct timeval *last_check, noit_check_t *check, 
     80                         struct timeval *now, dispatch_func_t dispatch) { 
     81  eventer_t newe; 
     82  struct timeval period, earliest; 
     83  recur_closure_t *rcl; 
     84 
     85  assert(check->fire_event == NULL); 
     86  if(check->period == 0) return 0; 
     87  if(NOIT_CHECK_DISABLED(check) || NOIT_CHECK_KILLED(check)) return 0; 
     88 
     89  /* If we have an event, we know when we intended it to fire.  This means 
     90   * we should schedule that point + period. 
     91   */ 
     92  if(now) 
     93    memcpy(&earliest, now, sizeof(earliest)); 
     94  else 
     95    gettimeofday(&earliest, NULL); 
     96  period.tv_sec = check->period / 1000; 
     97  period.tv_usec = (check->period % 1000) * 1000; 
     98 
     99  newe = eventer_alloc(); 
     100  memcpy(&newe->whence, last_check, sizeof(*last_check)); 
     101  add_timeval(newe->whence, period, &newe->whence); 
     102  if(compare_timeval(newe->whence, earliest) < 0) 
     103    memcpy(&newe->whence, &earliest, sizeof(earliest)); 
     104  newe->mask = EVENTER_TIMER; 
     105  newe->callback = noit_check_recur_handler; 
     106  rcl = calloc(1, sizeof(*rcl)); 
     107  rcl->self = self; 
     108  rcl->check = check; 
     109  rcl->dispatch = dispatch; 
     110  newe->closure = rcl; 
     111 
     112  eventer_add(newe); 
     113  check->fire_event = newe; 
     114  return 0; 
     115} 
     116