summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixThrd.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/tclUnixThrd.c')
-rw-r--r--unix/tclUnixThrd.c48
1 files changed, 14 insertions, 34 deletions
diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c
index 24bc72d..219d0c6 100644
--- a/unix/tclUnixThrd.c
+++ b/unix/tclUnixThrd.c
@@ -61,40 +61,9 @@
*----------------------------------------------------------------------
*/
-#ifndef HAVE_DECL_PTHREAD_MUTEX_RECURSIVE
-#define HAVE_DECL_PTHREAD_MUTEX_RECURSIVE 0
-#endif
-
-#if HAVE_DECL_PTHREAD_MUTEX_RECURSIVE
/*
- * Pthread has native reentrant (AKA recursive) mutexes. Use them for
- * Tcl_Mutex.
- */
-
-typedef pthread_mutex_t PMutex;
-
-static void
-PMutexInit(
- PMutex *pmutexPtr)
-{
- pthread_mutexattr_t attr;
-
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(pmutexPtr, &attr);
-}
-
-#define PMutexDestroy pthread_mutex_destroy
-#define PMutexLock pthread_mutex_lock
-#define PMutexUnlock pthread_mutex_unlock
-#define PCondWait pthread_cond_wait
-#define PCondTimedWait pthread_cond_timedwait
-
-#else /* !HAVE_PTHREAD_MUTEX_RECURSIVE */
-
-/*
- * No native support for reentrant mutexes. Emulate them with regular mutexes
- * and thread-local counters.
+ * No correct native support for reentrant mutexes. Emulate them with regular mutexes
+ * and threadlocal counters.
*/
typedef struct PMutex {
@@ -147,7 +116,13 @@ PCondWait(
pthread_cond_t *pcondPtr,
PMutex *pmutexPtr)
{
+ int counter = pmutexPtr->counter;
+
+ pmutexPtr->thread = 0;
+ pmutexPtr->counter = 0;
pthread_cond_wait(pcondPtr, &pmutexPtr->mutex);
+ pmutexPtr->thread = pthread_self();
+ pmutexPtr->counter = counter;
}
static void
@@ -156,9 +131,14 @@ PCondTimedWait(
PMutex *pmutexPtr,
struct timespec *ptime)
{
+ int counter = pmutexPtr->counter;
+
+ pmutexPtr->thread = 0;
+ pmutexPtr->counter = 0;
pthread_cond_timedwait(pcondPtr, &pmutexPtr->mutex, ptime);
+ pmutexPtr->thread = pthread_self();
+ pmutexPtr->counter = counter;
}
-#endif /* HAVE_PTHREAD_MUTEX_RECURSIVE */
/*
* globalLock is used to serialize creation of mutexes, condition variables,