static inline void _eglSetTSD(const _EGLThreadInfo *t) { tss_set(_egl_TSD, (void *) t); #ifdef GLX_USE_TLS _egl_TLS = t; #endif }
static int do_test (void) { /* Setting an invalid key should return an error. */ if (tss_set (key, TSS_VALUE) == thrd_success) FAIL_EXIT1 ("tss_set succeed where it should have failed"); if (tss_create (&key, NULL) != thrd_success) FAIL_EXIT1 ("tss_create failed"); thrd_t id; if (thrd_create (&id, tss_thrd, NULL) != thrd_success) FAIL_EXIT1 ("thrd_create failed"); if (thrd_join (id, NULL) != thrd_success) FAIL_EXIT1 ("thrd failed"); /* The value set in tss_thrd should not be visible here. */ void *value = tss_get (key); if (value != 0) FAIL_EXIT1 ("tss_get succeed where it should have failed"); tss_delete (key); return 0; }
static void test_tss (void) { thrd_t threads[TEST_TSS_N_THREADS]; int* value = (int*)malloc(sizeof(int)); int i; *value = rand(); tss_create(&(test_tss_data.key), test_tss_free); mtx_init(&(test_tss_data.mutex), mtx_plain); test_tss_data.values_freed = 0; assert(tss_get(test_tss_data.key) == NULL); tss_set(test_tss_data.key, value); assert(tss_get(test_tss_data.key) == value); for (i = 0; i < TEST_TSS_N_THREADS; i++) { thrd_create(&(threads[i]), test_tss_thread_func, NULL); } for (i = 0; i < TEST_TSS_N_THREADS; i++) { thrd_join(threads[i], NULL); } assert(test_tss_data.values_freed == TEST_TSS_N_THREADS); assert(tss_get(test_tss_data.key) == value); tss_delete(test_tss_data.key); assert(tss_get(test_tss_data.key) == NULL); assert(test_tss_data.values_freed == TEST_TSS_N_THREADS); free(value); }
static int test_tss_thread_func (void* data) { int* value = (int*)malloc(sizeof(int)); (void)data; *value = rand(); assert(tss_get(test_tss_data.key) == NULL); tss_set(test_tss_data.key, value); assert(tss_get(test_tss_data.key) == value); tss_set(test_tss_data.key, NULL); assert(tss_get(test_tss_data.key) == NULL); tss_set(test_tss_data.key, value); assert(tss_get(test_tss_data.key) == value); return 0; }
int main( void ) { #ifndef REGTEST TESTCASE(tss_create(&key, NULL) == thrd_success); TESTCASE(tss_get(key) == NULL); TESTCASE(tss_set(key, &v) == thrd_success); TESTCASE(tss_get(key) == &v); tss_delete(key); #endif return TEST_RESULTS; }
static int tss_thrd (void *arg) { if (tss_create (&key, NULL) != thrd_success) FAIL_EXIT1 ("tss_create failed"); if (tss_set (key, TSS_VALUE)) FAIL_EXIT1 ("tss_set failed"); void *value = tss_get (key); if (value == 0) FAIL_EXIT1 ("tss_get failed"); if (value != TSS_VALUE) FAIL_EXIT1 ("tss_get returned %p, expected %p", value, TSS_VALUE); thrd_exit (thrd_success); }
static void * ctxinit(struct hebi_error *err) { #ifdef USE_THREAD_LOCAL const size_t size = sizeof(struct hebi_shadow_context); #else const size_t size = sizeof(struct hebi_context); #endif void *p; int e; errno = 0; p = calloc(1, size); if (UNLIKELY(!p)) { err->he_domain = HEBI_ERRDOM_ERRNO; err->he_code = errno; if (UNLIKELY(!err->he_code)) err->he_code = ENOMEM; return NULL; } #if defined USE_C11_THREADS e = tss_set(ctxkey, p); if (UNLIKELY(e != thrd_success)) { free(p); err->he_domain = HEBI_ERRDOM_THRD; err->he_code = e; return NULL; } #elif defined USE_POSIX_THREADS e = pthread_setspecific(ctxkey, p); if (UNLIKELY(e)) { free(p); err->he_domain = HEBI_ERRDOM_ERRNO; err->he_code = e; return NULL; } #endif return p; }