summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpj <rpj>2001-02-13 07:56:26 +0000
committerrpj <rpj>2001-02-13 07:56:26 +0000
commit4b26627e3f31905f0f739d57947d49995aa81913 (patch)
treed336baa9ce2b1fa7862e81beaf16626be4c2a1af
parent3208cee87389dbe7479e44208f8c0a4f8725fae8 (diff)
Change the thread cancel lock to be a critical section
instead of a pthread_mutex_t.
-rw-r--r--ChangeLog17
-rw-r--r--cancel.c22
-rw-r--r--create.c5
-rw-r--r--implement.h102
-rw-r--r--misc.c2
-rw-r--r--private.c22
6 files changed, 93 insertions, 77 deletions
diff --git a/ChangeLog b/ChangeLog
index bbbdf93..6bf2110 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2001-02-13 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
+
+ * misc.c (ptw32_new): Change cancelLock to be a
+ critical section type instead of pthread_mutex_t
+ because we want to use the cancel routines in
+ pthread_mutex_* routines - this avoids any
+ recursive problems.
+ * cancel.c (ptw32_cancel_thread): Likewise.
+ (pthread_setcancelstate): Likewise.
+ (pthread_setcanceltype): Likewise.
+ (pthread_cancel): Likewise.
+ * private.c (ExceptionFilter): Likewise.
+ (ptw32_terminate): Likewise.
+ (ptw32_threadStart): Likewise.
+ * create.c (pthread_create): Likewise.
+ * implement.h (pthread_t_.cancelLock): Likewise.
+
2001-02-12 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
* mutex.c (pthread_mutex_init): Revamped yet again.
diff --git a/cancel.c b/cancel.c
index 2e8aa41..baf21cb 100644
--- a/cancel.c
+++ b/cancel.c
@@ -44,7 +44,7 @@ ptw32_cancel_thread(pthread_t thread)
{
HANDLE threadH = thread->threadH;
- (void) pthread_mutex_lock(&thread->cancelLock);
+ EnterCriticalSection(&thread->cancelLock);
SuspendThread(threadH);
@@ -60,7 +60,7 @@ ptw32_cancel_thread(pthread_t thread)
ResumeThread(threadH);
}
- (void) pthread_mutex_unlock(&thread->cancelLock);
+ LeaveCriticalSection(&thread->cancelLock);
}
@@ -118,7 +118,7 @@ pthread_setcancelstate (int state, int *oldstate)
/*
* Lock for async-cancel safety.
*/
- (void) pthread_mutex_lock(&self->cancelLock);
+ EnterCriticalSection(&self->cancelLock);
if (oldstate != NULL)
{
@@ -135,13 +135,13 @@ pthread_setcancelstate (int state, int *oldstate)
&& WaitForSingleObject(self->cancelEvent, 0) == WAIT_OBJECT_0)
{
ResetEvent(self->cancelEvent);
- (void) pthread_mutex_unlock(&self->cancelLock);
+ LeaveCriticalSection(&self->cancelLock);
ptw32_throw(PTW32_EPS_CANCEL);
/* Never reached */
}
- (void) pthread_mutex_unlock(&self->cancelLock);
+ LeaveCriticalSection(&self->cancelLock);
return (result);
@@ -202,7 +202,7 @@ pthread_setcanceltype (int type, int *oldtype)
/*
* Lock for async-cancel safety.
*/
- (void) pthread_mutex_lock(&self->cancelLock);
+ EnterCriticalSection(&self->cancelLock);
if (oldtype != NULL)
{
@@ -219,13 +219,13 @@ pthread_setcanceltype (int type, int *oldtype)
&& WaitForSingleObject(self->cancelEvent, 0) == WAIT_OBJECT_0)
{
ResetEvent(self->cancelEvent);
- (void) pthread_mutex_unlock(&self->cancelLock);
+ LeaveCriticalSection(&self->cancelLock);
ptw32_throw(PTW32_EPS_CANCEL);
/* Never reached */
}
- (void) pthread_mutex_unlock(&self->cancelLock);
+ LeaveCriticalSection(&self->cancelLock);
return (result);
@@ -333,14 +333,14 @@ pthread_cancel (pthread_t thread)
/*
* Lock for async-cancel safety.
*/
- (void) pthread_mutex_lock(&self->cancelLock);
+ EnterCriticalSection(&self->cancelLock);
if (thread->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS
&& thread->cancelState == PTHREAD_CANCEL_ENABLE )
{
if (cancel_self)
{
- (void) pthread_mutex_unlock(&self->cancelLock);
+ LeaveCriticalSection(&self->cancelLock);
ptw32_throw(PTW32_EPS_CANCEL);
/* Never reached */
@@ -359,7 +359,7 @@ pthread_cancel (pthread_t thread)
}
}
- (void) pthread_mutex_unlock(&self->cancelLock);
+ LeaveCriticalSection(&self->cancelLock);
return (result);
diff --git a/create.c b/create.c
index f342ca4..c99807a 100644
--- a/create.c
+++ b/create.c
@@ -157,7 +157,8 @@ pthread_create (pthread_t * tid,
* This lock will force pthread_threadStart() to wait until we have
* the thread handle.
*/
- (void) pthread_mutex_lock(&thread->cancelLock);
+ InitializeCriticalSection(&thread->cancelLock);
+ EnterCriticalSection(&thread->cancelLock);
thread->threadH = threadH = (HANDLE)
_beginthread (
@@ -182,7 +183,7 @@ pthread_create (pthread_t * tid,
SuspendThread (threadH);
}
- (void) pthread_mutex_unlock(&thread->cancelLock);
+ LeaveCriticalSection(&thread->cancelLock);
#endif /* __MINGW32__ && ! __MSVCRT__ */
diff --git a/implement.h b/implement.h
index bd74d55..41c220d 100644
--- a/implement.h
+++ b/implement.h
@@ -73,23 +73,23 @@ typedef enum {
PThreadDemise;
struct pthread_t_ {
- DWORD thread;
- HANDLE threadH;
- PThreadState state;
- PThreadDemise demise;
- void *exitStatus;
- void *parms;
- int ptErrno;
- int detachState;
- pthread_mutex_t cancelLock; /* Used for async-cancel safety */
- int cancelState;
- int cancelType;
- HANDLE cancelEvent;
+ DWORD thread;
+ HANDLE threadH;
+ PThreadState state;
+ PThreadDemise demise;
+ void * exitStatus;
+ void * parms;
+ int ptErrno;
+ int detachState;
+ CriticalSection cancelLock; /* Used for async-cancel safety */
+ int cancelState;
+ int cancelType;
+ HANDLE cancelEvent;
#if HAVE_SIGSET_T
- sigset_t sigmask;
+ sigset_t sigmask;
#endif /* HAVE_SIGSET_T */
- int implicit:1;
- void *keys;
+ int implicit:1;
+ void * keys;
};
@@ -99,13 +99,13 @@ struct pthread_t_ {
#define PTW32_ATTR_VALID ((unsigned long) 0xC4C0FFEE)
struct pthread_attr_t_ {
- unsigned long valid;
- void *stackaddr;
- size_t stacksize;
- int detachstate;
- int priority;
+ unsigned long valid;
+ void * stackaddr;
+ size_t stacksize;
+ int detachstate;
+ int priority;
#if HAVE_SIGSET_T
- sigset_t sigmask;
+ sigset_t sigmask;
#endif /* HAVE_SIGSET_T */
};
@@ -147,26 +147,26 @@ struct pthread_attr_t_ {
#define PTW32_OBJECT_INVALID NULL
struct pthread_mutexattr_t_ {
- int pshared;
- int type;
+ int pshared;
+ int type;
};
struct pthread_mutex_t_ {
- long lock_idx;
- long try_lock;
- int pshared;
- int type;
- pthread_t owner;
- long waiters; /* These last elements ensure fairness */
- pthread_t lastOwner; /* and guard against canceled threads. */
- pthread_t lastWaiter;
+ long lock_idx;
+ long try_lock;
+ int pshared;
+ int type;
+ pthread_t owner;
+ long waiters; /* These last elements ensure fairness */
+ pthread_t lastOwner; /* and guard against canceled threads. */
+ pthread_t lastWaiter;
};
struct pthread_key_t_ {
- DWORD key;
+ DWORD key;
void (*destructor) (void *);
- pthread_mutex_t threadsLock;
- void *threads;
+ pthread_mutex_t threadsLock;
+ void * threads;
};
@@ -174,9 +174,9 @@ typedef struct ThreadParms ThreadParms;
typedef struct ThreadKeyAssoc ThreadKeyAssoc;
struct ThreadParms {
- pthread_t tid;
- void *(*start) (void *);
- void *arg;
+ pthread_t tid;
+ void *(*start) (void *);
+ void * arg;
};
@@ -196,23 +196,23 @@ struct pthread_cond_t_ {
struct pthread_condattr_t_ {
- int pshared;
+ int pshared;
};
#define PTW32_RWLOCK_MAGIC 0xfacade2
struct pthread_rwlock_t_ {
- pthread_mutex_t mtxExclusiveAccess;
- pthread_mutex_t mtxSharedAccessCompleted;
- pthread_cond_t cndSharedAccessCompleted;
- int nSharedAccessCount;
- int nExclusiveAccessCount;
- int nCompletedSharedAccessCount;
- int nMagic;
+ 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 {
@@ -266,11 +266,11 @@ struct ThreadKeyAssoc {
*
*
*/
- pthread_mutex_t lock;
- pthread_t thread;
- pthread_key_t key;
- ThreadKeyAssoc *nextKey;
- ThreadKeyAssoc *nextThread;
+ pthread_mutex_t lock;
+ pthread_t thread;
+ pthread_key_t key;
+ ThreadKeyAssoc * nextKey;
+ ThreadKeyAssoc * nextThread;
};
diff --git a/misc.c b/misc.c
index 20c90f6..9d83ea7 100644
--- a/misc.c
+++ b/misc.c
@@ -390,7 +390,7 @@ ptw32_new (void)
t->detachState = PTHREAD_CREATE_JOINABLE;
t->cancelState = PTHREAD_CANCEL_ENABLE;
t->cancelType = PTHREAD_CANCEL_DEFERRED;
- t->cancelLock = PTHREAD_MUTEX_INITIALIZER;
+ InitializeCriticalSection(t->cancelLock);
}
return t;
diff --git a/private.c b/private.c
index ee3ab52..4f3bb80 100644
--- a/private.c
+++ b/private.c
@@ -185,7 +185,7 @@ ExceptionFilter (EXCEPTION_POINTERS * ep, DWORD * ei)
*/
pthread_t self = pthread_self();
- (void) pthread_mutex_destroy(&self->cancelLock);
+ DeleteCriticalSection(&self->cancelLock);
ptw32_callUserDestroyRoutines(self);
return EXCEPTION_CONTINUE_SEARCH;
@@ -222,7 +222,7 @@ ptw32_terminate ()
pthread_mutex_unlock(&termLock);
#endif
set_terminate(ptw32_oldTerminate);
- (void) pthread_mutex_destroy(&self->cancelLock);
+ DeleteCriticalSection(&self->cancelLock);
ptw32_callUserDestroyRoutines(self);
terminate();
}
@@ -258,14 +258,12 @@ ptw32_threadStart (ThreadParms * threadParms)
* before it returns us the thread handle, and so we do it here.
*/
self->thread = GetCurrentThreadId ();
- if (pthread_mutex_lock(&self->cancelLock) == 0)
- {
- /*
- * We got the lock which means that our creator has
- * our thread handle. Unlock and continue on.
- */
- (void) pthread_mutex_unlock(&self->cancelLock);
- }
+ EnterCriticalSection(&self->cancelLock);
+ /*
+ * We got the lock which means that our creator has
+ * our thread handle. Unlock and continue on.
+ */
+ LeaveCriticalSection(&self->cancelLock);
#endif
pthread_setspecific (ptw32_selfThreadKey, self);
@@ -353,7 +351,7 @@ ptw32_threadStart (ThreadParms * threadParms)
* and release the exception out of thread scope.
*/
status = self->exitStatus = PTHREAD_CANCELED;
- (void) pthread_mutex_destroy(&self->cancelLock);
+ DeleteCriticalSection(&self->cancelLock);
(void) set_terminate(ptw32_oldTerminate);
ptw32_callUserDestroyRoutines(self);
throw;
@@ -377,7 +375,7 @@ ptw32_threadStart (ThreadParms * threadParms)
#endif /* _MSC_VER */
- (void) pthread_mutex_destroy(&self->cancelLock);
+ DeleteCriticalSection(&self->cancelLock);
#if 1
if (self->detachState == PTHREAD_CREATE_DETACHED)