Skip to content

Commit e91e27b

Browse files
<__msvc_threads_core.hpp>: Use aligned byte arrays as aligned buffers (#5811)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent 755f6c9 commit e91e27b

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

stl/inc/__msvc_threads_core.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define __MSVC_THREADS_CORE_HPP
88
#include <yvals_core.h>
99
#if _STL_COMPILER_PREPROCESSOR
10-
#include <type_traits>
10+
#include <cstddef>
1111

1212
#pragma pack(push, _CRT_PACKING)
1313
#pragma warning(push, _STL_WARNING_LEVEL)
@@ -43,7 +43,7 @@ struct _Mtx_internal_imp_t {
4343
int _Type{};
4444
union {
4545
_Stl_critical_section _Critical_section{};
46-
_STD _Aligned_storage_t<_Critical_section_size, alignof(void*)> _Cs_storage;
46+
alignas(void*) unsigned char _Cs_storage[_Critical_section_size];
4747
};
4848
long _Thread_id{};
4949
int _Count{};
@@ -68,7 +68,7 @@ struct _Cnd_internal_imp_t {
6868

6969
union {
7070
_Stl_condition_variable _Stl_cv{};
71-
_STD _Aligned_storage_t<_Cnd_internal_imp_size, alignof(void*)> _Cv_storage;
71+
alignas(void*) unsigned char _Cv_storage[_Cnd_internal_imp_size];
7272
};
7373
};
7474
#pragma warning(pop)

tests/std/tests/P0660R10_jthread_and_cv_any/test.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,30 +147,30 @@ int main() {
147147
assert(jthread::hardware_concurrency() == thread::hardware_concurrency());
148148

149149
{ // first wait_until overload; without the cancellation this would deadlock
150-
jthread worker([](stop_token token) {
151-
mutex m;
152-
condition_variable_any cv;
150+
mutex m;
151+
condition_variable_any cv;
152+
jthread worker([&](stop_token token) {
153153
unique_lock lck{m};
154154
assert(cv.wait(lck, move(token), [] { return false; }) == false);
155155
});
156156
}
157157

158-
static constexpr auto forever = chrono::steady_clock::duration::max();
159-
static constexpr auto infinity = chrono::steady_clock::time_point::max();
158+
constexpr auto forever = chrono::steady_clock::duration::max();
159+
constexpr auto infinity = chrono::steady_clock::time_point::max();
160160

161161
{ // ditto without the cancellation this would deadlock
162-
jthread worker([](stop_token token) {
163-
mutex m;
164-
condition_variable_any cv;
162+
mutex m;
163+
condition_variable_any cv;
164+
jthread worker([&](stop_token token) {
165165
unique_lock lck{m};
166166
assert(cv.wait_until(lck, move(token), infinity, [] { return false; }) == false);
167167
});
168168
}
169169

170170
{ // ditto without the cancellation this would deadlock
171-
jthread worker([](stop_token token) {
172-
mutex m;
173-
condition_variable_any cv;
171+
mutex m;
172+
condition_variable_any cv;
173+
jthread worker([&](stop_token token) {
174174
unique_lock lck{m};
175175
assert(cv.wait_for(lck, move(token), forever, [] { return false; }) == false);
176176
});

0 commit comments

Comments
 (0)