aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat_winthreads.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-08-18 08:56:31 -0400
committerNick Mathewson <nickm@torproject.org>2015-08-18 08:56:31 -0400
commiteafae7f677364175e384d0e2c79f05e7d300049d (patch)
treec91e6744961a2c38cdec3ce559199b4834c548c5 /src/common/compat_winthreads.c
parentfe4c0a187dcc6ec8a14175dfc4c62334221d4239 (diff)
parent087cf882c6a9ef6b9617d21ef26c19c47a4fc660 (diff)
downloadtor-eafae7f677364175e384d0e2c79f05e7d300049d.tar.gz
tor-eafae7f677364175e384d0e2c79f05e7d300049d.zip
Merge branch 'decouple_controller_events_squashed'
Diffstat (limited to 'src/common/compat_winthreads.c')
-rw-r--r--src/common/compat_winthreads.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/common/compat_winthreads.c b/src/common/compat_winthreads.c
index 465ef3ebed..9a87daa871 100644
--- a/src/common/compat_winthreads.c
+++ b/src/common/compat_winthreads.c
@@ -125,6 +125,49 @@ tor_cond_signal_all(tor_cond_t *cond)
}
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)
+{
+ 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);
+ 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
tor_cond_wait(tor_cond_t *cond, tor_mutex_t *lock_, const struct timeval *tv)
{
CRITICAL_SECTION *lock = &lock_->mutex;