mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-07 16:00:55 +00:00
Reindent bench.c to Linux coding style
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
f7e93f9d43
commit
d9f078a119
1 file changed
+65
-71
@@ -60,11 +60,10 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#if NATIVE
|
#if NATIVE
|
||||||
# include "ev.h"
|
#include "ev.h"
|
||||||
#endif
|
#endif
|
||||||
#include <event.h>
|
#include <event.h>
|
||||||
|
|
||||||
|
|
||||||
static int count, writes, fired;
|
static int count, writes, fired;
|
||||||
static int *pipes;
|
static int *pipes;
|
||||||
static int num_pipes, num_active, num_writes;
|
static int num_pipes, num_active, num_writes;
|
||||||
@@ -73,34 +72,27 @@ static int timers, native;
|
|||||||
static struct ev_io *evio;
|
static struct ev_io *evio;
|
||||||
static struct ev_timer *evto;
|
static struct ev_timer *evto;
|
||||||
|
|
||||||
|
void read_cb(int fd, short which, void *arg)
|
||||||
|
|
||||||
void
|
|
||||||
read_cb(int fd, short which, void *arg)
|
|
||||||
{
|
{
|
||||||
int idx = (int) arg, widx = idx + 1;
|
int idx = (int)arg, widx = idx + 1;
|
||||||
u_char ch;
|
u_char ch;
|
||||||
|
|
||||||
if (timers)
|
if (timers) {
|
||||||
{
|
if (native) {
|
||||||
if (native)
|
|
||||||
{
|
|
||||||
#if NATIVE
|
#if NATIVE
|
||||||
evto [idx].repeat = 10. + drand48 ();
|
evto[idx].repeat = 10. + drand48();
|
||||||
ev_timer_again (&evto [idx]);
|
ev_timer_again(&evto[idx]);
|
||||||
#else
|
#else
|
||||||
abort ();
|
abort();
|
||||||
#endif
|
#endif
|
||||||
}
|
} else {
|
||||||
else
|
struct timeval tv;
|
||||||
{
|
event_del(&events[idx]);
|
||||||
struct timeval tv;
|
tv.tv_sec = 10;
|
||||||
event_del (&events [idx]);
|
tv.tv_usec = drand48() * 1e6;
|
||||||
tv.tv_sec = 10;
|
event_add(&events[idx], &tv);
|
||||||
tv.tv_usec = drand48() * 1e6;
|
}
|
||||||
event_add(&events[idx], &tv);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
count += read(fd, &ch, sizeof(ch));
|
count += read(fd, &ch, sizeof(ch));
|
||||||
if (writes) {
|
if (writes) {
|
||||||
@@ -113,50 +105,45 @@ read_cb(int fd, short which, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if NATIVE
|
#if NATIVE
|
||||||
void
|
void read_thunk(struct ev_io *w, int revents)
|
||||||
read_thunk(struct ev_io *w, int revents)
|
|
||||||
{
|
{
|
||||||
read_cb (w->fd, revents, w->data);
|
read_cb(w->fd, revents, w->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void timer_cb(struct ev_timer *w, int revents)
|
||||||
timer_cb (struct ev_timer *w, int revents)
|
|
||||||
{
|
{
|
||||||
/* nop */
|
/* nop */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct timeval *
|
struct timeval *run_once(void)
|
||||||
run_once(void)
|
|
||||||
{
|
{
|
||||||
int *cp, i, space;
|
int *cp, i, space;
|
||||||
static struct timeval ta, ts, te, tv;
|
static struct timeval ta, ts, te, tv;
|
||||||
|
|
||||||
gettimeofday(&ta, NULL);
|
gettimeofday(&ta, NULL);
|
||||||
for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
|
for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
|
||||||
if (native)
|
if (native) {
|
||||||
{
|
|
||||||
#if NATIVE
|
#if NATIVE
|
||||||
if (ev_is_active (&evio [i]))
|
if (ev_is_active(&evio[i]))
|
||||||
ev_io_stop (&evio [i]);
|
ev_io_stop(&evio[i]);
|
||||||
|
|
||||||
ev_io_set (&evio [i], cp [0], EV_READ);
|
ev_io_set(&evio[i], cp[0], EV_READ);
|
||||||
ev_io_start (&evio [i]);
|
ev_io_start(&evio[i]);
|
||||||
|
|
||||||
evto [i].repeat = 10. + drand48 ();
|
evto[i].repeat = 10. + drand48();
|
||||||
ev_timer_again (&evto [i]);
|
ev_timer_again(&evto[i]);
|
||||||
#else
|
#else
|
||||||
abort ();
|
abort();
|
||||||
#endif
|
#endif
|
||||||
}
|
} else {
|
||||||
else
|
event_del(&events[i]);
|
||||||
{
|
event_set(&events[i], cp[0], EV_READ | EV_PERSIST,
|
||||||
event_del(&events[i]);
|
read_cb, (void *)i);
|
||||||
event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (void *) i);
|
tv.tv_sec = 10.;
|
||||||
tv.tv_sec = 10.;
|
tv.tv_usec = drand48() * 1e6;
|
||||||
tv.tv_usec = drand48() * 1e6;
|
event_add(&events[i], timers ? &tv : 0);
|
||||||
event_add(&events[i], timers ? &tv : 0);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
event_loop(EVLOOP_ONCE | EVLOOP_NONBLOCK);
|
event_loop(EVLOOP_ONCE | EVLOOP_NONBLOCK);
|
||||||
@@ -169,29 +156,28 @@ run_once(void)
|
|||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
writes = num_writes;
|
writes = num_writes;
|
||||||
{ int xcount = 0;
|
{
|
||||||
gettimeofday(&ts, NULL);
|
int xcount = 0;
|
||||||
do {
|
gettimeofday(&ts, NULL);
|
||||||
event_loop(EVLOOP_ONCE | EVLOOP_NONBLOCK);
|
do {
|
||||||
xcount++;
|
event_loop(EVLOOP_ONCE | EVLOOP_NONBLOCK);
|
||||||
} while (count != fired);
|
xcount++;
|
||||||
gettimeofday(&te, NULL);
|
} while (count != fired);
|
||||||
|
gettimeofday(&te, NULL);
|
||||||
|
|
||||||
//if (xcount != count) fprintf(stderr, "Xcount: %d, Rcount: %d\n", xcount, count);
|
//if (xcount != count) fprintf(stderr, "Xcount: %d, Rcount: %d\n", xcount, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
timersub(&te, &ta, &ta);
|
timersub(&te, &ta, &ta);
|
||||||
timersub(&te, &ts, &ts);
|
timersub(&te, &ts, &ts);
|
||||||
fprintf(stdout, "%8ld %8ld\n",
|
fprintf(stdout, "%8ld %8ld\n",
|
||||||
ta.tv_sec * 1000000L + ta.tv_usec,
|
ta.tv_sec * 1000000L + ta.tv_usec,
|
||||||
ts.tv_sec * 1000000L + ts.tv_usec
|
ts.tv_sec * 1000000L + ts.tv_usec);
|
||||||
);
|
|
||||||
|
|
||||||
return (&te);
|
return (&te);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main(int argc, char **argv)
|
||||||
main (int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
struct rlimit rl;
|
struct rlimit rl;
|
||||||
int i, c;
|
int i, c;
|
||||||
@@ -214,10 +200,10 @@ main (int argc, char **argv)
|
|||||||
num_writes = atoi(optarg);
|
num_writes = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
native = 1;
|
native = 1;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
timers = 1;
|
timers = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Illegal argument \"%c\"\n", c);
|
fprintf(stderr, "Illegal argument \"%c\"\n", c);
|
||||||
@@ -247,11 +233,11 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
|
for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) {
|
||||||
#if NATIVE
|
#if NATIVE
|
||||||
if (native) {
|
if (native) {
|
||||||
ev_init (&evto [i], timer_cb);
|
ev_init(&evto[i], timer_cb);
|
||||||
ev_init (&evio [i], read_thunk);
|
ev_init(&evio[i], read_thunk);
|
||||||
evio [i].data = (void *)i;
|
evio[i].data = (void *)i;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_PIPES
|
#ifdef USE_PIPES
|
||||||
if (pipe(cp) == -1) {
|
if (pipe(cp) == -1) {
|
||||||
@@ -269,3 +255,11 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* version-control: t
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
Reference in new issue
Block a user