|
| 1 | +// __msvc_threads_core.hpp internal header (core) |
| 2 | + |
| 3 | +// Copyright (c) Microsoft Corporation. |
| 4 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | + |
| 6 | +#ifndef __MSVC_THREADS_CORE_HPP |
| 7 | +#define __MSVC_THREADS_CORE_HPP |
| 8 | +#include <yvals_core.h> |
| 9 | +#if _STL_COMPILER_PREPROCESSOR |
| 10 | +#include <type_traits> |
| 11 | + |
| 12 | +#pragma pack(push, _CRT_PACKING) |
| 13 | +#pragma warning(push, _STL_WARNING_LEVEL) |
| 14 | +#pragma warning(disable : _STL_DISABLED_WARNINGS) |
| 15 | +_STL_DISABLE_CLANG_WARNINGS |
| 16 | +#pragma push_macro("new") |
| 17 | +#undef new |
| 18 | + |
| 19 | +extern "C" { |
| 20 | +using _Thrd_id_t = unsigned int; |
| 21 | +struct _Thrd_t { // thread identifier for Win32 |
| 22 | + void* _Hnd; // Win32 HANDLE |
| 23 | + _Thrd_id_t _Id; |
| 24 | +}; |
| 25 | + |
| 26 | +using _Smtx_t = void*; |
| 27 | + |
| 28 | +enum class _Thrd_result : int { _Success, _Nomem, _Timedout, _Busy, _Error }; |
| 29 | + |
| 30 | +struct _Stl_critical_section { |
| 31 | + void* _Unused = nullptr; // TRANSITION, ABI: was the vptr |
| 32 | + _Smtx_t _M_srw_lock = nullptr; |
| 33 | +}; |
| 34 | + |
| 35 | +struct _Mtx_internal_imp_t { |
| 36 | +#if defined(_CRT_WINDOWS) || defined(UNDOCKED_WINDOWS_UCRT) |
| 37 | +#ifdef _WIN64 |
| 38 | + static constexpr size_t _Critical_section_size = 16; |
| 39 | +#else // ^^^ defined(_WIN64) / !defined(_WIN64) vvv |
| 40 | + static constexpr size_t _Critical_section_size = 8; |
| 41 | +#endif // ^^^ !defined(_WIN64) ^^^ |
| 42 | +#else // ^^^ Windows private STL / public STL vvv |
| 43 | +#ifdef _WIN64 |
| 44 | + static constexpr size_t _Critical_section_size = 64; |
| 45 | +#else // ^^^ defined(_WIN64) / !defined(_WIN64) vvv |
| 46 | + static constexpr size_t _Critical_section_size = 36; |
| 47 | +#endif // ^^^ !defined(_WIN64) ^^^ |
| 48 | +#endif // ^^^ public STL ^^^ |
| 49 | + |
| 50 | + static constexpr size_t _Critical_section_align = alignof(void*); |
| 51 | + |
| 52 | + int _Type{}; |
| 53 | + union { |
| 54 | + _Stl_critical_section _Critical_section{}; |
| 55 | + _STD _Aligned_storage_t<_Critical_section_size, _Critical_section_align> _Cs_storage; |
| 56 | + }; |
| 57 | + long _Thread_id{}; |
| 58 | + int _Count{}; |
| 59 | +}; |
| 60 | + |
| 61 | +// Size and alignment for _Cnd_internal_imp_t |
| 62 | +#if defined(_CRT_WINDOWS) // for Windows-internal code |
| 63 | +_INLINE_VAR constexpr size_t _Cnd_internal_imp_size = 2 * sizeof(void*); |
| 64 | +#elif defined(_WIN64) // ordinary 64-bit code |
| 65 | +_INLINE_VAR constexpr size_t _Cnd_internal_imp_size = 72; |
| 66 | +#else // vvv ordinary 32-bit code vvv |
| 67 | +_INLINE_VAR constexpr size_t _Cnd_internal_imp_size = 40; |
| 68 | +#endif // ^^^ ordinary 32-bit code ^^^ |
| 69 | + |
| 70 | +_INLINE_VAR constexpr size_t _Cnd_internal_imp_alignment = alignof(void*); |
| 71 | + |
| 72 | +using _Mtx_t = _Mtx_internal_imp_t*; |
| 73 | + |
| 74 | +#ifdef _M_CEE // avoid warning LNK4248: unresolved typeref token for '_Cnd_internal_imp_t'; image may not run |
| 75 | +using _Cnd_t = void*; |
| 76 | +#else // ^^^ defined(_M_CEE) / !defined(_M_CEE) vvv |
| 77 | +struct _Cnd_internal_imp_t; |
| 78 | +using _Cnd_t = _Cnd_internal_imp_t*; |
| 79 | +#endif // ^^^ !defined(_M_CEE) ^^^ |
| 80 | +} // extern "C" |
| 81 | + |
| 82 | +#pragma pop_macro("new") |
| 83 | +_STL_RESTORE_CLANG_WARNINGS |
| 84 | +#pragma warning(pop) |
| 85 | +#pragma pack(pop) |
| 86 | +#endif // _STL_COMPILER_PREPROCESSOR |
| 87 | +#endif // __MSVC_THREADS_CORE_HPP |
| 88 | + |
| 89 | +/* |
| 90 | + * This file is derived from software bearing the following |
| 91 | + * restrictions: |
| 92 | + * |
| 93 | + * (c) Copyright William E. Kempf 2001 |
| 94 | + * |
| 95 | + * Permission to use, copy, modify, distribute and sell this |
| 96 | + * software and its documentation for any purpose is hereby |
| 97 | + * granted without fee, provided that the above copyright |
| 98 | + * notice appear in all copies and that both that copyright |
| 99 | + * notice and this permission notice appear in supporting |
| 100 | + * documentation. William E. Kempf makes no representations |
| 101 | + * about the suitability of this software for any purpose. |
| 102 | + * It is provided "as is" without express or implied warranty. |
| 103 | + */ |
0 commit comments