From e121b938c9f012958196a3141f04a3fd4f58bdb9 Mon Sep 17 00:00:00 2001 From: rpj Date: Thu, 31 May 2001 02:01:47 +0000 Subject: 2001-05-30 Ross Johnson * pthread.h (rand_r): Fake using _seed argument to quell compiler warning (compiler should optimise this away later). * GNUmakefile (OPT): Leave symbolic information out of the library and increase optimisation level - for smaller faster prebuilt dlls. 2001-05-29 Ross Johnson Contributed by - Milan Gardian * Makefile: fix typo. * pthreads.h: Fix problems with stdcall/cdecl conventions, in particular remove the need for PT_STDCALL everywhere; remove warning supression. * (errno): Fix the longstanding "inconsistent dll linkage" problem with errno; now also works with /MD debugging libs - warnings emerged when compiling pthreads library with /MD (or /MDd) compiler switch, instead of /MT (or /MTd) (i.e. when compiling pthreads using Multithreaded DLL CRT instead of Multithreaded statically linked CRT). * create.c (pthread_create): Likewise; fix typo. * private.c (ptw32_threadStart): Eliminate use of terminate() which doesn't throw exceptions. * Remove unnecessary #includes from a number of modules - [I had to #include malloc.h in implement.h for gcc - rpj]. 2001-05-29 Ross Johnson Contributed by - Thomas Pfaff * pthread.h (PTHREAD_MUTEX_DEFAULT): New; equivalent to PTHREAD_MUTEX_DEFAULT_NP. * (PTHREAD_MUTEX_NORMAL): Similarly. * (PTHREAD_MUTEX_ERRORCHECK): Similarly. * (PTHREAD_MUTEX_RECURSIVE): Similarly. * (pthread_mutex_setdefaultkind_np): New; Linux compatibility stub for pthread_mutexattr_settype. * (pthread_mutexattr_getkind_np): New; Linux compatibility stub for pthread_mutexattr_gettype. * mutex.c (pthread_mutexattr_settype): New; allow the following types of mutex: PTHREAD_MUTEX_DEFAULT_NP PTHREAD_MUTEX_NORMAL_NP PTHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_RECURSIVE_NP * Note that PTHREAD_MUTEX_DEFAULT is equivalent to PTHREAD_MUTEX_NORMAL - ie. mutexes should no longer be recursive by default, and a thread will deadlock if it tries to relock a mutex it already owns. This is inline with other pthreads implementations. * (pthread_mutex_lock): Process the lock request according to the mutex type. * (pthread_mutex_init): Eliminate use of Win32 mutexes as the basis of POSIX mutexes - instead, a combination of one critical section and one semaphore are used in conjunction with Win32 Interlocked* routines. * (pthread_mutex_destroy): Likewise. * (pthread_mutex_lock): Likewise. * (pthread_mutex_trylock): Likewise. * (pthread_mutex_unlock): Likewise. * Use longjmp/setjmp to implement cancelation when building the library using a C compiler which doesn't support exceptions, e.g. gcc -x c (note that gcc -x c++ uses exceptions). * Also fixed some of the same typos and eliminated PT_STDCALL as Milan Gardian's patches above. 2001-02-07 Ross Johnson Contributed by - Alexander Terekhov * rwlock.c: Revamped. * implement.h (pthread_rwlock_t_): Redefined. This implementation does not have reader/writer starvation problem. Rwlock attempts to behave more like a normal mutex with races and scheduling policy determining who is more important; It also supports recursive locking, has less synchronization overhead (no broadcasts at all, readers are not blocked on any condition variable) and seem to be faster than the current implementation [W98 appears to be approximately 15 percent faster at least - on top of speed increase from Thomas Pfaff's changes to mutex.c - rpj]. --- implement.h | 65 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'implement.h') diff --git a/implement.h b/implement.h index c6f535e..fa02444 100644 --- a/implement.h +++ b/implement.h @@ -27,14 +27,8 @@ #ifndef _IMPLEMENT_H #define _IMPLEMENT_H -#ifdef __MINGW32__ -#define PT_STDCALL -#else -#ifdef __cplusplus -#define PT_STDCALL __stdcall -#else -#define PT_STDCALL __stdcall -#endif +#if defined(__MINGW32__) +#include #endif /* changed include from to use local file during development */ @@ -85,6 +79,9 @@ struct pthread_t_ { int cancelState; int cancelType; HANDLE cancelEvent; +#ifdef __CLEANUP_C + jmp_buf start_mark; +#endif /* __CLEANUP_C */ #if HAVE_SIGSET_T sigset_t sigmask; #endif /* HAVE_SIGSET_T */ @@ -122,16 +119,18 @@ struct pthread_attr_t_ { #define PTW32_OBJECT_INVALID NULL struct pthread_mutex_t_ { - HANDLE mutex; - CRITICAL_SECTION cs; - int lockCount; + LONG lock_idx; + int recursive_count; + int kind; pthread_t ownerThread; + HANDLE wait_sema; + CRITICAL_SECTION try_lock_cs; }; struct pthread_mutexattr_t_ { int pshared; - int forcecs; + int kind; }; @@ -173,23 +172,23 @@ struct pthread_condattr_t_ { int pshared; }; -#define RW_MAGIC 0x19283746 +#define PTW32_RWLOCK_MAGIC 0xfacade2 struct pthread_rwlock_t_ { - pthread_mutex_t rw_lock; /* basic lock on this struct */ - pthread_cond_t rw_condreaders; /* for reader threads waiting */ - pthread_cond_t rw_condwriters; /* for writer threads waiting */ - int rw_magic; /* for error checking */ - int rw_nwaitreaders; /* the number waiting */ - int rw_nwaitwriters; /* the number waiting */ - int rw_refcount; /* -1 if writer has the lock, - else # readers holding the lock */ + pthread_mutex_t mtxExclusiveAccess; + pthread_mutex_t mtxSharedAccessCompleted; + pthread_cond_t cndSharedAccessCompleted; + int nSharedAccessCount; + int nExclusiveAccessCount; + int nCompletedSharedAccessCount; + int nMagic; }; struct pthread_rwlockattr_t_ { - int pshared; + int pshared; }; + struct ThreadKeyAssoc { /* * Purpose: @@ -249,7 +248,7 @@ struct ThreadKeyAssoc { }; -#if defined(_MSC_VER) && !defined(__cplusplus) +#ifdef __CLEANUP_SEH /* * -------------------------------------------------------------- * MAKE_SOFTWARE_EXCEPTION @@ -292,25 +291,31 @@ struct ThreadKeyAssoc { #define PTW32_SERVICES_FACILITY 0xBAD #define PTW32_SERVICES_ERROR 0xDEED -#endif /* _MSC_VER */ +#endif /* __CLEANUP_SEH */ /* * Services available through EXCEPTION_PTW32_SERVICES * and also used [as parameters to ptw32_throw()] as * generic exception selectors. */ -#define PTW32_EPS_CANCEL 0 -#define PTW32_EPS_EXIT 1 +#define PTW32_EPS_EXIT (1) +#define PTW32_EPS_CANCEL (2) + +#define PTW32_MUTEX_LOCK_IDX_INIT (-1) /* Declared in global.c */ extern int ptw32_processInitialized; extern pthread_key_t ptw32_selfThreadKey; extern pthread_key_t ptw32_cleanupKey; + +extern int ptw32_mutex_default_kind; + +extern int ptw32_concurrency; + extern CRITICAL_SECTION ptw32_mutex_test_init_lock; extern CRITICAL_SECTION ptw32_cond_test_init_lock; extern CRITICAL_SECTION ptw32_rwlock_test_init_lock; -extern BOOL (WINAPI *ptw32_try_enter_critical_section)(LPCRITICAL_SECTION); /* Declared in misc.c */ @@ -339,16 +344,16 @@ void ptw32_processTerminate (void); void ptw32_threadDestroy (pthread_t tid); -void ptw32_cleanupStack (void); +void ptw32_pop_cleanup_all (int execute); pthread_t ptw32_new (void); #if ! defined (__MINGW32__) || defined (__MSVCRT__) -unsigned PT_STDCALL +unsigned __stdcall #else void #endif -ptw32_threadStart (ThreadParms * threadParms); +ptw32_threadStart (void * vthreadParms); void ptw32_callUserDestroyRoutines (pthread_t thread); -- cgit v1.2.3