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) */
37 void (*oldfunc) (struct rxevent *, void *, void *);
38 void (*newfunc) (struct rxevent *, void *, void *, int);
39 } func; /* Function to call when this expires */
40 void *arg; /* Argument to the function */
41 void *arg1; /* Another argument */
42 int arg2; /* An integer argument */
43 int newargs; /* Nonzero if new-form arguments should be used */
46 /* We used to maintain a sorted list of events, but the amount of CPU
47 * required to maintain the list grew with the square of the number of
48 * connections. Now we keep a list of epochs, each epoch contains the
49 * events scheduled for a particular second. Each epoch contains a sorted
50 * list of the events scheduled for that epoch. */
52 struct rx_queue junk; /* Epochs are queued */
53 int epochSec; /* each epoch spans one second */
54 struct rx_queue events; /* list of events for this epoch */
57 /* Some macros to make macros more reasonable (this allows a block to be
58 * used within a macro which does not cause if statements to screw up).
59 * That is, you can use "if (...) macro_name(); else ...;" without
60 * having things blow up on the semi-colon. */
64 #define END } while(0)
67 /* This routine must be called to initialize the event package.
68 * nEvents is the number of events to allocate in a batch whenever
69 * more are needed. If this is 0, a default number (10) will be
72 extern void rxevent_Init( /* nEvents, scheduler */ );
75 /* Get the expiration time for the next event */
77 extern void exevent_NextEvent( /* when */ );
80 /* Arrange for the indicated event at the appointed time. When is a
81 * "struct clock", in the clock.c time base */
83 extern struct rxevent *rxevent_Post( /* when, func, arg, arg1 */ );
86 /* Remove the indicated event from the event queue. The event must be
87 * pending. Also see the warning, above. The event pointer supplied
90 #ifdef RX_ENABLE_LOCKS
91 #ifdef RX_REFCOUNT_CHECK
92 #define rxevent_Cancel(event_ptr, call, type) \
95 rxevent_Cancel_1(event_ptr, call, type); \
99 #else /* RX_REFCOUNT_CHECK */
100 #define rxevent_Cancel(event_ptr, call, type) \
103 rxevent_Cancel_1(event_ptr, call, 0); \
107 #endif /* RX_REFCOUNT_CHECK */
108 #else /* RX_ENABLE_LOCKS */
109 #define rxevent_Cancel(event_ptr, call, type) \
112 rxevent_Cancel_1(event_ptr, NULL, 0); \
116 #endif /* RX_ENABLE_LOCKS */
118 /* The actions specified for each event that has reached the current clock
119 * time will be taken. The current time returned by GetTime is used
120 * (warning: this may be an old time if the user has not called
124 extern int rxevent_RaiseEvents();