]>
git.proxmox.com Git - rustc.git/blob - src/jemalloc/test/unit/tsd.c
1 #include "test/jemalloc_test.h"
3 #define THREAD_DATA 0x72b65c10
5 typedef unsigned int data_t
;
7 static bool data_cleanup_executed
;
9 malloc_tsd_types(data_
, data_t
)
10 malloc_tsd_protos(, data_
, data_t
)
13 data_cleanup(void *arg
)
15 data_t
*data
= (data_t
*)arg
;
17 if (!data_cleanup_executed
) {
18 assert_x_eq(*data
, THREAD_DATA
,
19 "Argument passed into cleanup function should match tsd "
22 data_cleanup_executed
= true;
25 * Allocate during cleanup for two rounds, in order to assure that
26 * jemalloc's internal tsd reinitialization happens.
44 void *p
= mallocx(1, 0);
45 assert_ptr_not_null(p
, "Unexpeced mallocx() failure");
50 malloc_tsd_externs(data_
, data_t
)
51 #define DATA_INIT 0x12345678
52 malloc_tsd_data(, data_
, data_t
, DATA_INIT
)
53 malloc_tsd_funcs(, data_
, data_t
, DATA_INIT
, data_cleanup
)
58 data_t d
= (data_t
)(uintptr_t)arg
;
61 assert_x_eq(*data_tsd_get(), DATA_INIT
,
62 "Initial tsd get should return initialization value");
65 assert_ptr_not_null(p
, "Unexpected malloc() failure");
68 assert_x_eq(*data_tsd_get(), d
,
69 "After tsd set, tsd get should return value that was set");
72 assert_x_eq(*data_tsd_get(), (data_t
)(uintptr_t)arg
,
73 "Resetting local data should have no effect on tsd");
79 TEST_BEGIN(test_tsd_main_thread
)
82 thd_start((void *) 0xa5f3e329);
86 TEST_BEGIN(test_tsd_sub_thread
)
90 data_cleanup_executed
= false;
91 thd_create(&thd
, thd_start
, (void *)THREAD_DATA
);
93 assert_true(data_cleanup_executed
,
94 "Cleanup function should have executed");
105 test_tsd_main_thread
,
106 test_tsd_sub_thread
));