Skip to content

Commit f7ab9dd

Browse files
committed
add attribute noinline to tls_bls
update
1 parent 15b52c5 commit f7ab9dd

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/bthread/task_group.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@ int TaskGroup::init(size_t runqueue_capacity) {
297297
return 0;
298298
}
299299

300+
// use noinline to avoid read wrong tls due to compiler optimization
301+
// https://github.com/apache/brpc/issues/1776
302+
__attribute__((noinline)) void clean_tls_bls(TaskMeta* const m) {
303+
KeyTable* kt = tls_bls.keytable;
304+
if (kt != NULL) {
305+
return_keytable(m->attr.keytable_pool, kt);
306+
tls_bls.keytable = NULL;
307+
m->local_storage.keytable = NULL; // optional
308+
}
309+
}
310+
300311
#ifdef BUTIL_USE_ASAN
301312
void TaskGroup::asan_task_runner(intptr_t) {
302313
// This is a new thread, and it doesn't have the fake stack yet. ASan will
@@ -372,13 +383,7 @@ void TaskGroup::task_runner(intptr_t skip_remained) {
372383
// Clean tls variables, must be done before changing version_butex
373384
// otherwise another thread just joined this thread may not see side
374385
// effects of destructing tls variables.
375-
KeyTable* kt = tls_bls.keytable;
376-
if (kt != NULL) {
377-
return_keytable(m->attr.keytable_pool, kt);
378-
// After deletion: tls may be set during deletion.
379-
tls_bls.keytable = NULL;
380-
m->local_storage.keytable = NULL; // optional
381-
}
386+
clean_tls_bls(m);
382387

383388
// During running the function in TaskMeta and deleting the KeyTable in
384389
// return_KeyTable, the group is probably changed.

0 commit comments

Comments
 (0)