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 "afsincludes.h" /* Afs-based standard headers */
17 #include "afs/afs_stats.h" /* afs statistics */
19 #if defined(AFS_HPUX1122_ENV)
20 void afs_osi_Wakeup(char *event);
21 void afs_osi_Sleep(char *event);
26 /* call procedure aproc with arock as an argument, in ams milliseconds */
27 static int afs_osi_CallProc(aproc, arock, ams)
28 register void (*aproc)();
34 AFS_STATCNT(osi_CallProc);
36 /* hz is in cycles/second, and timeout's 3rd parm is in cycles */
37 code = timeout(aproc, arock, (ams * afs_hz)/1000 + 1);
42 /* cancel a timeout, whether or not it has already occurred */
43 static int afs_osi_CancelProc(aproc, arock)
44 register void (*aproc)();
48 AFS_STATCNT(osi_CancelProc);
51 code = untimeout(aproc, arock);
56 static void AfsWaitHack()
58 AFS_STATCNT(WaitHack);
62 void afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle)
64 AFS_STATCNT(osi_InitWaitHandle);
65 achandle->proc = (caddr_t) 0;
69 void afs_osi_CancelWait(struct afs_osi_WaitHandle *achandle)
73 AFS_STATCNT(osi_CancelWait);
74 proc = achandle->proc;
75 if (proc == 0) return;
76 achandle->proc = (caddr_t) 0; /* so dude can figure out he was signalled */
77 afs_osi_Wakeup(&waitV);
81 * Waits for data on ahandle, or ams ms later. ahandle may be null.
82 * Returns 0 if timeout and EINTR if signalled.
84 int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok)
87 afs_int32 endTime, tid;
89 AFS_STATCNT(osi_Wait);
90 endTime = osi_Time() + (ams/1000);
92 ahandle->proc = (caddr_t) u.u_procp;
96 /* do not do anything for solaris, digital, AIX, and SGI MP */
97 afs_osi_CallProc(AfsWaitHack, (char *) u.u_procp, ams);
98 afs_osi_Sleep(&waitV); /* for HP 10.0 */
100 /* do not do anything for solaris, digital, and SGI MP */
101 afs_osi_CancelProc(AfsWaitHack, (char *) u.u_procp);
102 if (code) break; /* if something happened, quit now */
103 /* if we we're cancelled, quit now */
104 if (ahandle && (ahandle->proc == (caddr_t) 0)) {
105 /* we've been signalled */
108 } while (osi_Time() < endTime);
112 int afs_osi_SleepSig(void *event)
114 afs_osi_Sleep(event);
118 int afs_osi_Wakeup(void *event)
120 wakeup((caddr_t) event);
124 #if defined(AFS_HPUX1122_ENV)
126 /* on HP 11.22 we are using beta semiphore for AFS_GLOCK */
128 typedef struct afs_event {
129 struct afs_event *next; /* next in hash chain */
130 char *event; /* lwp event: an address */
131 int refcount; /* Is it in use? */
132 int seq; /* Sequence number: this is incremented
133 by wakeup calls; wait will not return until
138 afs_event_t *afs_evhasht[HASHSIZE];/* Hash table for events */
139 #define afs_evhash(event) (afs_uint32) ((((long)event)>>2) & (HASHSIZE-1));
140 int afs_evhashcnt = 0;
142 /* Get and initialize event structure corresponding to lwp event (i.e. address)
144 static afs_event_t *afs_getevent(char *event)
146 afs_event_t *evp, *newp = 0;
150 hashcode = afs_evhash(event);
151 evp = afs_evhasht[hashcode];
153 if (evp->event == event) {
157 if (evp->refcount == 0)
162 newp = (afs_event_t *) osi_AllocSmallSpace(sizeof (afs_event_t));
164 newp->next = afs_evhasht[hashcode];
165 afs_evhasht[hashcode] = newp;
174 /* Release the specified event */
175 #define relevent(evp) ((evp)->refcount--)
177 void afs_osi_Sleep(char *event)
179 struct afs_event *evp;
182 evp = afs_getevent(event);
184 while (seq == evp->seq) {
186 get_sleep_lock(event);
188 sleep(event, PZERO-2);
194 void afs_osi_Wakeup(char *event)
196 struct afs_event *evp;
199 evp = afs_getevent(event);
200 sleep_lock = get_sleep_lock(event);
201 if (evp->refcount > 1) {
205 spinunlock(sleep_lock);