void erts_lcnt_init() { erts_lcnt_thread_data_t *eltd = NULL; /* init lock */ if (ethr_mutex_init(&lcnt_data_lock) != 0) abort(); /* init tsd */ lcnt_n_thr = 0; ethr_tsd_key_create(&lcnt_thr_data_key); lcnt_lock(); erts_lcnt_rt_options = ERTS_LCNT_OPT_PROCLOCK | ERTS_LCNT_OPT_LOCATION; eltd = lcnt_thread_data_alloc(); ethr_tsd_set(lcnt_thr_data_key, eltd); /* init lcnt structure */ erts_lcnt_data = (erts_lcnt_data_t*)malloc(sizeof(erts_lcnt_data_t)); erts_lcnt_data->current_locks = erts_lcnt_list_init(); erts_lcnt_data->deleted_locks = erts_lcnt_list_init(); lcnt_unlock(); /* set start timer and zero statistics */ erts_lcnt_clear_counters(); }
static void tsd_test(void) { void *tres; int i, res; ethr_tid tid[TT_THREADS]; int values[TT_THREADS]; res = ethr_tsd_key_create(&tt_key,"tsd_test"); ASSERT(res == 0); for (i = 1; i < TT_THREADS; i++) { res = ethr_thr_create(&tid[i], tt_thread, (void *) &values[i], NULL); ASSERT(res == 0); } tres = tt_thread((void *) &values[0]); ASSERT(tres == (void *) &values[0]); for (i = 1; i < TT_THREADS; i++) { res = ethr_thr_join(tid[i], &tres); ASSERT(res == 0); ASSERT(tres == (void *) &values[i]); } res = ethr_tsd_key_delete(tt_key); ASSERT(res == 0); }
void erl_drv_thr_init(void) { int i; #ifdef USE_THREADS int res = ethr_tsd_key_create(&tid_key,"erts_tid_key"); if (res == 0) res = ethr_install_exit_handler(thread_exit_handler); if (res != 0) fatal_error(res, "erl_drv_thr_init()"); #else tsd_len = 0; tsd = NULL; #endif no_name = "unknown"; next_tsd_key = 0; max_used_tsd_key = -1; used_tsd_keys_len = ERL_DRV_TSD_KEYS_INC; used_tsd_keys = erts_alloc(ERTS_ALC_T_DRV_TSD, sizeof(char *)*ERL_DRV_TSD_KEYS_INC); for (i = 0; i < ERL_DRV_TSD_KEYS_INC; i++) used_tsd_keys[i] = NULL; erts_mtx_init(&tsd_mtx, "drv_tsd"); }