2 * BIRD Library -- Event Processing
4 * (c) 1999 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
12 * Events are there to keep track of deferred execution.
13 * Since BIRD is single-threaded, it requires long lasting tasks to be split to smaller
14 * parts, so that no module can monopolize the CPU. To split such a task, just create
15 * an &event resource, point it to the function you want to have called and call ev_schedule()
16 * to ask the core to run the event when nothing more important requires attention.
18 * You can also define your own event lists (the &event_list structure), enqueue your
19 * events in them and explicitly ask to run them.
22 #include "nest/bird.h"
23 #include "lib/event.h"
25 event_list global_event_list
;
40 event
*e
= (event
*) r
;
42 debug("(code %p, data %p, %s)\n",
45 e
->n
.next
? "scheduled" : "inactive");
48 static struct resclass ev_class
= {
51 (void (*)(resource
*)) ev_postpone
,
58 * ev_new - create a new event
61 * This function creates a new event resource. To use it,
62 * you need to fill the structure fields and call ev_schedule().
67 event
*e
= ralloc(p
, &ev_class
);
72 * ev_run - run an event
75 * This function explicitly runs the event @e (calls its hook
76 * function) and removes it from an event list if it's linked to any.
78 * From the hook function, you can call ev_enqueue() or ev_schedule()
79 * to re-add the event.
89 * ev_enqueue - enqueue an event
93 * ev_enqueue() stores the event @e to the specified event
94 * list @l which can be run by calling ev_run_list().
97 ev_enqueue(event_list
*l
, event
*e
)
104 * ev_schedule - schedule an event
107 * This function schedules an event by enqueueing it to a system-wide
108 * event list which is run by the platform dependent code whenever
112 ev_schedule(event
*e
)
114 ev_enqueue(&global_event_list
, e
);
118 * ev_run_list - run an event list
121 * This function calls ev_run() for all events enqueued in the list @l.
124 ev_run_list(event_list
*l
)
129 init_list(&tmp_list
);
130 add_tail_list(&tmp_list
, l
);
132 WALK_LIST_FIRST(n
, tmp_list
)
134 event
*e
= SKIP_BACK(event
, n
, n
);
137 return !EMPTY_LIST(*l
);