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
10 #include <afsconfig.h>
11 #include "afs/param.h"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* afs statistics */
22 static int osi_TimedSleep(char *event, afs_int32 ams, int aintok);
28 afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle)
30 AFS_STATCNT(osi_InitWaitHandle);
31 achandle->proc = (caddr_t) 0;
36 afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle)
40 AFS_STATCNT(osi_CancelWait);
41 proc = achandle->proc;
44 achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */
45 afs_osi_Wakeup(&waitV);
49 * Waits for data on ahandle, or ams ms later. ahandle may be null.
50 * Returns 0 if timeout and EINTR if signalled.
53 afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok)
56 afs_int32 endTime, tid;
58 AFS_STATCNT(osi_Wait);
59 endTime = osi_Time() + (ams / 1000);
61 ahandle->proc = (caddr_t) u.u_procp;
65 code = osi_TimedSleep(&waitV, ams, aintok);
68 break; /* if something happened, quit now */
69 /* if we we're cancelled, quit now */
70 if (ahandle && (ahandle->proc == (caddr_t) 0)) {
71 /* we've been signalled */
74 } while (osi_Time() < endTime);
81 typedef struct afs_event {
82 struct afs_event *next; /* next in hash chain */
83 char *event; /* lwp event: an address */
84 int refcount; /* Is it in use? */
85 int seq; /* Sequence number: this is incremented
86 * by wakeup calls; wait will not return until
92 afs_event_t *afs_evhasht[HASHSIZE]; /* Hash table for events */
93 #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1));
94 int afs_evhashcnt = 0;
96 /* Get and initialize event structure corresponding to lwp event (i.e. address)
99 afs_getevent(char *event)
101 afs_event_t *evp, *newp = 0;
105 hashcode = afs_evhash(event);
106 evp = afs_evhasht[hashcode];
108 if (evp->event == event) {
112 if (evp->refcount == 0)
117 newp = (afs_event_t *) osi_AllocSmallSpace(sizeof(afs_event_t));
119 newp->next = afs_evhasht[hashcode];
120 afs_evhasht[hashcode] = newp;
128 /* Release the specified event */
129 #define relevent(evp) ((evp)->refcount--)
133 afs_osi_Sleep(void *event)
135 struct afs_event *evp;
138 evp = afs_getevent(event);
140 while (seq == evp->seq) {
142 assert_wait((vm_offset_t) (&evp->cond), 0);
151 afs_osi_SleepSig(void *event)
153 afs_osi_Sleep(event);
160 * event - event to sleep on
161 * ams --- max sleep time in milliseconds
162 * aintok - 1 if should sleep interruptibly
164 * Returns 0 if timeout and EINTR if signalled.
167 osi_TimedSleep(char *event, afs_int32 ams, int aintok)
170 struct afs_event *evp;
173 ticks = (ams * afs_hz) / 1000;
176 evp = afs_getevent(event);
178 assert_wait((vm_offset_t) (&evp->cond), aintok);
180 thread_set_timeout(ticks);
183 if (current_thread()->wait_result != THREAD_AWAKENED)
192 afs_osi_Wakeup(void *event)
195 struct afs_event *evp;
197 evp = afs_getevent(event);
198 if (evp->refcount > 1) {
200 thread_wakeup((vm_offset_t) (&evp->cond));