TSD: Make state atomic.

This will let us change the state of another thread remotely, eventually.
This commit is contained in:
David Goldblatt 2018-03-08 16:51:07 -08:00 committed by David Goldblatt
parent 982c10de35
commit 39d6420c0c

View File

@ -78,7 +78,7 @@ typedef void (*test_callback_t)(int *);
MALLOC_TEST_TSD MALLOC_TEST_TSD
#define TSD_INITIALIZER { \ #define TSD_INITIALIZER { \
tsd_state_uninitialized, \ ATOMIC_INIT(tsd_state_uninitialized), \
TCACHE_ENABLED_ZERO_INITIALIZER, \ TCACHE_ENABLED_ZERO_INITIALIZER, \
false, \ false, \
0, \ 0, \
@ -116,7 +116,7 @@ struct tsd_s {
*/ */
/* We manually limit the state to just a single byte. */ /* We manually limit the state to just a single byte. */
uint8_t state; atomic_u8_t state;
#define O(n, t, nt) \ #define O(n, t, nt) \
t use_a_getter_or_setter_instead_##n; t use_a_getter_or_setter_instead_##n;
MALLOC_TSD MALLOC_TSD
@ -125,12 +125,18 @@ MALLOC_TSD
JEMALLOC_ALWAYS_INLINE uint8_t JEMALLOC_ALWAYS_INLINE uint8_t
tsd_state_get(tsd_t *tsd) { tsd_state_get(tsd_t *tsd) {
return tsd->state; /*
* This should be atomic. Unfortunately, compilers right now can't tell
* that this can be done as a memory comparison, and forces a load into
* a register that hurts fast-path performance.
*/
/* return atomic_load_u8(&tsd->state, ATOMIC_RELAXED); */
return *(uint8_t *)&tsd->state;
} }
JEMALLOC_ALWAYS_INLINE void JEMALLOC_ALWAYS_INLINE void
tsd_state_set(tsd_t *tsd, uint8_t state) { tsd_state_set(tsd_t *tsd, uint8_t state) {
tsd->state = state; atomic_store_u8(&tsd->state, state, ATOMIC_RELAXED);
} }
/* /*