summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfbonnet <fredericbonnet@free.fr>2018-06-09 17:20:15 (GMT)
committerfbonnet <fredericbonnet@free.fr>2018-06-09 17:20:15 (GMT)
commit7fe9e1b90c4464f3f288cecc3fa1d65bb6904cd1 (patch)
tree0256ca9b11a531320c08d906f859d1ab1cfa55a9
parentb91a2765aef7499e3bf0ca35d47c6dc068c35ed6 (diff)
downloadtcl-7fe9e1b90c4464f3f288cecc3fa1d65bb6904cd1.zip
tcl-7fe9e1b90c4464f3f288cecc3fa1d65bb6904cd1.tar.gz
tcl-7fe9e1b90c4464f3f288cecc3fa1d65bb6904cd1.tar.bz2
Removed thread-specific mutex lock counter and replaced by shared counter + thread ID for systems without PTHREAD_MUTEX_RECURSIVE
-rw-r--r--unix/tclUnixThrd.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c
index 3d3f81d..226552f 100644
--- a/unix/tclUnixThrd.c
+++ b/unix/tclUnixThrd.c
@@ -53,7 +53,8 @@ PMutexInit(
typedef struct PMutex {
pthread_mutex_t mutex;
- pthread_key_t counter;
+ pthread_t thread;
+ int counter;
} PMutex;
static void
@@ -62,7 +63,8 @@ PMutexInit(
)
{
pthread_mutex_init(&pmutexPtr->mutex, NULL);
- pthread_key_create(&pmutexPtr->counter, NULL);
+ pmutexPtr->thread = 0;
+ pmutexPtr->counter = 0;
}
static void
@@ -71,7 +73,6 @@ PMutexDestroy(
)
{
pthread_mutex_destroy(&pmutexPtr->mutex);
- pthread_key_delete(pmutexPtr->counter);
}
static void
@@ -79,11 +80,12 @@ PMutexLock(
PMutex *pmutexPtr
)
{
- intptr_t count = (intptr_t)pthread_getspecific(pmutexPtr->counter);
- pthread_setspecific(pmutexPtr->counter, (const void *)(count+1));
- if (count == 0) {
- pthread_mutex_lock(&pmutexPtr->mutex);
+ if (pmutexPtr->thread != pthread_self() || pmutexPtr->counter == 0) {
+ pthread_mutex_lock(&pmutexPtr->mutex);
+ pmutexPtr->thread = pthread_self();
+ pmutexPtr->counter = 0;
}
+ pmutexPtr->counter++;
}
static void
@@ -91,10 +93,10 @@ PMutexUnlock(
PMutex *pmutexPtr
)
{
- intptr_t count = (intptr_t)pthread_getspecific(pmutexPtr->counter);
- pthread_setspecific(pmutexPtr->counter, (const void *)(count-1));
- if (count == 1) {
- pthread_mutex_unlock(&pmutexPtr->mutex);
+ pmutexPtr->counter--;
+ if (pmutexPtr->counter == 0) {
+ pmutexPtr->thread = 0;
+ pthread_mutex_unlock(&pmutexPtr->mutex);
}
}