6#if defined (ELYSIA_RUNTIME_HPERF_ENABLE)
40 starter_args->callable = callable;
45 yoi_result->gc_refcount = 1;
46 yoi_result->type_id = 16;
48 if (thread_handle == 0) {
49 yoi_result->ok =
nullptr;
51 yoi_result->err->gc_refcount = 1;
52 yoi_result->err->type_id = 0;
53 yoi_result->err->value = errno;
57 yoi_result->err =
nullptr;
59 yoi_result->ok->gc_refcount = 1;
60 yoi_result->ok->type_id = 0;
61 yoi_result->ok->value = (
unsigned long long)thread_handle;
72 DWORD result = WaitForSingleObject(win_handle, INFINITE);
74 CloseHandle(win_handle);
77 yoi_result->gc_refcount = 1;
78 yoi_result->type_id = 0;
80 if (result == WAIT_OBJECT_0) {
81 yoi_result->value = 0;
83 yoi_result->value = GetLastError();
86 if (--thread_handle_obj->gc_refcount == 0)
92 return (uint64_t)GetCurrentThreadId();
100 yoi_result->gc_refcount = 1;
101 yoi_result->type_id = 0;
103 if (GetExitCodeThread(win_handle, &exit_code)) {
104 if (exit_code == STILL_ACTIVE) {
105 yoi_result->value = 0;
107 yoi_result->value = ESRCH;
110 yoi_result->value = ESRCH;
113 if (--thread_handle_obj->gc_refcount == 0)
120 GetSystemInfo(&sysinfo);
121 return (uint64_t)sysinfo.dwNumberOfProcessors;
125 auto* cs = (CRITICAL_SECTION*) malloc(
sizeof(CRITICAL_SECTION));
129 yoi_result_obj->type_id = 16;
130 yoi_result_obj->ok =
nullptr;
133 yoi_result_obj->err->gc_refcount = 1;
134 yoi_result_obj->err->type_id = 0;
135 yoi_result_obj->err->value = ENOMEM;
136 return yoi_result_obj;
139 InitializeCriticalSection(cs);
142 yoi_result->gc_refcount = 1;
143 yoi_result->type_id = 0;
144 yoi_result->value = (
unsigned long long)cs;
147 yoi_result_obj->gc_refcount = 1;
148 yoi_result_obj->type_id = 16;
149 yoi_result_obj->err =
nullptr;
150 yoi_result_obj->ok = yoi_result;
152 return yoi_result_obj;
156 auto *cs = (CRITICAL_SECTION *)handle->
value;
157 DeleteCriticalSection(cs);
160 if (--handle->gc_refcount == 0)
165 EnterCriticalSection((CRITICAL_SECTION *)mutex_handle->
value);
172 LeaveCriticalSection((CRITICAL_SECTION *)mutex_handle->
value);
179 BOOL res = TryEnterCriticalSection((CRITICAL_SECTION *)mutex_handle->
value);
182 yoi_result->gc_refcount = 1;
183 yoi_result->type_id = 0;
184 yoi_result->value = res ? 0 : EBUSY;
193 auto* cv = (CONDITION_VARIABLE*) malloc(
sizeof(CONDITION_VARIABLE));
198 yoi_result_obj->type_id = 16;
199 yoi_result_obj->ok =
nullptr;
202 yoi_result_obj->err->gc_refcount = 1;
203 yoi_result_obj->err->type_id = 0;
204 yoi_result_obj->err->value = ENOMEM;
205 return yoi_result_obj;
208 InitializeConditionVariable(cv);
211 yoi_cv_handle->gc_refcount = 1;
212 yoi_cv_handle->type_id = 0;
213 yoi_cv_handle->value = (
unsigned long long)cv;
216 yoi_result_obj->gc_refcount = 1;
217 yoi_result_obj->type_id = 16;
218 yoi_result_obj->err =
nullptr;
219 yoi_result_obj->ok = yoi_cv_handle;
221 return yoi_result_obj;
225 auto *cv = (CONDITION_VARIABLE *)handle->
value;
230 if (--handle->gc_refcount == 0)
235 WakeConditionVariable((CONDITION_VARIABLE *)condition_handle->
value);
242 auto *cv = (CONDITION_VARIABLE *)condition_handle->
value;
243 auto *cs = (CRITICAL_SECTION *)mutex_handle->
value;
246 SleepConditionVariableCS(cv, cs, INFINITE);
264 #if defined (ELYSIA_RUNTIME_HPERF_ENABLE)
287 starter_args->callable = callable;
293 yoi_result->gc_refcount = 1;
294 yoi_result->type_id = 16;
297 yoi_result->ok =
nullptr;
299 yoi_result->err->gc_refcount = 1;
300 yoi_result->err->type_id = 0;
301 yoi_result->err->value = result;
304 yoi_result->err =
nullptr;
306 yoi_result->ok->gc_refcount = 1;
307 yoi_result->ok->type_id = 0;
308 yoi_result->ok->value = (
unsigned long long)thread_id;
318 int result = pthread_join(pthread_id,
nullptr);
321 yoi_result->gc_refcount = 1;
322 yoi_result->type_id = 0;
323 yoi_result->value = result;
331 return (uint64_t)pthread_self();
337 yoi_result->gc_refcount = 1;
338 yoi_result->type_id = 0;
339 yoi_result->value = result;
347 auto mutex = (pthread_mutex_t*) malloc(
sizeof(pthread_mutex_t));
348 auto result = pthread_mutex_init(mutex,
nullptr);
352 yoi_result->gc_refcount = 1;
353 yoi_result->type_id = 0;
354 yoi_result->value = (
unsigned long long)mutex;
357 yoi_result_obj->gc_refcount = 1;
358 yoi_result_obj->err =
nullptr;
359 yoi_result_obj->ok = yoi_result;
360 return yoi_result_obj;
363 yoi_result->gc_refcount = 1;
364 yoi_result->type_id = 0;
365 yoi_result->value = 0;
368 yoi_result_obj->gc_refcount = 1;
369 yoi_result_obj->err = yoi_result;
370 yoi_result_obj->ok =
nullptr;
372 return yoi_result_obj;
378 auto *mutex = (pthread_mutex_t *)handle->
value;
379 pthread_mutex_destroy(mutex);
386 pthread_mutex_lock((pthread_mutex_t *)mutex_handle->
value);
393 pthread_mutex_unlock((pthread_mutex_t *)mutex_handle->
value);
400 auto res = pthread_mutex_trylock((pthread_mutex_t *)mutex_handle->
value);
402 yoi_result->gc_refcount = 1;
403 yoi_result->type_id = 0;
404 yoi_result->value = res;
413 auto* cv = (pthread_cond_t*) malloc(
sizeof(pthread_cond_t));
417 result = pthread_cond_init(cv,
nullptr);
424 yoi_cv_handle->gc_refcount = 1;
425 yoi_cv_handle->type_id = 0;
426 yoi_cv_handle->value = (
unsigned long long)cv;
429 yoi_result_obj->gc_refcount = 1;
430 yoi_result_obj->type_id = 16;
431 yoi_result_obj->err =
nullptr;
432 yoi_result_obj->ok = yoi_cv_handle;
433 return yoi_result_obj;
438 yoi_result_obj->gc_refcount = 1;
439 yoi_result_obj->type_id = 16;
440 yoi_result_obj->ok =
nullptr;
443 yoi_result_obj->err->gc_refcount = 1;
444 yoi_result_obj->err->type_id = 0;
445 yoi_result_obj->err->value = result;
446 return yoi_result_obj;
451 auto *cv = (pthread_cond_t *)handle->
value;
452 pthread_cond_destroy(cv);
460 pthread_cond_signal((pthread_cond_t *)condition_handle->
value);
467 auto *cv = (pthread_cond_t *)condition_handle->
value;
468 auto *mutex = (pthread_mutex_t *)mutex_handle->
value;
470 pthread_cond_wait(cv, mutex);
480 return (uint64_t)sysconf(_SC_NPROCESSORS_ONLN);
HPerfContext * hperf_context_create(size_t unique_id)
void * runtime_object_alloc(unsigned long size)
void runtime_finalize_object(YoiObject *object)
YoiVoidCallableInterface * callable
unsigned long long gc_refcount
unsigned long long gc_refcount
unsigned long long gc_refcount
void *(* gc_dec_func)(void *this_ptr)
void *(* callable)(void *this_ptr)
YoiIntegerObject * runtime_thread_join(YoiUnsignedObject *thread_id_obj)
void runtime_thread_mutex_lock(YoiUnsignedObject *mutex_handle)
void runtime_thread_condition_wait(YoiUnsignedObject *condition_handle, YoiUnsignedObject *mutex_handle)
YoiIntegerObject * runtime_ping_thread(YoiUnsignedObject *thread_id_obj)
void * thread_starter_wrapper(void *args)
YoiResultUnsignedAndIntObject * runtime_start_thread(YoiVoidCallableInterface *callable)
void runtime_thread_mutex_unlock(YoiUnsignedObject *mutex_handle)
YoiResultUnsignedAndIntObject * runtime_thread_new_condition()
void runtime_thread_finalize_mutex_lock(YoiUnsignedObject *handle)
YoiResultUnsignedAndIntObject * runtime_thread_new_mutex_lock()
uint64_t runtime_get_thread_id()
uint64_t runtime_thread_hardware_concurrency()
void runtime_thread_condition_signal(YoiUnsignedObject *condition_handle)
YoiIntegerObject * runtime_thread_mutex_try_lock(YoiUnsignedObject *mutex_handle)
void runtime_thread_finalize_condition(YoiUnsignedObject *handle)
pthread_t YoiThreadHandle