From 9ec94f1d22a87fbf86f721c6106f78f85b8be33c Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 12 Aug 2015 10:49:19 -0400 Subject: Use thread-local storage to block event_queue recursion. --- src/common/compat_winthreads.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/common/compat_winthreads.c') diff --git a/src/common/compat_winthreads.c b/src/common/compat_winthreads.c index 71b994c4e4..3d9e236d8b 100644 --- a/src/common/compat_winthreads.c +++ b/src/common/compat_winthreads.c @@ -122,6 +122,33 @@ tor_cond_signal_all(tor_cond_t *cond) tor_cond_signal_impl(cond, 1); } +int +tor_threadlocal_init(tor_threadlocal_t *threadlocal) +{ + threadlocal->index = TlsAlloc(); + return (threadlocal->index == TLS_OUT_OF_INDEXES) ? -1 : 0; +} + +void +tor_threadlocal_destroy(tor_threadlocal_t *threadlocal) +{ + TlsFree(threadlocal->index); + memset(threadlocal, 0, sizeof(tor_threadlocal_t)); +} + +void * +tor_threadlocal_get(tor_threadlocal_t *threadlocal) +{ + return TlsGetValue(threadlocal->index); +} + +void +tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value) +{ + BOOL ok = TlsSetValue(threadlocal->index, value); + tor_assert(ok); +} + int tor_cond_wait(tor_cond_t *cond, tor_mutex_t *lock_, const struct timeval *tv) { -- cgit v1.2.3-54-g00ecf From 087cf882c6a9ef6b9617d21ef26c19c47a4fc660 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Aug 2015 08:37:15 -0400 Subject: Log meaningful messages before failing on windows with threadlocal. --- src/common/compat_winthreads.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/common/compat_winthreads.c') diff --git a/src/common/compat_winthreads.c b/src/common/compat_winthreads.c index 3d9e236d8b..381e338877 100644 --- a/src/common/compat_winthreads.c +++ b/src/common/compat_winthreads.c @@ -139,14 +139,30 @@ tor_threadlocal_destroy(tor_threadlocal_t *threadlocal) void * tor_threadlocal_get(tor_threadlocal_t *threadlocal) { - return TlsGetValue(threadlocal->index); + void *value = TlsGetValue(threadlocal->index); + if (value == NULL) { + DWORD err = GetLastError(); + if (err != ERROR_SUCCESS) { + char *msg = format_win32_error(err); + log_err(LD_GENERAL, "Error retrieving thread-local value: %s", msg); + tor_free(msg); + tor_assert(err == ERROR_SUCCESS); + } + } + return value; } void tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value) { BOOL ok = TlsSetValue(threadlocal->index, value); - tor_assert(ok); + if (!ok) { + DWORD err = GetLastError(); + char *msg = format_win32_error(err); + log_err(LD_GENERAL, "Error adjusting thread-local value: %s", msg); + tor_free(msg); + tor_assert(ok); + } } int -- cgit v1.2.3-54-g00ecf