75 строки
1.2 KiB
C
75 строки
1.2 KiB
C
|
/*
|
||
|
* Compile with:
|
||
|
* cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
|
||
|
*/
|
||
|
|
||
|
#ifdef HAVE_SYS_TYPES_H
|
||
|
#include <sys/types.h>
|
||
|
#endif
|
||
|
#include <sys/stat.h>
|
||
|
#ifdef HAVE_SYS_TIME_H
|
||
|
#include <sys/time.h>
|
||
|
#endif
|
||
|
#include <fcntl.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#ifdef HAVE_UNISTD_H
|
||
|
#include <unistd.h>
|
||
|
#endif
|
||
|
#include <errno.h>
|
||
|
|
||
|
#include <event.h>
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
|