Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
fix: x86 build error.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiroKaku committed Oct 7, 2023
1 parent 3a5eab4 commit 65e4226
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
18 changes: 10 additions & 8 deletions src/crt/stl/cond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ struct _Cnd_internal_imp_t { // condition variable implementation for ConcRT
static_assert(sizeof(_Cnd_internal_imp_t) <= _Cnd_internal_imp_size, "incorrect _Cnd_internal_imp_size");
static_assert(alignof(_Cnd_internal_imp_t) <= _Cnd_internal_imp_alignment, "incorrect _Cnd_internal_imp_alignment");

void _Cnd_init_in_situ(const _Cnd_t cond) { // initialize condition variable in situ
_EXTERN_C
void __cdecl _Cnd_init_in_situ(const _Cnd_t cond) { // initialize condition variable in situ
Concurrency::details::create_stl_condition_variable(cond->_get_cv());
}

void _Cnd_destroy_in_situ(const _Cnd_t cond) { // destroy condition variable in situ
void __cdecl _Cnd_destroy_in_situ(const _Cnd_t cond) { // destroy condition variable in situ
cond->_get_cv()->destroy();
}

int _Cnd_init(_Cnd_t* const pcond) { // initialize
int __cdecl _Cnd_init(_Cnd_t* const pcond) { // initialize
*pcond = nullptr;

const auto cond = static_cast<_Cnd_t>(_calloc_crt(1, sizeof(_Cnd_internal_imp_t)));
Expand All @@ -45,22 +46,22 @@ int _Cnd_init(_Cnd_t* const pcond) { // initialize
return _Thrd_success;
}

void _Cnd_destroy(const _Cnd_t cond) { // clean up
void __cdecl _Cnd_destroy(const _Cnd_t cond) { // clean up
if (cond) { // something to do, do it
_Cnd_destroy_in_situ(cond);
_free_crt(cond);
}
}

int _Cnd_wait(const _Cnd_t cond, const _Mtx_t mtx) { // wait until signaled
int __cdecl _Cnd_wait(const _Cnd_t cond, const _Mtx_t mtx) { // wait until signaled
const auto cs = static_cast<Concurrency::details::stl_critical_section_interface*>(_Mtx_getconcrtcs(mtx));
_Mtx_clear_owner(mtx);
cond->_get_cv()->wait(cs);
_Mtx_reset_owner(mtx);
return _Thrd_success; // TRANSITION, ABI: Always returns _Thrd_success
}

int _Cnd_timedwait(const _Cnd_t cond, const _Mtx_t mtx, const xtime* const target) { // wait until signaled or timeout
int __cdecl _Cnd_timedwait(const _Cnd_t cond, const _Mtx_t mtx, const xtime* const target) { // wait until signaled or timeout
int res = _Thrd_success;
const auto cs = static_cast<Concurrency::details::stl_critical_section_interface*>(_Mtx_getconcrtcs(mtx));
if (target == nullptr) { // no target time specified, wait on mutex
Expand All @@ -82,15 +83,16 @@ int _Cnd_timedwait(const _Cnd_t cond, const _Mtx_t mtx, const xtime* const targe
return res;
}

int _Cnd_signal(const _Cnd_t cond) { // release one waiting thread
int __cdecl _Cnd_signal(const _Cnd_t cond) { // release one waiting thread
cond->_get_cv()->notify_one();
return _Thrd_success; // TRANSITION, ABI: Always returns _Thrd_success
}

int _Cnd_broadcast(const _Cnd_t cond) { // release all waiting threads
int __cdecl _Cnd_broadcast(const _Cnd_t cond) { // release all waiting threads
cond->_get_cv()->notify_all();
return _Thrd_success; // TRANSITION, ABI: Always returns _Thrd_success
}
_END_EXTERN_C

/*
* This file is derived from software bearing the following
Expand Down
22 changes: 11 additions & 11 deletions src/crt/stl/cthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ namespace {
_EXTERN_C

// TRANSITION, ABI: _Thrd_exit() is preserved for binary compatibility
_CRTIMP2_PURE void _Thrd_exit(int res) { // terminate execution of calling thread
_CRTIMP2_PURE void __cdecl _Thrd_exit(int res) { // terminate execution of calling thread
_endthreadex(res);
}

// TRANSITION, ABI: _Thrd_start() is preserved for binary compatibility
_CRTIMP2_PURE int _Thrd_start(_Thrd_t* thr, _Thrd_callback_t func, void* b) { // start a thread
_CRTIMP2_PURE int __cdecl _Thrd_start(_Thrd_t* thr, _Thrd_callback_t func, void* b) { // start a thread
thr->_Hnd = reinterpret_cast<HANDLE>(_beginthreadex(nullptr, 0, func, b, 0, &thr->_Id));
return thr->_Hnd == nullptr ? _Thrd_error : _Thrd_success;
}

int _Thrd_join(_Thrd_t thr, int* code) { // returns when thread terminates
int __cdecl _Thrd_join(_Thrd_t thr, int* code) { // returns when thread terminates
if (ZwWaitForSingleObject(thr._Hnd, FALSE, nullptr) != STATUS_SUCCESS) {
return _Thrd_error;
}
Expand All @@ -72,11 +72,11 @@ int _Thrd_join(_Thrd_t thr, int* code) { // returns when thread terminates
return NT_SUCCESS(ZwClose(thr._Hnd)) ? _Thrd_success : _Thrd_error;
}

int _Thrd_detach(_Thrd_t thr) { // tell OS to release thread's resources when it terminates
int __cdecl _Thrd_detach(_Thrd_t thr) { // tell OS to release thread's resources when it terminates
return NT_SUCCESS(ZwClose(thr._Hnd)) ? _Thrd_success : _Thrd_error;
}

void _Thrd_sleep(const xtime* xt) { // suspend thread until time xt
void __cdecl _Thrd_sleep(const xtime* xt) { // suspend thread until time xt
xtime now;
xtime_get(&now, TIME_UTC);
do { // sleep and check time
Expand All @@ -89,33 +89,33 @@ void _Thrd_sleep(const xtime* xt) { // suspend thread until time xt
} while (now.sec < xt->sec || now.sec == xt->sec && now.nsec < xt->nsec);
}

void _Thrd_yield() { // surrender remainder of timeslice
void __cdecl _Thrd_yield() { // surrender remainder of timeslice
(void)ZwYieldExecution();
}

// TRANSITION, ABI: _Thrd_equal() is preserved for binary compatibility
_CRTIMP2_PURE int _Thrd_equal(_Thrd_t thr0, _Thrd_t thr1) { // return 1 if thr0 and thr1 identify same thread
_CRTIMP2_PURE int __cdecl _Thrd_equal(_Thrd_t thr0, _Thrd_t thr1) { // return 1 if thr0 and thr1 identify same thread
return thr0._Id == thr1._Id;
}

// TRANSITION, ABI: _Thrd_current() is preserved for binary compatibility
_CRTIMP2_PURE _Thrd_t _Thrd_current() { // return _Thrd_t identifying current thread
_CRTIMP2_PURE _Thrd_t __cdecl _Thrd_current() { // return _Thrd_t identifying current thread
_Thrd_t result;
result._Hnd = nullptr;
result._Id = static_cast<_Thrd_id_t>(reinterpret_cast<size_t>(PsGetCurrentThreadId()));
return result;
}

_Thrd_id_t _Thrd_id() { // return unique id for current thread
_Thrd_id_t __cdecl _Thrd_id() { // return unique id for current thread
return static_cast<_Thrd_id_t>(reinterpret_cast<size_t>(PsGetCurrentThreadId()));
}

unsigned int _Thrd_hardware_concurrency() { // return number of processors
unsigned int __cdecl _Thrd_hardware_concurrency() { // return number of processors
return KeQueryActiveProcessorCount(nullptr);
}

// TRANSITION, ABI: _Thrd_create() is preserved for binary compatibility
_CRTIMP2_PURE int _Thrd_create(_Thrd_t* thr, _Thrd_start_t func, void* d) { // create thread
_CRTIMP2_PURE int __cdecl _Thrd_create(_Thrd_t* thr, _Thrd_start_t func, void* d) { // create thread
int res;
_Thrd_binder b;
int started = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/crt/stl/xnotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ _EXTERN_C
void _Lock_at_thread_exit_mutex();
void _Unlock_at_thread_exit_mutex();

void _Cnd_register_at_thread_exit(
void __cdecl _Cnd_register_at_thread_exit(
_Cnd_t cnd, _Mtx_t mtx, int* p) { // register condition variable and mutex for cleanup at thread exit
// find block with available space
_At_thread_exit_block* block = &_Thread_exit_data;
Expand Down Expand Up @@ -62,7 +62,7 @@ void _Cnd_register_at_thread_exit(
_Unlock_at_thread_exit_mutex();
}

void _Cnd_unregister_at_thread_exit(_Mtx_t mtx) { // unregister condition variable/mutex for cleanup at thread exit
void __cdecl _Cnd_unregister_at_thread_exit(_Mtx_t mtx) { // unregister condition variable/mutex for cleanup at thread exit
// find condition variables waiting for this thread to exit
_At_thread_exit_block* block = &_Thread_exit_data;

Expand All @@ -80,7 +80,7 @@ void _Cnd_unregister_at_thread_exit(_Mtx_t mtx) { // unregister condition variab
_Unlock_at_thread_exit_mutex();
}

void _Cnd_do_broadcast_at_thread_exit() { // notify condition variables waiting for this thread to exit
void __cdecl _Cnd_do_broadcast_at_thread_exit() { // notify condition variables waiting for this thread to exit
// find condition variables waiting for this thread to exit
_At_thread_exit_block* block = &_Thread_exit_data;
const unsigned int currentThreadId = _Thrd_id();
Expand Down

0 comments on commit 65e4226

Please sign in to comment.