lwp: zero reused request blocks
[openafs.git] / src / lwp / iomgr.c
index a1ef701..64e9f9c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#include <malloc.h>
-extern void lwp_abort(void);
-#else
-#include <unistd.h>            /* select() prototype */
-#include <sys/types.h>         /* fd_set on older platforms */
-#include <sys/time.h>          /* struct timeval, select() prototype */
-#ifndef FD_SET
-# include <sys/select.h>       /* fd_set on newer platforms */
-#endif
-#include <sys/file.h>
-#endif /* AFS_NT40_ENV */
-#include "lwp.h"
-#include "timer.h"
-#include <signal.h>
-#include <errno.h>
-#ifdef AFS_SUN5_ENV
-#include <fcntl.h>
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
 #endif
 
-#if    defined(USE_PTHREADS) || defined(USE_SOLARIS_THREADS)
-
-void IOMGR_Initialize()        /* noop */
-{ }
-
-void IOMGR_Sleep (seconds)
-  unsigned seconds;
-{
-    struct timespec itv;
-
-    itv.tv_sec = seconds;
-    itv.tv_nsec = 0;
-    assert(pthread_mutex_unlock(&lwp_mutex) == 0);
-    assert(pthread_delay_np(&itv) == 0);
-    assert(pthread_mutex_lock(&lwp_mutex) == 0);
-}
-
-#else
+#include <afs/opr.h>
 
-#ifdef AFS_DECOSF_ENV
-extern void *malloc();
-#endif /* AFS_DECOSF_ENV */
+#include "lwp.h"
+#include "timer.h"
 
 typedef unsigned char bool;
 #define FALSE  0
@@ -97,7 +60,7 @@ typedef unsigned char bool;
 #endif
 
 static int SignalSignals(void);
-\f
+
 /********************************\
 *                               *
 *  Stuff for managing IoRequests *
@@ -150,7 +113,7 @@ static int sigDelivered[NSIG];              /* True for signals delivered so far.
 static void *(*sigProc[NSOFTSIG])(void *);
 static void *sigRock[NSOFTSIG];
 
-\f
+
 static struct IoRequest *iorFreeList = 0;
 
 static struct TM_Elem *Requests;       /* List of requests */
@@ -164,7 +127,7 @@ static void SignalIO(int fds, fd_set *rfds, fd_set *wfds, fd_set *efs,
                    int code);
 static void SignalTimeout(int code, struct timeval *timeout);
 
-/* fd_set pool managment. 
+/* fd_set pool managment.
  * Use the pool instead of creating fd_set's on the stack. fd_set's can be
  * 8K in size, so making three could put 24K in the limited space of an LWP
  * stack.
@@ -195,7 +158,7 @@ fd_set *IOMGR_AllocFDSet(void)
        iomgrFreeFDSets = iomgrFreeFDSets->next;
     }
     else {
-       t = (struct IOMGR_fd_set *)malloc(sizeof(fd_set));
+       t = malloc(sizeof(fd_set));
     }
     if (!t)
        return (fd_set*)0;
@@ -211,17 +174,17 @@ static struct IoRequest *NewRequest(void)
 {
     struct IoRequest *request;
 
-    if ((request=iorFreeList))
+    if ((request=iorFreeList)) {
        iorFreeList = (struct IoRequest *) (request->next);
-    else request = (struct IoRequest *) malloc(sizeof(struct IoRequest));
+       memset(request, 0, sizeof(struct IoRequest));
+    } else request = calloc(1, sizeof(struct IoRequest));
 
-    memset((char*)request, 0, sizeof(struct IoRequest));
     return request;
 }
 
 #define Purge(list) FOR_ALL_ELTS(req, list, { free(req->BackPointer); })
 
-\f
+
 /* FD_SET support routines. All assume the fd_set size is a multiple of an int
  * so we can at least do logical operations on ints instead of chars.
  *
@@ -306,7 +269,7 @@ static void FDSetSet(int nfds, fd_set *fd_set1, fd_set *fd_set2)
 #endif
 }
 
-/* FDSetAnd - fd_set1  <- fd_set1 & fd_set2. 
+/* FDSetAnd - fd_set1  <- fd_set1 & fd_set2.
  */
 #ifdef AFS_NT40_ENV
 static void FDSetAnd(int nfds, fd_set *fd_set1, fd_set *fd_set2)
@@ -316,7 +279,7 @@ static void FDSetAnd(int nfds, fd_set *fd_set1, fd_set *fd_set2)
 
     if (fd_set1 == NULL || fd_set1->fd_count == 0)
        return;
-    
+
     if (fd_set2 == NULL || fd_set2->fd_count == 0) {
        FD_ZERO(fd_set1);
     }
