pull-prototypes-to-head-20020821
[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 time, unless cancelled prematurely.  The user routine (*func)() is called with arguments (event, arg, arg1) when the event occurs.  Warnings:  (1) The user supplied routine should NOT cause process preemption.   (2) The event passed to the user is still on the event queue at that time.  The user must not remove (event_Cancel) it explicitly, but the user may remove or schedule any OTHER event at this time. */
24
25 struct rxevent {
26     struct rx_queue junk;    /* Events are queued */
27     struct clock eventTime; /* When this event times out (in clock.c units) */
28     void (*func)();         /* Function to call when this expires */
29     char *arg;              /* Argument to the function */
30     char *arg1;             /* Another argument */
31 };
32
33 /* We used to maintain a sorted list of events, but the amount of CPU
34  * required to maintain the list grew with the square of the number of
35  * connections. Now we keep a list of epochs, each epoch contains the
36  * events scheduled for a particular second. Each epoch contains a sorted
37  * list of the events scheduled for that epoch. */
38 struct rxepoch {
39     struct rx_queue junk;       /* Epochs are queued */
40     int epochSec;               /* each epoch spans one second */
41     struct rx_queue events;     /* list of events for this epoch */
42 };
43
44 /* Some macros to make macros more reasonable (this allows a block to be used within a macro which does not cause if statements to screw up).   That is, you can use "if (...) macro_name(); else ...;" without having things blow up on the semi-colon. */
45
46 #ifndef BEGIN
47 #define BEGIN do {
48 #define END } while(0)
49 #endif
50
51 /* This routine must be called to initialize the event package.  nEvents is the number of events to allocate in a batch whenever more are needed.  If this is 0, a default number (10) will be allocated. */
52 #if 0
53 extern void rxevent_Init(/* nEvents, scheduler */);
54 #endif
55
56 /* Get the expiration time for the next event */
57 #if 0
58 extern void exevent_NextEvent(/* when */);
59 #endif
60
61 /* Arrange for the indicated event at the appointed time.  When is a "struct clock", in the clock.c time base */
62 #if 0
63 extern struct rxevent *rxevent_Post(/* when, func, arg, arg1 */);
64 #endif
65
66 /* Remove the indicated event from the event queue.  The event must be pending.  Also see the warning, above.  The event pointer supplied is zeroed. */
67 #ifdef RX_ENABLE_LOCKS
68 #ifdef RX_REFCOUNT_CHECK
69 #define rxevent_Cancel(event_ptr, call, type)                       \
70         BEGIN                                       \
71             if (event_ptr) {                        \
72                 rxevent_Cancel_1(event_ptr, call, type);            \
73                 event_ptr = NULL;           \
74             }                                       \
75         END
76 #else /* RX_REFCOUNT_CHECK */
77 #define rxevent_Cancel(event_ptr, call, type)                       \
78         BEGIN                                       \
79             if (event_ptr) {                        \
80                 rxevent_Cancel_1(event_ptr, call, 0);       \
81                 event_ptr = NULL;           \
82             }                                       \
83         END
84 #endif /* RX_REFCOUNT_CHECK */
85 #else /* RX_ENABLE_LOCKS */
86 #define rxevent_Cancel(event_ptr, call, type)                       \
87         BEGIN                                       \
88             if (event_ptr) {                        \
89                 rxevent_Cancel_1(event_ptr, NULL, 0);       \
90                 event_ptr = NULL;           \
91             }                                       \
92         END
93 #endif /* RX_ENABLE_LOCKS */
94
95 /* The actions specified for each event that has reached the current clock time will be taken.  The current time returned by GetTime is used (warning:  this may be an old time if the user has not called clock_NewTime) */
96 #if 0
97 extern int rxevent_RaiseEvents();
98 #endif
99
100 #endif /* _EVENT_ */