2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
16 #include "rx/rx_queue.h"
17 #include "rx/rx_clock.h"
23 /* An event is something that will happen at (or after) a specified clock
24 * time, unless cancelled prematurely. The user routine (*func)() is called
25 * with arguments (event, arg, arg1) when the event occurs.
27 * (1) The user supplied routine should NOT cause process preemption.
28 * (2) The event passed to the user is still on the event queue at that
29 * time. The user must not remove (event_Cancel) it explicitly, but
30 * the user may remove or schedule any OTHER event at this time.
34 struct rx_queue junk; /* Events are queued */
35 struct clock eventTime; /* When this event times out (in clock.c units) */
36 void (*func) (struct rxevent *, void *, void *, int);
37 void *arg; /* Argument to the function */
38 void *arg1; /* Another argument */
39 int arg2; /* An integer argument */
42 /* We used to maintain a sorted list of events, but the amount of CPU
43 * required to maintain the list grew with the square of the number of
44 * connections. Now we keep a list of epochs, each epoch contains the
45 * events scheduled for a particular second. Each epoch contains a sorted
46 * list of the events scheduled for that epoch. */
48 struct rx_queue junk; /* Epochs are queued */
49 int epochSec; /* each epoch spans one second */
50 struct rx_queue events; /* list of events for this epoch */
53 /* Some macros to make macros more reasonable (this allows a block to be
54 * used within a macro which does not cause if statements to screw up).
55 * That is, you can use "if (...) macro_name(); else ...;" without
56 * having things blow up on the semi-colon. */
60 #define END } while(0)
63 /* This routine must be called to initialize the event package.
64 * nEvents is the number of events to allocate in a batch whenever
65 * more are needed. If this is 0, a default number (10) will be
68 extern void rxevent_Init( /* nEvents, scheduler */ );
71 /* Get the expiration time for the next event */
73 extern void exevent_NextEvent( /* when */ );
76 /* Arrange for the indicated event at the appointed time. When is a
77 * "struct clock", in the clock.c time base */
79 extern struct rxevent *rxevent_Post( /* when, func, arg, arg1 */ );
82 /* Remove the indicated event from the event queue. The event must be
83 * pending. Also see the warning, above. The event pointer supplied
86 #ifdef RX_ENABLE_LOCKS
87 #ifdef RX_REFCOUNT_CHECK
88 #define rxevent_Cancel(event_ptr, call, type) \
91 rxevent_Cancel_1(event_ptr, call, type); \
95 #else /* RX_REFCOUNT_CHECK */
96 #define rxevent_Cancel(event_ptr, call, type) \
99 rxevent_Cancel_1(event_ptr, call, 0); \
103 #endif /* RX_REFCOUNT_CHECK */
104 #else /* RX_ENABLE_LOCKS */
105 #define rxevent_Cancel(event_ptr, call, type) \
108 rxevent_Cancel_1(event_ptr, NULL, 0); \
112 #endif /* RX_ENABLE_LOCKS */
114 /* The actions specified for each event that has reached the current clock
115 * time will be taken. The current time returned by GetTime is used
116 * (warning: this may be an old time if the user has not called
120 extern int rxevent_RaiseEvents();