From 97cb4b33462735b93ac9522df6bf4d43d0b7fe71 Mon Sep 17 00:00:00 2001 From: bje Date: Sun, 4 Oct 1998 18:32:15 +0000 Subject: 1998-10-05 Ben Elliston * global.c (PTHREAD_MUTEX_INITIALIZER): Move to pthread.h. * pthread.h (PTHREAD_MUTEX_INITIALIZER): Define. (pthread_mutex_t): Reimplement as a struct containing a valid flag. If the flag is ever down upon entry to a mutex operation, we call pthread_mutex_create() to initialise the object. This fixes the problem of how to handle statically initialised objects that can't call InitializeCriticalSection() due to their context. * mutex.c (pthread_mutex_init): Set valid flag. (pthread_mutex_destroy): Clear valid flag. (pthread_mutex_lock): Check and handle the valid flag. (pthread_mutex_unlock): Likewise. (pthread_mutex_trylock): Likewise. * tests/mutex3.c: New file; test for the static initialisation macro. Passes. --- pthread.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pthread.h') diff --git a/pthread.h b/pthread.h index 5c31af2..e9278c2 100644 --- a/pthread.h +++ b/pthread.h @@ -74,8 +74,13 @@ struct timespec { pointer to an object in memory. */ #define PTHREAD_CANCELED ((void *) 1) +#define PTHREAD_MUTEX_INITIALIZER {0 /* ignore internals */ } + typedef struct _pthread * pthread_t; -typedef CRITICAL_SECTION pthread_mutex_t; +typedef struct { + int valid; + CRITICAL_SECTION cs; +} pthread_mutex_t; typedef DWORD pthread_key_t; -- cgit v1.2.3