Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul condition_variable #4720

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Stop calling _Cnd_init() and _Cnd_destroy().
We declared them in xthreads.h (guarded by `_CRTBLD`) because they were defined by cond.cpp and used by cthread.cpp.
As usual, dropping these declarations won't affect bincompat, as the definitions are consistently marked `_CRTIMP2_PURE`.

Mark the definitions as preserved for bincompat.

In cthread.cpp `_Thrd_create()` (itself preserved for bincompat), we don't need to dynamically allocate and deallocate a condition variable.
Locally initializing `_Cnd_internal_imp_t cond_var{};` and taking its address is sufficient.
StephanTLavavej committed Jun 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 7ed5c6a78e95958ac852ea9a496547aa2cc7c808
4 changes: 0 additions & 4 deletions stl/inc/xthreads.h
Original file line number Diff line number Diff line change
@@ -55,10 +55,6 @@ void __cdecl _Smtx_unlock_exclusive(_Smtx_t*) noexcept;
void __cdecl _Smtx_unlock_shared(_Smtx_t*) noexcept;

// condition variables
#ifdef _CRTBLD
_CRTIMP2_PURE _Thrd_result __cdecl _Cnd_init(_Cnd_t*) noexcept;
_CRTIMP2_PURE void __cdecl _Cnd_destroy(_Cnd_t) noexcept;
#endif // _CRTBLD
#ifdef _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
_CRTIMP2_PURE void __cdecl _Cnd_init_in_situ(_Cnd_t) noexcept;
#endif // ^^^ defined(_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR) ^^^
2 changes: 2 additions & 0 deletions stl/src/cond.cpp
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ _CRTIMP2_PURE void __cdecl _Cnd_init_in_situ(const _Cnd_t cond) noexcept { // in
// TRANSITION, ABI: preserved for binary compatibility
_CRTIMP2_PURE void __cdecl _Cnd_destroy_in_situ(_Cnd_t) noexcept {} // destroy condition variable in situ

// TRANSITION, ABI: preserved for binary compatibility
_CRTIMP2_PURE _Thrd_result __cdecl _Cnd_init(_Cnd_t* const pcond) noexcept { // initialize
*pcond = nullptr;

@@ -33,6 +34,7 @@ _CRTIMP2_PURE _Thrd_result __cdecl _Cnd_init(_Cnd_t* const pcond) noexcept { //
return _Thrd_result::_Success;
}

// TRANSITION, ABI: preserved for binary compatibility
_CRTIMP2_PURE void __cdecl _Cnd_destroy(const _Cnd_t cond) noexcept { // clean up
if (cond) { // something to do, do it
_free_crt(cond);
5 changes: 2 additions & 3 deletions stl/src/cthread.cpp
Original file line number Diff line number Diff line change
@@ -113,9 +113,9 @@ _CRTIMP2_PURE _Thrd_result __cdecl _Thrd_create(_Thrd_t* thr, _Thrd_start_t func
_Thrd_result res;
_Thrd_binder b;
int started = 0;
_Cnd_t cond;
_Cnd_internal_imp_t cond_var{};
_Cnd_t cond = &cond_var;
_Mtx_t mtx;
_Cnd_init(&cond);
_Mtx_init(&mtx, _Mtx_plain);
b.func = func;
b.data = d;
@@ -129,7 +129,6 @@ _CRTIMP2_PURE _Thrd_result __cdecl _Thrd_create(_Thrd_t* thr, _Thrd_start_t func
}
}
_Mtx_unlock(mtx);
_Cnd_destroy(cond);
_Mtx_destroy(mtx);
return res;
}