root/src/eventer/eventer.c

Revision 919b09a62be1e318c5b142de70468c11e8fc980e, 1.0 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

umm.. that last commit was junk, I should work on one machine... This compiles on OpenBSD

  • Property mode set to 100644
Line 
1 #include "eventer/eventer.h"
2 #include "eventer/eventer_impl.h"
3 #include "eventer/eventer_POSIX_fd_opset.h"
4
5 eventer_t eventer_alloc() {
6   eventer_t e;
7   e = calloc(1, sizeof(*e));
8   e->opset = eventer_POSIX_fd_opset;
9   return e;
10 }
11
12 int eventer_timecompare(void *av, void *bv) {
13   /* Herein we avoid equality.  This function is only used as a comparator
14    * for a heap of timed events.  If they are equal, b is considered less
15    * just to maintain an order (despite it not being stable).
16    */
17   eventer_t a = (eventer_t)av;
18   eventer_t b = (eventer_t)bv;
19   if(a->whence.tv_sec < b->whence.tv_sec) return -1;
20   if(a->whence.tv_sec == b->whence.tv_sec &&
21      a->whence.tv_usec < b->whence.tv_usec) return -1;
22   return 1;
23 }
24
25 void eventer_free(eventer_t e) {
26   free(e);
27 }
28
29 int eventer_choose(const char *name) {
30   eventer_impl_t choice;
31   for(choice = registered_eventers[0]; choice; choice++) {
32     if(!strcmp(choice->name, name)) {
33       __eventer = choice;
34       return 0;
35     }
36   }
37   return -1;
38 }
Note: See TracBrowser for help on using the browser.