From 65e42262dfcbce315d2450a862e92a8cd3dfe531 Mon Sep 17 00:00:00 2001 From: MiroKaku <50670906+MiroKaku@users.noreply.github.com> Date: Sat, 7 Oct 2023 18:22:58 +0800 Subject: [PATCH] fix: x86 build error. --- src/crt/stl/cond.cpp | 18 ++++++++++-------- src/crt/stl/cthread.cpp | 22 +++++++++++----------- src/crt/stl/xnotify.cpp | 6 +++--- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/crt/stl/cond.cpp b/src/crt/stl/cond.cpp index e64f16e..bbf94f0 100644 --- a/src/crt/stl/cond.cpp +++ b/src/crt/stl/cond.cpp @@ -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))); @@ -45,14 +46,14 @@ 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(_Mtx_getconcrtcs(mtx)); _Mtx_clear_owner(mtx); cond->_get_cv()->wait(cs); @@ -60,7 +61,7 @@ int _Cnd_wait(const _Cnd_t cond, const _Mtx_t mtx) { // wait until signaled 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(_Mtx_getconcrtcs(mtx)); if (target == nullptr) { // no target time specified, wait on mutex @@ -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 diff --git a/src/crt/stl/cthread.cpp b/src/crt/stl/cthread.cpp index c7046a3..947f101 100644 --- a/src/crt/stl/cthread.cpp +++ b/src/crt/stl/cthread.cpp @@ -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(_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; } @@ -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 @@ -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(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(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; diff --git a/src/crt/stl/xnotify.cpp b/src/crt/stl/xnotify.cpp index 3378291..7565fbf 100644 --- a/src/crt/stl/xnotify.cpp +++ b/src/crt/stl/xnotify.cpp @@ -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; @@ -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; @@ -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();