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"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* afs statistics */
21 afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle)
23 AFS_STATCNT(osi_InitWaitHandle);
24 achandle->proc = (caddr_t) 0;
29 afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle)
33 AFS_STATCNT(osi_CancelWait);
34 proc = achandle->proc;
37 achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */
38 afs_osi_Wakeup(&waitV);
42 * Waits for data on ahandle, or ams ms later. ahandle may be null.
43 * Returns 0 if timeout and EINTR if signalled.
46 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) curthread;
58 code = afs_osi_TimedSleep(&waitV, ams, aintok);
61 break; /* if something happened, quit now */
62 /* if we we're cancelled, quit now */
63 if (ahandle && (ahandle->proc == (caddr_t) 0)) {
64 /* we've been signalled */
67 } while (osi_Time() < endTime);
74 typedef struct afs_event {
75 struct afs_event *next; /* next in hash chain */
76 char *event; /* lwp event: an address */
77 int refcount; /* Is it in use? */
78 int seq; /* Sequence number: this is incremented
79 * by wakeup calls; wait will not return until
81 kcondvar_t cond; /* Currently associated condition variable */
85 afs_event_t *afs_evhasht[HASHSIZE]; /* Hash table for events */
86 #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1));
87 int afs_evhashcnt = 0;
89 /* Get and initialize event structure corresponding to lwp event (i.e. address)
92 afs_getevent(char *event)
94 afs_event_t *evp, *newp = 0;
98 hashcode = afs_evhash(event);
99 evp = afs_evhasht[hashcode];
101 if (evp->event == event) {
105 if (evp->refcount == 0)
110 newp = (afs_event_t *) osi_AllocSmallSpace(sizeof(afs_event_t));
112 newp->next = afs_evhasht[hashcode];
113 afs_evhasht[hashcode] = newp;
114 cv_init(&newp->cond, "event cond var", CV_DEFAULT, NULL);
122 /* Release the specified event */
123 #define relevent(evp) ((evp)->refcount--)
127 afs_osi_Sleep(void *event)
129 struct afs_event *evp;
132 evp = afs_getevent(event);
134 while (seq == evp->seq) {
136 cv_wait(&evp->cond, &afs_global_lock);
142 afs_osi_SleepSig(void *event)
144 struct afs_event *evp;
147 evp = afs_getevent(event);
149 while (seq == evp->seq) {
151 if (cv_wait_sig(&evp->cond, &afs_global_lock) == 0) {
160 /* afs_osi_TimedSleep
163 * event - event to sleep on
164 * ams --- max sleep time in milliseconds
165 * aintok - 1 if should sleep interruptibly
167 * Returns 0 if timeout and EINTR if signalled.
170 afs_osi_TimedSleep(void *event, afs_int32 ams, int aintok)
173 struct afs_event *evp;
176 ticks = (ams * afs_hz) / 1000;
177 #if defined(AFS_SUN510_ENV)
178 ticks = ticks + ddi_get_lbolt();
180 ticks = ticks + lbolt;
183 evp = afs_getevent(event);
187 if (cv_timedwait_sig(&evp->cond, &afs_global_lock, ticks) == 0)
190 cv_timedwait(&evp->cond, &afs_global_lock, ticks);
199 afs_osi_Wakeup(void *event)
202 struct afs_event *evp;
204 evp = afs_getevent(event);
205 if (evp->refcount > 1) {
207 cv_broadcast(&evp->cond);