Commit 72c51354 authored by zhujiashun's avatar zhujiashun

fix the problem that tls data cannot be read in destructor which is specified by pthread_key_create

parent 0fe6c3d0
...@@ -233,9 +233,8 @@ void return_keytable(bthread_keytable_pool_t* pool, KeyTable* kt) { ...@@ -233,9 +233,8 @@ void return_keytable(bthread_keytable_pool_t* pool, KeyTable* kt) {
pool->free_keytables = kt; pool->free_keytables = kt;
} }
static void cleanup_pthread() { static void cleanup_pthread(void* arg) {
KeyTable* kt = tls_bls.keytable; KeyTable* kt = static_cast<KeyTable*>(arg);
//TODO(zhujiashun): thread local storage not works in macos using clang
if (kt) { if (kt) {
delete kt; delete kt;
// After deletion: tls may be set during deletion. // After deletion: tls may be set during deletion.
...@@ -447,7 +446,7 @@ int bthread_setspecific(bthread_key_t key, void* data) { ...@@ -447,7 +446,7 @@ int bthread_setspecific(bthread_key_t key, void* data) {
} }
if (!bthread::tls_ever_created_keytable) { if (!bthread::tls_ever_created_keytable) {
bthread::tls_ever_created_keytable = true; bthread::tls_ever_created_keytable = true;
CHECK_EQ(0, butil::thread_atexit(bthread::cleanup_pthread)); CHECK_EQ(0, butil::thread_atexit(bthread::cleanup_pthread, kt));
} }
} }
return kt->set_data(key, data); return kt->set_data(key, data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment