/*
* 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
#endif
static int SignalSignals(void);
-\f
+
/********************************\
* *
* Stuff for managing IoRequests *
static void *(*sigProc[NSOFTSIG])(void *);
static void *sigRock[NSOFTSIG];
-\f
+
static struct IoRequest *iorFreeList = 0;
static struct TM_Elem *Requests; /* List of requests */
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.
iomgrFreeFDSets = iomgrFreeFDSets->next;
}
else {
- t = (struct IOMGR_fd_set *)malloc(sizeof(fd_set));
+ t = malloc(sizeof(fd_set));
}
if (!t)
return (fd_set*)0;
{
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.
*
#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)
if (fd_set1 == NULL || fd_set1->fd_count == 0)
return;
-
+
if (fd_set2 == NULL || fd_set2->fd_count == 0) {
FD_ZERO(fd_set1);
}
}
}
#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)
{
}
#endif
iomgr_errno = errno;
- lwp_abort();
+ opr_abort();
}
}
}
return (void *)-1; /* keeps compilers happy. */
}
-\f
+
/************************\
* *
* Signalling routines *
return;
})
}
-\f
+
/*****************************************************\
* *
* Signal handling routine (not to be confused with *
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;
}
return gotone;
}
-\f
+
/***************************\
* *
* User-callable routines *
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);
}
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) {
if (fds < req->nfds)
fds = req->nfds;
})
-
+
tv.tv_sec = 0;
tv.tv_usec = 0;
#ifdef AFS_NT40_ENV
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;
fprintf(stderr, "IOMGR_Select: fds=%d, more than max %d\n",
fds, FD_SETSIZE);
fflush(stderr);
- lwp_abort();
+ opr_abort();
}
#endif
* can also get this error return
*/
if (code < 0 && errno == EAGAIN)
- goto again;
+ goto again;
#endif
#ifdef AFS_NT40_ENV
if (code == SOCKET_ERROR) {
FreeRequest(request);
return (result > 1 ? 1 : result);
}
-\f
+
int IOMGR_Cancel(PROCESS pid)
{
struct IoRequest *request;
return 0;
}
-\f
+
#ifndef AFS_NT40_ENV
/* Cause delivery of signal signo to result in a LWP_SignalProcess of
event. */
timeout.tv_usec = 0;
IOMGR_Select(0, 0, 0, 0, &timeout);
}
-#endif /* USE_PTHREADS */