int ethr_late_init_common__(ethr_late_init_data *lid) { ethr_ts_event *tsep = NULL; int reader_groups; int res; int i; ethr_memory_allocator *m[] = {ðr_mem__.std, ðr_mem__.sl, ðr_mem__.ll}; if (lid) ethr_mem__ = lid->mem; if (!ethr_mem__.std.alloc || !ethr_mem__.std.realloc || !ethr_mem__.std.free) { ethr_mem__.std.alloc = malloc; ethr_mem__.std.realloc = realloc; ethr_mem__.std.free = free; } for (i = 0; i < sizeof(m)/sizeof(m[0]); i++) { if (!m[i]->alloc || !m[i]->realloc || !m[i]->free) { m[i]->alloc = ethr_mem__.std.alloc; m[i]->realloc = ethr_mem__.std.realloc; m[i]->free = ethr_mem__.std.free; } } res = init_ts_event_alloc(); if (res != 0) return res; res = ethr_make_ts_event__(&tsep); if (res == 0) tsep->iflgs |= ETHR_TS_EV_ETHREAD; if (!lid) { main_threads = 0; reader_groups = 0; } else { if (lid->main_threads < 0 || USHRT_MAX < lid->main_threads) return res; main_threads = lid->main_threads; reader_groups = lid->reader_groups; } res = ethr_mutex_lib_late_init(reader_groups, main_threads); if (res != 0) return res; ethr_not_completely_inited__ = 0; /* Need it for rwmutex_init */ res = ethr_rwmutex_init(&xhndl_rwmtx); ethr_not_completely_inited__ = 1; if (res != 0) return res; return 0; }
static unsigned __stdcall thr_wrapper(LPVOID vtwd) { ethr_tid my_tid; ethr_sint32_t result; void *res; ethr_thr_wrap_data__ *twd = (ethr_thr_wrap_data__ *) vtwd; void *(*thr_func)(void *) = twd->thr_func; void *arg = twd->arg; ethr_ts_event *tsep = NULL; result = (ethr_sint32_t) ethr_make_ts_event__(&tsep); if (result == 0) { tsep->iflgs |= ETHR_TS_EV_ETHREAD; my_tid = *twd->tid; if (!TlsSetValue(own_tid_key, (LPVOID) &my_tid)) { result = (ethr_sint32_t) ethr_win_get_errno__(); ethr_free_ts_event__(tsep); } else { if (ethr_thr_child_func__) ethr_thr_child_func__(twd->prep_func_res); } } tsep = twd->tse; /* We aren't allowed to follow twd after result has been set! */ ethr_atomic32_set(&twd->result, result); ethr_event_set(&tsep->event); res = result == 0 ? (*thr_func)(arg) : NULL; thr_exit_cleanup(&my_tid, res); return 0; }