/* * Compile with: * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent */ #ifdef HAVE_SYS_TYPES_H #include #endif #include #ifdef HAVE_SYS_TIME_H #include #endif #include #include #include #include #ifdef HAVE_UNISTD_H #include #endif #include #include int called = 0; #define NEVENT 20000 struct opal_event *ev[NEVENT]; void time_cb(int fd, short event, void *arg) { struct timeval tv; int i, j; called++; if (called < 10*NEVENT) { for (i = 0; i < 10; i++) { j = random() % NEVENT; tv.tv_sec = 0; tv.tv_usec = random() % 50000L; if (tv.tv_usec % 2) opal_evtimer_add(ev[j], &tv); else opal_evtimer_del(ev[j]); } } } int main (int argc, char **argv) { struct timeval tv; int i; /* Initalize the event library */ opal_event_init(); for (i = 0; i < NEVENT; i++) { ev[i] = malloc(sizeof(struct opal_event)); /* Initalize one event */ opal_evtimer_set(ev[i], time_cb, ev[i]); tv.tv_sec = 0; tv.tv_usec = random() % 50000L; opal_evtimer_add(ev[i], &tv); } opal_event_dispatch(); return (called < NEVENT); }