rx: New signature for rx event functions
[openafs.git] / src / rx / rx_event.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 /* Event package */
11
12 #ifndef _EVENT_
13 #define _EVENT_
14
15 #ifdef  KERNEL
16 #include "rx/rx_queue.h"
17 #include "rx/rx_clock.h"
18 #else /* KERNEL */
19 #include "rx_queue.h"
20 #include "rx_clock.h"
21 #endif /* KERNEL */
22
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.
26  * Warnings:
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.
31  */
32
33 struct rxevent {
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 */
40 };
41
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. */
47 struct rxepoch {
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 */
51 };
52
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. */
57
58 #ifndef BEGIN
59 #define BEGIN do {
60 #define END } while(0)
61 #endif
62
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
66  * allocated. */
67 #if 0
68 extern void rxevent_Init( /* nEvents, scheduler */ );
69 #endif
70
71 /* Get the expiration time for the next event */
72 #if 0
73 extern void exevent_NextEvent( /* when */ );
74 #endif
75
76 /* Arrange for the indicated event at the appointed time.  When is a
77  * "struct clock", in the clock.c time base */
78 #if 0
79 extern struct rxevent *rxevent_Post( /* when, func, arg, arg1 */ );
80 #endif
81
82 /* Remove the indicated event from the event queue.  The event must be
83  * pending.  Also see the warning, above.  The event pointer supplied
84  * is zeroed.
85  */
86 #ifdef RX_ENABLE_LOCKS
87 #ifdef RX_REFCOUNT_CHECK
88 #define rxevent_Cancel(event_ptr, call, type)                       \
89         BEGIN                                       \
90             if (event_ptr) {                        \
91                 rxevent_Cancel_1(event_ptr, call, type);            \
92                 event_ptr = NULL;           \
93             }                                       \
94         END
95 #else /* RX_REFCOUNT_CHECK */
96 #define rxevent_Cancel(event_ptr, call, type)                       \
97         BEGIN                                       \
98             if (event_ptr) {                        \
99                 rxevent_Cancel_1(event_ptr, call, 0);       \
100                 event_ptr = NULL;           \
101             }                                       \
102         END
103 #endif /* RX_REFCOUNT_CHECK */
104 #else /* RX_ENABLE_LOCKS */
105 #define rxevent_Cancel(event_ptr, call, type)                       \
106         BEGIN                                       \
107             if (event_ptr) {                        \
108                 rxevent_Cancel_1(event_ptr, NULL, 0);       \
109                 event_ptr = NULL;           \
110             }                                       \
111         END
112 #endif /* RX_ENABLE_LOCKS */
113
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
117  * clock_NewTime)
118  */
119 #if 0
120 extern int rxevent_RaiseEvents();
121 #endif
122
123 #endif /* _EVENT_ */