示例#1
0
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;
}
示例#2
0
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);
}
示例#3
0
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;
}
示例#4
0
文件: test.c 项目: Walkerks/locks
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);
}
示例#6
0
文件: rapist.c 项目: CM44/data_pirate
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);
}
示例#7
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;
}
示例#8
0
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);
}
示例#9
0
文件: eglcurrent.c 项目: xranby/mesa
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;
}