diff options
author | rpj <rpj> | 1999-04-03 22:05:39 +0000 |
---|---|---|
committer | rpj <rpj> | 1999-04-03 22:05:39 +0000 |
commit | 451bb0670ddd5f5c0606410f2b5f51733119645d (patch) | |
tree | 09e56af6c763e0c7874cce25ac700daf9f1e93a0 /implement.h | |
parent | ad0b866780adf56e19114fb67ab2d532b4501425 (diff) |
./ChangeLog
Sun Apr 4 11:05:57 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* 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 <rpj@ixobrychus.canberra.edu.au>
* Makefile.in (OBJS): Add errno.o.
Fri Apr 2 11:08:50 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* 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 <jebossom@cognos.com>
(_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 <rpj@ixobrychus.canberra.edu.au>
* 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.
Diffstat (limited to 'implement.h')
-rw-r--r-- | implement.h | 137 |
1 files changed, 123 insertions, 14 deletions
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 <semaphore.h> + +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 */ |