aboutsummaryrefslogtreecommitdiff
path: root/src/lib/thread
diff options
context:
space:
mode:
authorDaniel Pinto <danielpinto52@gmail.com>2020-11-12 19:40:07 +0000
committerDaniel Pinto <danielpinto52@gmail.com>2020-11-12 19:50:55 +0000
commit877dbfc0561dfc5297cf446fe653cc3095d20b46 (patch)
tree764653ed71dc88f2786f3d1a94288c4b3479b5d3 /src/lib/thread
parent46ccde66a97d7985388eb54bc74a025402fb0a19 (diff)
downloadtor-877dbfc0561dfc5297cf446fe653cc3095d20b46.tar.gz
tor-877dbfc0561dfc5297cf446fe653cc3095d20b46.zip
Use SRWLocks to implement locking on Windows #17927
Replace the Windows locking implementation which used critical sections with the faster SRWLocks available since Vista.
Diffstat (limited to 'src/lib/thread')
-rw-r--r--src/lib/thread/compat_winthreads.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/lib/thread/compat_winthreads.c b/src/lib/thread/compat_winthreads.c
index fcc9c0279b..a6213aa46a 100644
--- a/src/lib/thread/compat_winthreads.c
+++ b/src/lib/thread/compat_winthreads.c
@@ -144,13 +144,17 @@ tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value)
int
tor_cond_wait(tor_cond_t *cond, tor_mutex_t *lock_, const struct timeval *tv)
{
- CRITICAL_SECTION *lock = &lock_->mutex;
+ // recursive SRW locks are not supported because they need extra logic for
+ // acquiring and releasing but SleepConditionVariableSRW will use the OS
+ // lock relase function which lacks our extra logic
+ tor_assert(lock_->type == NON_RECURSIVE);
+ SRWLOCK *lock = &lock_->mutex;
DWORD ms = INFINITE;
if (tv) {
ms = tv->tv_sec*1000 + (tv->tv_usec+999)/1000;
}
- BOOL ok = SleepConditionVariableCS(&cond->cond, lock, ms);
+ BOOL ok = SleepConditionVariableSRW(&cond->cond, lock, ms, 0);
if (!ok) {
DWORD err = GetLastError();
if (err == ERROR_TIMEOUT) {