summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorJoe Mistachkin <joe@mistachkin.com>2015-10-21 20:18:58 (GMT)
committerJoe Mistachkin <joe@mistachkin.com>2015-10-21 20:18:58 (GMT)
commit09ea45da659a9f307db9b53c6f15886435f5af81 (patch)
treeb59bcc933e315941931517b6417b9e4457ede63b /win
parent55eaa262af18233fe7993814273589f53aa273c2 (diff)
downloadtcl-bug_57945b574a.zip
tcl-bug_57945b574a.tar.gz
tcl-bug_57945b574a.tar.bz2
Further cleanup and enhancements.bug_57945b574a
Diffstat (limited to 'win')
-rw-r--r--win/tclWinThrd.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c
index ed30879..4922cc6 100644
--- a/win/tclWinThrd.c
+++ b/win/tclWinThrd.c
@@ -626,6 +626,37 @@ static void FinalizeConditionEvent(ClientData data);
/*
*----------------------------------------------------------------------
*
+ * TclpMutexWait
+ *
+ * This procedure is used to delay for a short interval while
+ * waiting for a mutex to be unlocked by another thread.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The value of the retry parameter is changed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+TclpMutexWait(
+ Tcl_Mutex *mutexPtr, /* Mutex passed to Tcl_MutexLock. */
+ int *retry, /* The number of retries so far. */
+ ClientData clientData) /* The extra data, if any. */
+{
+ int nRetry = (retry != NULL) ? *retry : 0;
+ if (nRetry > TCL_MUTEX_LOCK_RESET_LIMIT) {
+ nRetry = 0;
+ }
+ Tcl_Sleep(TCL_MUTEX_LOCK_SLEEP_TIME * nRetry);
+ if (retry != NULL) *retry = nRetry;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Tcl_MutexLock --
*
* This procedure is invoked to lock a mutex. This is a self initializing
@@ -679,12 +710,9 @@ retry:
TclpMutexUnlock();
mutexWaitProc = TclGetMutexWaitProc();
if (mutexWaitProc != NULL) {
- mutexWaitProc(mutexPtr, nRetry, NULL);
+ mutexWaitProc(mutexPtr, &nRetry, NULL);
} else {
- if (nRetry > TCL_MUTEX_LOCK_RESET_LIMIT) {
- nRetry = 0;
- }
- Tcl_Sleep(TCL_MUTEX_LOCK_SLEEP_TIME * nRetry);
+ TclpMutexWait(mutexPtr, &nRetry, NULL);
}
nRetry++;
}