@@ -343,8 +306,8 @@ static void FDSetAnd(int nfds, fd_set *fd_set1, fd_set *fd_set2)
     }
 }
 #endif
-           
-/* FDSetEmpty - return true if fd_set is empty 
+
+/* FDSetEmpty - return true if fd_set is empty
  */
 static int FDSetEmpty(int nfds, fd_set *fds)
 {
@@ -587,7 +550,7 @@ static void *IOMGR(void *dummy)
                  }
 #endif
                  iomgr_errno = errno;
-                 lwp_abort();
+                 opr_abort();
               }
            }
 
@@ -622,7 +585,7 @@ static void *IOMGR(void *dummy)
     }
     return (void *)-1; /* keeps compilers happy. */
 }
-\f
+
 /************************\
 *                       *
 *  Signalling routines          *
@@ -670,7 +633,7 @@ static void SignalTimeout(int code, struct timeval *timeout)
            return;
     })
 }
-\f
+
 /*****************************************************\
 *                                                    *
 *  Signal handling routine (not to be confused with   *
@@ -704,7 +667,7 @@ static int SignalSignals (void)
     for (i=0; i < NSOFTSIG; i++) {
        PROCESS pid;
        if ((p=sigProc[i])) /* This yields!!! */
-           LWP_CreateProcess2(p, stackSize, LWP_NORMAL_PRIORITY, 
+           LWP_CreateProcess2(p, stackSize, LWP_NORMAL_PRIORITY,
                               sigRock[i], "SignalHandler", &pid);
        sigProc[i] = 0;
     }
@@ -718,7 +681,7 @@ static int SignalSignals (void)
     return gotone;
 }
 
-\f
+
 /***************************\
 *                          *
 *  User-callable routines   *
@@ -766,7 +729,7 @@ int IOMGR_Initialize(void)
     anySigsDelivered = TRUE; /* A soft signal may have happened before
        IOMGR_Initialize:  so force a check for signals regardless */
 
-    return LWP_CreateProcess(IOMGR, AFS_LWP_MINSTACKSIZE, 0, (void *) 0, 
+    return LWP_CreateProcess(IOMGR, AFS_LWP_MINSTACKSIZE, 0, (void *) 0,
                             "IO MANAGER", &IOMGR_Id);
 }
 
@@ -780,7 +743,7 @@ int IOMGR_Finalize(void)
     IOMGR_Id = NULL;
     return status;
 }
-\f
+
 /* signal I/O for anyone who is waiting for a FD or a timeout; not too cheap,
  * since forces select and timeofday check */
 int IOMGR_Poll(void) {
@@ -835,7 +798,7 @@ int IOMGR_Poll(void) {
        if (fds < req->nfds)
            fds = req->nfds;
     })
-       
+
     tv.tv_sec = 0;
     tv.tv_usec = 0;
 #ifdef AFS_NT40_ENV
@@ -858,7 +821,7 @@ int IOMGR_Poll(void) {
     return 0;
 }
 
-int IOMGR_Select(int fds, fd_set *readfds, fd_set *writefds, 
+int IOMGR_Select(int fds, fd_set *readfds, fd_set *writefds,
                 fd_set *exceptfds, struct timeval *timeout)
 {
     struct IoRequest *request;
@@ -869,7 +832,7 @@ int IOMGR_Select(int fds, fd_set *readfds, fd_set *writefds,
        fprintf(stderr, "IOMGR_Select: fds=%d, more than max %d\n",
                fds, FD_SETSIZE);
        fflush(stderr);
-       lwp_abort();
+       opr_abort();
     }
 #endif
 
@@ -893,7 +856,7 @@ again:
             * can also get this error return
             */
            if (code < 0 && errno == EAGAIN)
-               goto again;     
+               goto again;
 #endif
 #ifdef AFS_NT40_ENV
            if (code == SOCKET_ERROR) {
@@ -955,7 +918,7 @@ again:
     FreeRequest(request);
     return (result > 1 ? 1 : result);
 }
-\f
+
 int IOMGR_Cancel(PROCESS pid)
 {
     struct IoRequest *request;
@@ -978,7 +941,7 @@ int IOMGR_Cancel(PROCESS pid)
 
     return 0;
 }
-\f
+
 #ifndef AFS_NT40_ENV
 /* Cause delivery of signal signo to result in a LWP_SignalProcess of
    event. */
@@ -1020,4 +983,3 @@ void IOMGR_Sleep (int seconds)
     timeout.tv_usec = 0;
     IOMGR_Select(0, 0, 0, 0, &timeout);
 }
-#endif /* USE_PTHREADS */