diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-08-12 10:49:19 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-08-18 08:56:23 -0400 |
commit | 9ec94f1d22a87fbf86f721c6106f78f85b8be33c (patch) | |
tree | 9f2e36dad0208158c77be8a986e49973a4401988 /src/common/compat_pthreads.c | |
parent | e2a6a7ec6178834c3de7a3be614679120e2c00c8 (diff) | |
download | tor-9ec94f1d22a87fbf86f721c6106f78f85b8be33c.tar.gz tor-9ec94f1d22a87fbf86f721c6106f78f85b8be33c.zip |
Use thread-local storage to block event_queue recursion.
Diffstat (limited to 'src/common/compat_pthreads.c')
-rw-r--r-- | src/common/compat_pthreads.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c index b78ab3d871..4b32fc93d2 100644 --- a/src/common/compat_pthreads.c +++ b/src/common/compat_pthreads.c @@ -275,6 +275,33 @@ tor_cond_signal_all(tor_cond_t *cond) pthread_cond_broadcast(&cond->cond); } +int +tor_threadlocal_init(tor_threadlocal_t *threadlocal) +{ + int err = pthread_key_create(&threadlocal->key, NULL); + return err ? -1 : 0; +} + +void +tor_threadlocal_destroy(tor_threadlocal_t *threadlocal) +{ + pthread_key_delete(threadlocal->key); + memset(threadlocal, 0, sizeof(tor_threadlocal_t)); +} + +void * +tor_threadlocal_get(tor_threadlocal_t *threadlocal) +{ + return pthread_getspecific(threadlocal->key); +} + +void +tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value) +{ + int err = pthread_setspecific(threadlocal->key, value); + tor_assert(err == 0); +} + /** Set up common structures for use by threading. */ void tor_threads_init(void) |