diff options
author | Francis Ricci <francisjricci@gmail.com> | 2017-02-17 03:23:07 +0000 |
---|---|---|
committer | Francis Ricci <francisjricci@gmail.com> | 2017-02-17 03:23:07 +0000 |
commit | f3c9234d9af6d1c627cd111b001f054be34730cd (patch) | |
tree | 367958735f2f74437fdfa85bf86c85a0134803bc /lib/lsan/lsan_common_mac.cc | |
parent | aa1e41788966f989fd5b9d315b14de764cb498d3 (diff) |
Use pthreads to store current thread id on darwin
Summary:
__thread is not supported by all darwin versions and architectures,
use pthreads instead to allow for building darwin lsan on iossim.
Reviewers: kubamracek, kcc
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D29993
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295405 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/lsan/lsan_common_mac.cc')
-rw-r--r-- | lib/lsan/lsan_common_mac.cc | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/lib/lsan/lsan_common_mac.cc b/lib/lsan/lsan_common_mac.cc index a58d1cd8f..7f5e0550d 100644 --- a/lib/lsan/lsan_common_mac.cc +++ b/lib/lsan/lsan_common_mac.cc @@ -22,43 +22,46 @@ namespace __lsan { +typedef struct { + int disable_counter; + u32 current_thread_id; +} thread_local_data_t; + static pthread_key_t key; static pthread_once_t key_once = PTHREAD_ONCE_INIT; static void make_tls_key() { CHECK_EQ(pthread_key_create(&key, NULL), 0); } -static int *get_tls_val(bool allocate) { +static thread_local_data_t *get_tls_val() { pthread_once(&key_once, make_tls_key); - int *ptr = (int *)pthread_getspecific(key); - if (ptr == NULL && allocate) { - ptr = (int *)InternalAlloc(sizeof(*ptr)); - *ptr = 0; + thread_local_data_t *ptr = (thread_local_data_t *)pthread_getspecific(key); + if (ptr == NULL) { + ptr = (thread_local_data_t *)InternalAlloc(sizeof(*ptr)); + ptr->disable_counter = 0; + ptr->current_thread_id = kInvalidTid; pthread_setspecific(key, ptr); } return ptr; } -bool DisabledInThisThread() { - int *disable_counter = get_tls_val(false); - return disable_counter ? *disable_counter > 0 : false; -} - -void DisableInThisThread() { - int *disable_counter = get_tls_val(true); +bool DisabledInThisThread() { return get_tls_val()->disable_counter > 0; } - ++*disable_counter; -} +void DisableInThisThread() { ++get_tls_val()->disable_counter; } void EnableInThisThread() { - int *disable_counter = get_tls_val(true); + int *disable_counter = &get_tls_val()->disable_counter; if (*disable_counter == 0) { DisableCounterUnderflow(); } --*disable_counter; } +u32 GetCurrentThread() { return get_tls_val()->current_thread_id; } + +void SetCurrentThread(u32 tid) { get_tls_val()->current_thread_id = tid; } + void InitializePlatformSpecificModules() { CHECK(0 && "unimplemented"); } |