mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-25 06:13:13 +00:00
Fix tsd cleanup regressions.
Fix tsd cleanup regressions that were introduced in
5460aa6f66 (Convert all tsd variables to
reside in a single tsd structure.). These regressions were twofold:
1) tsd_tryget() should never (and need never) return NULL. Rename it to
tsd_fetch() and simplify all callers.
2) tsd_*_set() must only be called when tsd is in the nominal state,
because cleanup happens during the nominal-->purgatory transition,
and re-initialization must not happen while in the purgatory state.
Add tsd_nominal() and use it as needed. Note that tsd_*{p,}_get()
can still be used as long as no re-initialization that would require
cleanup occurs. This means that e.g. the thread_allocated counter
can be updated unconditionally.
This commit is contained in:
@@ -6,17 +6,46 @@ typedef unsigned int data_t;
|
||||
|
||||
static bool data_cleanup_executed;
|
||||
|
||||
malloc_tsd_protos(, data_, data_t)
|
||||
|
||||
void
|
||||
data_cleanup(void *arg)
|
||||
{
|
||||
data_t *data = (data_t *)arg;
|
||||
|
||||
assert_x_eq(*data, THREAD_DATA,
|
||||
"Argument passed into cleanup function should match tsd value");
|
||||
if (!data_cleanup_executed) {
|
||||
assert_x_eq(*data, THREAD_DATA,
|
||||
"Argument passed into cleanup function should match tsd "
|
||||
"value");
|
||||
}
|
||||
data_cleanup_executed = true;
|
||||
|
||||
/*
|
||||
* Allocate during cleanup for two rounds, in order to assure that
|
||||
* jemalloc's internal tsd reinitialization happens.
|
||||
*/
|
||||
switch (*data) {
|
||||
case THREAD_DATA:
|
||||
*data = 1;
|
||||
data_tsd_set(data);
|
||||
break;
|
||||
case 1:
|
||||
*data = 2;
|
||||
data_tsd_set(data);
|
||||
break;
|
||||
case 2:
|
||||
return;
|
||||
default:
|
||||
not_reached();
|
||||
}
|
||||
|
||||
{
|
||||
void *p = mallocx(1, 0);
|
||||
assert_ptr_not_null(p, "Unexpeced mallocx() failure");
|
||||
dallocx(p, 0);
|
||||
}
|
||||
}
|
||||
|
||||
malloc_tsd_protos(, data_, data_t)
|
||||
malloc_tsd_externs(data_, data_t)
|
||||
#define DATA_INIT 0x12345678
|
||||
malloc_tsd_data(, data_, data_t, DATA_INIT)
|
||||
|
||||
Reference in New Issue
Block a user