File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -415,7 +415,7 @@ class BAIDU_CACHELINE_ALIGNMENT ObjectPool {
415415 }
416416
417417 inline LocalPool* get_or_new_local_pool () {
418- LocalPool* lp = _local_pool;
418+ LocalPool* lp = BAIDU_GET_VOLATILE_THREAD_LOCAL ( _local_pool) ;
419419 if (BAIDU_LIKELY (lp != NULL )) {
420420 return lp;
421421 }
@@ -424,7 +424,7 @@ class BAIDU_CACHELINE_ALIGNMENT ObjectPool {
424424 return NULL ;
425425 }
426426 BAIDU_SCOPED_LOCK (_change_thread_mutex); // avoid race with clear()
427- _local_pool = lp ;
427+ BAIDU_SET_VOLATILE_THREAD_LOCAL ( _local_pool, lp) ;
428428 butil::thread_atexit (LocalPool::delete_local_pool, lp);
429429 _nlocal.fetch_add (1 , butil::memory_order_relaxed);
430430 return lp;
@@ -523,7 +523,7 @@ class BAIDU_CACHELINE_ALIGNMENT ObjectPool {
523523
524524 static butil::static_atomic<ObjectPool*> _singleton;
525525 static pthread_mutex_t _singleton_mutex;
526- static BAIDU_THREAD_LOCAL LocalPool* _local_pool;
526+ STATIC_MEMBER_BAIDU_VOLATILE_THREAD_LOCAL ( LocalPool*, _local_pool) ;
527527 static butil::static_atomic<long > _nlocal;
528528 static butil::static_atomic<size_t > _ngroup;
529529 static pthread_mutex_t _block_group_mutex;
Original file line number Diff line number Diff line change @@ -419,7 +419,7 @@ class BAIDU_CACHELINE_ALIGNMENT ResourcePool {
419419 }
420420
421421 inline LocalPool* get_or_new_local_pool () {
422- LocalPool* lp = _local_pool;
422+ LocalPool* lp = BAIDU_GET_VOLATILE_THREAD_LOCAL ( _local_pool) ;
423423 if (lp != NULL ) {
424424 return lp;
425425 }
@@ -428,7 +428,7 @@ class BAIDU_CACHELINE_ALIGNMENT ResourcePool {
428428 return NULL ;
429429 }
430430 BAIDU_SCOPED_LOCK (_change_thread_mutex); // avoid race with clear()
431- _local_pool = lp ;
431+ BAIDU_SET_VOLATILE_THREAD_LOCAL ( _local_pool, lp) ;
432432 butil::thread_atexit (LocalPool::delete_local_pool, lp);
433433 _nlocal.fetch_add (1 , butil::memory_order_relaxed);
434434 return lp;
@@ -524,7 +524,7 @@ class BAIDU_CACHELINE_ALIGNMENT ResourcePool {
524524
525525 static butil::static_atomic<ResourcePool*> _singleton;
526526 static pthread_mutex_t _singleton_mutex;
527- static BAIDU_THREAD_LOCAL LocalPool* _local_pool;
527+ STATIC_MEMBER_BAIDU_VOLATILE_THREAD_LOCAL ( LocalPool*, _local_pool) ;
528528 static butil::static_atomic<long > _nlocal;
529529 static butil::static_atomic<size_t > _ngroup;
530530 static pthread_mutex_t _block_group_mutex;
Original file line number Diff line number Diff line change 4646 var_name = v; \
4747 }
4848
49+ #define STATIC_MEMBER_BAIDU_VOLATILE_THREAD_LOCAL (type, var_name ) \
50+ static BAIDU_THREAD_LOCAL type var_name; \
51+ static __attribute__ ((noinline, unused)) type get_##var_name(void ) { \
52+ asm volatile (" " ); \
53+ return var_name; \
54+ } \
55+ static __attribute__ ((noinline, unused)) type *get_ptr_##var_name(void ) { \
56+ type *ptr = &var_name; \
57+ asm volatile (" " : " +rm" (ptr)); \
58+ return ptr; \
59+ } \
60+ static __attribute__ ((noinline, unused)) void set_##var_name(type v) { \
61+ asm volatile (" " ); \
62+ var_name = v; \
63+ }
64+
4965#if (defined (__aarch64__) && defined (__GNUC__)) || defined(__clang__)
5066// GNU compiler under aarch and Clang compiler is incorrectly caching the
5167// address of thread_local variables across a suspend-point. The following
You can’t perform that action at this time.
0 commit comments