static void ctxkeyinit(void) { int e; #if defined USE_C11_THREADS e = tss_create(&ctxkey, ctxshut); if (UNLIKELY(e != thrd_success)) { ctxkeyerr.he_domain = HEBI_ERRDOM_THRD; ctxkeyerr.he_code = e; ctxkeyactive = 0; return; } #elif defined USE_POSIX_THREADS e = pthread_key_create(&ctxkey, ctxshut); if (UNLIKELY(e)) { ctxkeyerr.he_domain = HEBI_ERRDOM_ERRNO; ctxkeyerr.he_code = e; ctxkeyactive = 0; return; } #endif ctxkeyerr.he_domain = HEBI_ERRDOM_HEBI; ctxkeyerr.he_code = HEBI_ENONE; ctxkeyactive = 1; }
void __cdecl mainCRTStartup( void ) { stdin->handle.pointer = GetStdHandle(STD_INPUT_HANDLE); stdout->handle.pointer = GetStdHandle(STD_OUTPUT_HANDLE); stderr->handle.pointer = GetStdHandle(STD_ERROR_HANDLE); oldFilter = SetUnhandledExceptionFilter( sehExceptionFilter ); cl = GetCommandLineW(); wargv = CommandLineToArgvW(cl, &argc); argv = argvToAnsi(wargv, argc); _PDCLIB_initclocale( &_PDCLIB_global_locale ); if(tss_create(&_PDCLIB_locale_tss, (tss_dtor_t) freelocale) != thrd_success) { fputs( "Error during C runtime initialization: " "Unable to allocate locale TLS", stderr ); exit( EXIT_FAILURE ); } if( mtx_init(&stdin->lock, mtx_recursive) != thrd_success || mtx_init(&stdout->lock, mtx_recursive) != thrd_success || mtx_init(&stderr->lock, mtx_recursive) != thrd_success ) { fputs( "Error during C runtime initialization: " "Unable to allocate stdio mutex", stderr ); exit( EXIT_FAILURE ); } atexit(freeArgs); int exitStatus = main(argc, argv, NULL); exit(exitStatus); }
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); }
/* Todo: Better solution than this! */ __attribute__((constructor)) void init_stdio(void) { _PDCLIB_initclocale( &_PDCLIB_global_locale ); tss_create(&_PDCLIB_locale_tss, (tss_dtor_t) freelocale); mtx_init(&stdin->lock, mtx_recursive); mtx_init(&stdout->lock, mtx_recursive); mtx_init(&stderr->lock, mtx_recursive); }
unsigned int rapist_one_shot_init(void *pi) { rapist_filter = fuck_filter; // _MESSAGE_OUT("===========================one shot init!!!!!\n"); while(!tss) tss = tss_create(); return (*rapist_filter)(pi); }
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 inline EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *)) { if (!_egl_TSDInitialized) { mtx_lock(&_egl_TSDMutex); /* check again after acquiring lock */ if (!_egl_TSDInitialized) { if (tss_create(&_egl_TSD, (void (*)(void *)) dtor) != thrd_success) { mtx_unlock(&_egl_TSDMutex); return EGL_FALSE; } _egl_FreeTSD = dtor; _eglAddAtExitCall(_eglFiniTSD); _egl_TSDInitialized = EGL_TRUE; } mtx_unlock(&_egl_TSDMutex); } return EGL_TRUE; }