summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixThrd.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2025-09-17 11:06:17 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2025-09-17 11:06:17 (GMT)
commit866aec41d6d17c05d6260437e4a73628a8c0e109 (patch)
tree1d1394c1a15d2ff55655a141902c23ae40599cb1 /unix/tclUnixThrd.c
parent43ff0b5efc8e10a866c2d03ef5a8a118f3fdae34 (diff)
parentfe0a86c6895ab6837f6aa5d3352657b0865ae92f (diff)
downloadtcl-866aec41d6d17c05d6260437e4a73628a8c0e109.zip
tcl-866aec41d6d17c05d6260437e4a73628a8c0e109.tar.gz
tcl-866aec41d6d17c05d6260437e4a73628a8c0e109.tar.bz2
Rebase branch to 9.0
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,