From 451bb0670ddd5f5c0606410f2b5f51733119645d Mon Sep 17 00:00:00 2001 From: rpj Date: Sat, 3 Apr 1999 22:05:39 +0000 Subject: ./ChangeLog Sun Apr 4 11:05:57 1999 Ross Johnson * sched.c (sched.h): Include. * sched.h: New file for POSIX 1b scheduling. * pthread.h: Move opaque structures to implement.h; move sched_* prototypes out and into sched.h. * implement.h: Add opaque structures from pthread.h. * sched.c (sched_yield): New function. * condvar.c (_pthread_sem_*): Rename to sem_*; except for _pthread_sem_timedwait which is an private function. Sat Apr 3 23:28:00 1999 Ross Johnson * Makefile.in (OBJS): Add errno.o. Fri Apr 2 11:08:50 1999 Ross Johnson * implement.h (_pthread_sem_*): Remove prototypes now defined in semaphore.h. * pthread.h (sempahore.h): Include. * semaphore.h: New file for POSIX 1b semaphores. * pthread.h (_pthread_sem_t): Change to sem_t. * semaphore.c (_pthread_sem_*): Change to sem_*; these functions will be exported from the library; set errno on error. - John Bossom (_pthread_sem_timedwait): Moved to private.c. * private.c (_pthread_sem_timedwait): Moved from semaphore.c; set errno on error. * errno.c (_errno): New file. New function. - John Bossom * pthread.h (pthread_t_): Add per-thread errno element. tests/ChangeLog Sun Apr 4 12:04:28 1999 Ross Johnson * tsd1.c (mythread): Change Sleep(0) to sched_yield(). (sched.h): Include. * condvar3.c (mythread): Remove redundant Sleep(). * runtest.bat: Re-organised to make more informative. --- implement.h | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 123 insertions(+), 14 deletions(-) (limited to 'implement.h') diff --git a/implement.h b/implement.h index 7740e0c..6151ce4 100644 --- a/implement.h +++ b/implement.h @@ -27,11 +27,111 @@ #ifndef _IMPLEMENT_H #define _IMPLEMENT_H +#include + +typedef enum { + /* + * This enumeration represents the state of the thread; + * The thread is still "alive" if the numeric value of the + * state is greater or equal "PThreadStateRunning". + */ + PThreadStateInitial = 0, /* Thread not running */ + PThreadStateRunning, /* Thread alive & kicking */ + PThreadStateSuspended, /* Thread alive but suspended */ + PThreadStateCanceling, /* Thread alive but and is */ + /* in the process of terminating */ + /* due to a cancellation request */ + PThreadStateException, /* Thread alive but exiting */ + /* due to an exception */ + PThreadStateLast +} +PThreadState; + + +typedef enum { + /* + * This enumeration represents the reason why a thread has + * terminated/is terminating. + */ + PThreadDemisePeaceful = 0, /* Death due natural causes */ + PThreadDemiseCancelled, /* Death due to user cancel */ + PThreadDemiseException, /* Death due to unhandled */ + /* exception */ + PThreadDemiseNotDead /* I'm not dead! */ +} +PThreadDemise; + +struct pthread_t_ { + DWORD thread; + HANDLE threadH; + PThreadState state; + PThreadDemise demise; + void *exitStatus; + void *parms; + int ptErrno; + int detachState; + int cancelState; + int cancelType; + HANDLE cancelEvent; +#if HAVE_SIGSET_T + sigset_t sigmask; +#endif /* HAVE_SIGSET_T */ + int implicit:1; + void *keys; +}; + + +/* + * Special value to mark attribute objects as valid. + */ +#define _PTHREAD_ATTR_VALID ((unsigned long) 0xC4C0FFEE) + +struct pthread_attr_t_ { + unsigned long valid; + void *stackaddr; + size_t stacksize; + int detachstate; + int priority; +#if HAVE_SIGSET_T + sigset_t sigmask; +#endif /* HAVE_SIGSET_T */ +}; + + +/* + * ==================== + * ==================== + * Mutexes and Condition Variables + * ==================== + * ==================== + */ + +#define _PTHREAD_OBJECT_AUTO_INIT ((void *) -1) +#define _PTHREAD_OBJECT_INVALID NULL + +struct pthread_mutex_t_ { + HANDLE mutex; + CRITICAL_SECTION cs; +}; + + +struct pthread_mutexattr_t_ { + int pshared; + int forcecs; +}; + + +struct pthread_key_t_ { + DWORD key; + void (*destructor) (void *); + pthread_mutex_t threadsLock; + void *threads; +}; + typedef struct ThreadParms ThreadParms; typedef struct ThreadKeyAssoc ThreadKeyAssoc; - struct ThreadParms { pthread_t tid; void *(*start) (void *); @@ -39,6 +139,27 @@ struct ThreadParms { }; +struct pthread_cond_t_ { + long waiters; /* # waiting threads */ + pthread_mutex_t waitersLock; /* Mutex that guards access to + waiter count */ + sem_t sema; /* Queue up threads waiting for the + condition to become signaled */ + HANDLE waitersDone; /* An auto reset event used by the + broadcast/signal thread to wait + for the waiting thread(s) to wake + up and get a chance at the + semaphore */ + int wasBroadcast; /* keeps track if we are signaling + or broadcasting */ +}; + + +struct pthread_condattr_t_ { + int pshared; +}; + + struct ThreadKeyAssoc { /* * Purpose: @@ -198,21 +319,9 @@ int _pthread_tkAssocCreate (ThreadKeyAssoc ** assocP, void _pthread_tkAssocDestroy (ThreadKeyAssoc * assoc); -int _pthread_sem_init (_pthread_sem_t * sem, - int pshared, - unsigned int value); - -int _pthread_sem_destroy (_pthread_sem_t * sem); - -int _pthread_sem_trywait (_pthread_sem_t * sem); - -int _pthread_sem_wait (_pthread_sem_t * sem); - -int _pthread_sem_timedwait (_pthread_sem_t * sem, +int _pthread_sem_timedwait (sem_t * sem, const struct timespec * abstime); -int _pthread_sem_post (_pthread_sem_t * sem); - #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit v1.2.3