afs: remove dead code afs_osi_SetTime
[openafs.git] / src / afs / OBSD / osi_sleep.c
index 5fd1c0e..e12688d 100644 (file)
@@ -44,8 +44,6 @@ such damages.
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
 
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
 #include "afs/afsincludes.h"   /* Afs-based standard headers */
@@ -54,11 +52,13 @@ RCSID
 static char waitV;
 
 
-void
-afs_osi_InitWaitHandle(struct afs_osi_WaitHandle *achandle)
+time_t
+osi_Time()
 {
-    AFS_STATCNT(osi_InitWaitHandle);
-    achandle->proc = NULL;
+    struct timeval now;
+
+    getmicrotime(&now);
+    return now.tv_sec;
 }
 
 /* cancel osi_Wait */
@@ -83,13 +83,14 @@ int
 afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok)
 {
     int timo, code = 0;
-    struct timeval atv, endTime;
+    struct timeval atv, now, endTime;
 
     AFS_STATCNT(osi_Wait);
 
     atv.tv_sec = ams / 1000;
     atv.tv_usec = (ams % 1000) * 1000;
-    timeradd(&atv, &time, &endTime);
+    getmicrotime(&now);
+    timeradd(&atv, &now, &endTime);
 
     if (ahandle)
        ahandle->proc = (caddr_t) curproc;
@@ -97,7 +98,7 @@ afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok)
     AFS_GUNLOCK();
 
     do {
-       timersub(&endTime, &time, &atv);
+       timersub(&endTime, &now, &atv);
        timo = atv.tv_sec * hz + atv.tv_usec * hz / 1000000 + 1;
        if (aintok) {
            code = tsleep(&waitV, PCATCH | PVFS, "afs_W1", timo);
@@ -111,28 +112,89 @@ afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok)
            /* we've been signalled */
            break;
        }
-    } while (timercmp(&time, &endTime, <));
+       getmicrotime(&now);
+    } while (timercmp(&now, &endTime, <));
 
     AFS_GLOCK();
     return code;
 }
 
+afs_event_t *afs_evhasht[AFS_EVHASHSIZE];     /* Hash table for events */
+#define afs_evhash(event)       (afs_uint32) ((((long)event)>>2) & (AFS_EVHASHSIZE-1))
+int afs_evhashcnt = 0;
+
+/* Get and initialize event structure corresponding to lwp event (i.e. address)
+ * */
+static afs_event_t *
+afs_getevent(char *event)
+{
+    afs_event_t *evp, *newp = 0;
+    int hashcode;
+
+    AFS_ASSERT_GLOCK();
+    hashcode = afs_evhash(event);
+    evp = afs_evhasht[hashcode];
+    while (evp) {
+        if (evp->event == event) {
+            evp->refcount++;
+            return evp;
+        }
+        if (evp->refcount == 0)
+            newp = evp;
+        evp = evp->next;
+    }
+    if (!newp) {
+        newp = osi_AllocSmallSpace(sizeof(afs_event_t));
+        afs_evhashcnt++;
+        newp->next = afs_evhasht[hashcode];
+        afs_evhasht[hashcode] = newp;
+        newp->seq = 0;
+    }
+    newp->event = event;
+    newp->refcount = 1;
+    return newp;
+}
+
+/* Release the specified event */
+#define relevent(evp) ((evp)->refcount--)
+
+int
+afs_osi_TimedSleep(void *event, afs_int32 ams, int aintok)
+{
+    int code = 0;
+    struct afs_event *evp;
+    int seq, prio;
+    int ticks;
+
+    evp = afs_getevent(event);
+    seq = evp->seq;
+    AFS_GUNLOCK();
+    if (aintok)
+       prio = PCATCH | PPAUSE;
+    else
+       prio = PVFS;
+    ticks = (ams * afs_hz) / 1000;
+    code = tsleep(event, prio, "afs_osi_TimedSleep", ticks);
+    if (seq == evp->seq)
+       code = EINTR;
+    relevent(evp);
+    AFS_GLOCK();
+    return code;
+}
+
 void
 afs_osi_Sleep(void *event)
 {
     AFS_ASSERT_GLOCK();
     AFS_GUNLOCK();
-    tsleep(event, PVFS, "afs", 0);
+    tsleep(event, PVFS, "afsslp", 0);
     AFS_GLOCK();
 }
 
 int
 afs_osi_SleepSig(void *event)
 {
-    AFS_ASSERT_GLOCK();
-    AFS_GUNLOCK();
-    tsleep(event, PVFS, "afs", 0);
-    AFS_GLOCK();
+    afs_osi_Sleep(event);
     return 0;
 }