summaryrefslogtreecommitdiff
path: root/deps/jemalloc/test/unit/tsd.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/jemalloc/test/unit/tsd.c')
-rw-r--r--deps/jemalloc/test/unit/tsd.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/deps/jemalloc/test/unit/tsd.c b/deps/jemalloc/test/unit/tsd.c
index f421c1a3c..8be787fda 100644
--- a/deps/jemalloc/test/unit/tsd.c
+++ b/deps/jemalloc/test/unit/tsd.c
@@ -6,29 +6,64 @@ typedef unsigned int data_t;
static bool data_cleanup_executed;
+malloc_tsd_types(data_, data_t)
+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)
+malloc_tsd_externs(data_, data_t)
#define DATA_INIT 0x12345678
-malloc_tsd_data(, data, data_t, DATA_INIT)
-malloc_tsd_funcs(, data, data_t, DATA_INIT, data_cleanup)
+malloc_tsd_data(, data_, data_t, DATA_INIT)
+malloc_tsd_funcs(, data_, data_t, DATA_INIT, data_cleanup)
static void *
thd_start(void *arg)
{
data_t d = (data_t)(uintptr_t)arg;
+ void *p;
+
assert_x_eq(*data_tsd_get(), DATA_INIT,
"Initial tsd get should return initialization value");
+ p = malloc(1);
+ assert_ptr_not_null(p, "Unexpected malloc() failure");
+
data_tsd_set(&d);
assert_x_eq(*data_tsd_get(), d,
"After tsd set, tsd get should return value that was set");
@@ -37,6 +72,7 @@ thd_start(void *arg)
assert_x_eq(*data_tsd_get(), (data_t)(uintptr_t)arg,
"Resetting local data should have no effect on tsd");
+ free(p);
return (NULL);
}