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"
15 #include "../afs/sysincludes.h" /* Standard vendor system headers */
16 #include "../afs/afsincludes.h" /* Afs-based standard headers */
17 #include "../afs/afs_stats.h" /* afs statistics */
21 static int osi_TimedSleep(char *event, afs_int32 ams, int aintok);
22 void afs_osi_Wakeup(char *event);
23 void afs_osi_Sleep(char *event);
28 void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle)
30 AFS_STATCNT(osi_InitWaitHandle);
31 achandle->proc = (caddr_t) 0;
35 void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle)
39 AFS_STATCNT(osi_CancelWait);
40 proc = achandle->proc;
41 if (proc == 0) return;
42 achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */
43 afs_osi_Wakeup(&waitV);
47 * Waits for data on ahandle, or ams ms later. ahandle may be null.
48 * Returns 0 if timeout and EINTR if signalled.
50 int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok)
53 afs_int32 endTime, tid;
55 AFS_STATCNT(osi_Wait);
56 endTime = osi_Time() + (ams/1000);
58 ahandle->proc = (caddr_t) u.u_procp;
62 code = osi_TimedSleep(&waitV, ams, aintok);
64 if (code) break; /* if something happened, quit now */
65 /* if we we're cancelled, quit now */
66 if (ahandle && (ahandle->proc == (caddr_t) 0)) {
67 /* we've been signalled */
70 } while (osi_Time() < endTime);
77 typedef struct afs_event {
78 struct afs_event *next; /* next in hash chain */
79 char *event; /* lwp event: an address */
80 int refcount; /* Is it in use? */
81 int seq; /* Sequence number: this is incremented
82 by wakeup calls; wait will not return until
88 afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */
89 #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1));
90 int afs_evhashcnt = 0;
92 /* Get and initialize event structure corresponding to lwp event (i.e. address)
94 static afs_event_t *afs_getevent(char *event)
96 afs_event_t *evp, *newp = 0;
100 hashcode = afs_evhash(event);
101 evp = afs_evhasht[hashcode];
103 if (evp->event == event) {
107 if (evp->refcount == 0)
112 newp = (afs_event_t *) osi_AllocSmallSpace(sizeof (afs_event_t));
114 newp->next = afs_evhasht[hashcode];
115 afs_evhasht[hashcode] = newp;
123 /* Release the specified event */
124 #define relevent(evp) ((evp)->refcount--)
127 void afs_osi_Sleep(char *event)
129 struct afs_event *evp;
132 evp = afs_getevent(event);
134 while (seq == evp->seq) {
136 assert_wait((vm_offset_t)(&evp->cond), 0);
144 int afs_osi_SleepSig(char *event)
146 afs_osi_Sleep(event);
153 * event - event to sleep on
154 * ams --- max sleep time in milliseconds
155 * aintok - 1 if should sleep interruptibly
157 * Returns 0 if timeout and EINTR if signalled.
159 static int osi_TimedSleep(char *event, afs_int32 ams, int aintok)
162 struct afs_event *evp;
165 ticks = ( ams * afs_hz )/1000;
168 evp = afs_getevent(event);
170 assert_wait((vm_offset_t)(&evp->cond), aintok);
172 thread_set_timeout(ticks);
175 if (current_thread()->wait_result != THREAD_AWAKENED)
183 void afs_osi_Wakeup(char *event)
185 struct afs_event *evp;
187 evp = afs_getevent(event);
188 if (evp->refcount > 1) {
190 thread_wakeup((vm_offset_t)(&evp->cond));