| Line | |
|---|
| 1 | /*
|
|---|
| 2 | inet/generic/event.c
|
|---|
| 3 |
|
|---|
| 4 | Created: April 1995 by Philip Homburg <philip@f-mnx.phicoh.com>
|
|---|
| 5 |
|
|---|
| 6 | Implementation of an event queue.
|
|---|
| 7 |
|
|---|
| 8 | Copyright 1995 Philip Homburg
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | #include "inet.h"
|
|---|
| 12 | #include "assert.h"
|
|---|
| 13 | #include "event.h"
|
|---|
| 14 |
|
|---|
| 15 | THIS_FILE
|
|---|
| 16 |
|
|---|
| 17 | event_t *ev_head;
|
|---|
| 18 | static event_t *ev_tail;
|
|---|
| 19 |
|
|---|
| 20 | void ev_init(ev)
|
|---|
| 21 | event_t *ev;
|
|---|
| 22 | {
|
|---|
| 23 | ev->ev_func= 0;
|
|---|
| 24 | ev->ev_next= NULL;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | void ev_enqueue(ev, func, ev_arg)
|
|---|
| 28 | event_t *ev;
|
|---|
| 29 | ev_func_t func;
|
|---|
| 30 | ev_arg_t ev_arg;
|
|---|
| 31 | {
|
|---|
| 32 | assert(ev->ev_func == 0);
|
|---|
| 33 | ev->ev_func= func;
|
|---|
| 34 | ev->ev_arg= ev_arg;
|
|---|
| 35 | ev->ev_next= NULL;
|
|---|
| 36 | if (ev_head == NULL)
|
|---|
| 37 | ev_head= ev;
|
|---|
| 38 | else
|
|---|
| 39 | ev_tail->ev_next= ev;
|
|---|
| 40 | ev_tail= ev;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | void ev_process()
|
|---|
| 44 | {
|
|---|
| 45 | ev_func_t func;
|
|---|
| 46 | event_t *curr;
|
|---|
| 47 |
|
|---|
| 48 | while (ev_head)
|
|---|
| 49 | {
|
|---|
| 50 | curr= ev_head;
|
|---|
| 51 | ev_head= curr->ev_next;
|
|---|
| 52 | func= curr->ev_func;
|
|---|
| 53 | curr->ev_func= 0;
|
|---|
| 54 |
|
|---|
| 55 | assert(func != 0);
|
|---|
| 56 | func(curr, curr->ev_arg);
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | int ev_in_queue(ev)
|
|---|
| 61 | event_t *ev;
|
|---|
| 62 | {
|
|---|
| 63 | return ev->ev_func != 0;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | /*
|
|---|
| 68 | * $PchId: event.c,v 1.6 2004/08/03 16:23:32 philip Exp $
|
|---|
| 69 | */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.