Added simple event scheduling system to avoid recursive calling
of various callbacks. Events are just another resource type objects (thus automatically freed and unlinked when the protocol using them shuts down). Each event can be linked in at most one event list. For most purposes, just use the global event list handled by the following functions: ev_schedule Schedule event to be called at the next event scheduling point. If the event was already scheduled, it's just re-linked to the end of the list. ev_postpone Postpone an already scheduled event, so that it won't get called. Postponed events can be scheduled again by ev_schedule(). You can also create custom event lists to build your own synchronization primitives. Just use: ev_init_list to initialize an event list ev_enqueue to schedule event on specified event list ev_postpone works as well for custom lists ev_run_list to run all events on your custom list ev_run to run a specific event and dequeue it
This commit is contained in:
parent
edf62ba13f
commit
e8f73195fa
3 changed files with 7 additions and 1 deletions
1
TODO
1
TODO
|
@ -8,6 +8,7 @@ Core
|
||||||
|
|
||||||
* Fix router ID calculation
|
* Fix router ID calculation
|
||||||
* debug dump: dump router ID as well
|
* debug dump: dump router ID as well
|
||||||
|
* proto_report_state() !
|
||||||
|
|
||||||
- TOS not supported by kernel -> automatically drop routes with TOS<>0
|
- TOS not supported by kernel -> automatically drop routes with TOS<>0
|
||||||
|
|
||||||
|
|
|
@ -25,3 +25,5 @@ string.h
|
||||||
patmatch.c
|
patmatch.c
|
||||||
slists.c
|
slists.c
|
||||||
slists.h
|
slists.h
|
||||||
|
event.c
|
||||||
|
event.h
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "lib/resource.h"
|
#include "lib/resource.h"
|
||||||
#include "lib/timer.h"
|
#include "lib/timer.h"
|
||||||
#include "lib/socket.h"
|
#include "lib/socket.h"
|
||||||
|
#include "lib/event.h"
|
||||||
#include "nest/iface.h"
|
#include "nest/iface.h"
|
||||||
|
|
||||||
#include "lib/unix.h"
|
#include "lib/unix.h"
|
||||||
|
@ -58,7 +59,7 @@ tm_dump(resource *r)
|
||||||
{
|
{
|
||||||
timer *t = (timer *) r;
|
timer *t = (timer *) r;
|
||||||
|
|
||||||
debug("(code %p, data %p, ");
|
debug("(code %p, data %p, ", t->hook, t->data);
|
||||||
if (t->randomize)
|
if (t->randomize)
|
||||||
debug("rand %d, ", t->randomize);
|
debug("rand %d, ", t->randomize);
|
||||||
if (t->recurrent)
|
if (t->recurrent)
|
||||||
|
@ -682,6 +683,7 @@ io_init(void)
|
||||||
init_list(&near_timers);
|
init_list(&near_timers);
|
||||||
init_list(&far_timers);
|
init_list(&far_timers);
|
||||||
init_list(&sock_list);
|
init_list(&sock_list);
|
||||||
|
init_list(&global_event_list);
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,6 +703,7 @@ io_loop(void)
|
||||||
FD_ZERO(&wr);
|
FD_ZERO(&wr);
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
|
ev_run_list(&global_event_list);
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
tout = tm_first_shot();
|
tout = tm_first_shot();
|
||||||
if (tout <= now)
|
if (tout <= now)
|
||||||
|
|
Loading…
Reference in a new issue