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 "../afs/param.h" /* Should be always first */
11 #include "../afs/sysincludes.h" /* Standard vendor system headers */
12 #include "../afs/afsincludes.h" /* Afs-based standard headers */
13 #include "../afs/afs_stats.h" /* afs statistics */
17 static int osi_TimedSleep(char *event, afs_int32 ams, int aintok);
18 void afs_osi_Wakeup(char *event);
19 void afs_osi_Sleep(char *event);
24 void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle)
26 AFS_STATCNT(osi_InitWaitHandle);
27 achandle->proc = (caddr_t) 0;
31 void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle)
35 AFS_STATCNT(osi_CancelWait);
36 proc = achandle->proc;
37 if (proc == 0) return;
38 achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */
39 afs_osi_Wakeup(&waitV);
43 * Waits for data on ahandle, or ams ms later. ahandle may be null.
44 * Returns 0 if timeout and EINTR if signalled.
46 int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok)
49 afs_int32 endTime, tid;
51 AFS_STATCNT(osi_Wait);
52 endTime = osi_Time() + (ams/1000);
54 ahandle->proc = (caddr_t) u.u_procp;
58 code = osi_TimedSleep(&waitV, ams, aintok);
60 if (code) break; /* if something happened, quit now */
61 /* if we we're cancelled, quit now */
62 if (ahandle && (ahandle->proc == (caddr_t) 0)) {
63 /* we've been signalled */
66 } while (osi_Time() < endTime);
73 typedef struct afs_event {
74 struct afs_event *next; /* next in hash chain */
75 char *event; /* lwp event: an address */
76 int refcount; /* Is it in use? */
77 int seq; /* Sequence number: this is incremented
78 by wakeup calls; wait will not return until
84 afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */
85 #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1));
86 int afs_evhashcnt = 0;
88 /* Get and initialize event structure corresponding to lwp event (i.e. address)
90 static afs_event_t *afs_getevent(char *event)
92 afs_event_t *evp, *newp = 0;
96 hashcode = afs_evhash(event);
97 evp = afs_evhasht[hashcode];
99 if (evp->event == event) {
103 if (evp->refcount == 0)
108 newp = (afs_event_t *) osi_AllocSmallSpace(sizeof (afs_event_t));
110 newp->next = afs_evhasht[hashcode];
111 afs_evhasht[hashcode] = newp;
119 /* Release the specified event */
120 #define relevent(evp) ((evp)->refcount--)
123 void afs_osi_Sleep(char *event)
125 struct afs_event *evp;
128 evp = afs_getevent(event);
130 while (seq == evp->seq) {
132 assert_wait((vm_offset_t)(&evp->cond), 0);
143 * event - event to sleep on
144 * ams --- max sleep time in milliseconds
145 * aintok - 1 if should sleep interruptibly
147 * Returns 0 if timeout and EINTR if signalled.
149 static int osi_TimedSleep(char *event, afs_int32 ams, int aintok)
152 struct afs_event *evp;
155 ticks = ( ams * afs_hz )/1000;
158 evp = afs_getevent(event);
160 assert_wait((vm_offset_t)(&evp->cond), aintok);
162 thread_set_timeout(ticks);
165 if (current_thread()->wait_result != THREAD_AWAKENED)
173 void afs_osi_Wakeup(char *event)
175 struct afs_event *evp;
177 evp = afs_getevent(event);
178 if (evp->refcount > 1) {
180 thread_wakeup((vm_offset_t)(&evp->cond));