diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -119,6 +119,8 @@ - ````, ````, ````, ````, ```` and ```` no longer include ```` (it was previously included in all Standard versions). +- ````, ````, ````, ```` and ```` no longer include ````. + - The headers ```` and ```` have been removed, since all the contents have been implemented in namespace ``std`` for at least two releases. diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -519,6 +519,7 @@ __memory_resource/unsynchronized_pool_resource.h __mutex/lock_guard.h __mutex/mutex.h + __mutex/once_flag.h __mutex/tag_types.h __mutex/unique_lock.h __node_handle diff --git a/libcxx/include/__locale b/libcxx/include/__locale --- a/libcxx/include/__locale +++ b/libcxx/include/__locale @@ -13,12 +13,12 @@ #include <__availability> #include <__config> #include <__memory/shared_ptr.h> // __shared_count +#include <__mutex/once_flag.h> #include <__type_traits/make_unsigned.h> #include #include #include #include -#include #include // Some platforms require more includes than others. Keep the includes on all plaforms for now. diff --git a/libcxx/include/__mutex/once_flag.h b/libcxx/include/__mutex/once_flag.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__mutex/once_flag.h @@ -0,0 +1,150 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MUTEX_ONCE_FLAG_H +#define _LIBCPP___MUTEX_ONCE_FLAG_H + +#include <__config> +#include <__functional/invoke.h> +#include <__memory/shared_ptr.h> // __libcpp_acquire_load +#include <__tuple/tuple_indices.h> +#include <__tuple/tuple_size.h> +#include <__utility/forward.h> +#include <__utility/move.h> +#include +#ifndef _LIBCPP_CXX03_LANG +# include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_TEMPLATE_VIS once_flag; + +#ifndef _LIBCPP_CXX03_LANG + +template +_LIBCPP_HIDE_FROM_ABI void call_once(once_flag&, _Callable&&, _Args&&...); + +#else // _LIBCPP_CXX03_LANG + +template +_LIBCPP_HIDE_FROM_ABI void call_once(once_flag&, _Callable&); + +template +_LIBCPP_HIDE_FROM_ABI void call_once(once_flag&, const _Callable&); + +#endif // _LIBCPP_CXX03_LANG + +struct _LIBCPP_TEMPLATE_VIS once_flag { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR once_flag() _NOEXCEPT : __state_(0) {} + once_flag(const once_flag&) = delete; + once_flag& operator=(const once_flag&) = delete; + +#if defined(_LIBCPP_ABI_MICROSOFT) + typedef uintptr_t _State_type; +#else + typedef unsigned long _State_type; +#endif + +private: + _State_type __state_; + +#ifndef _LIBCPP_CXX03_LANG + template + friend void call_once(once_flag&, _Callable&&, _Args&&...); +#else // _LIBCPP_CXX03_LANG + template + friend void call_once(once_flag&, _Callable&); + + template + friend void call_once(once_flag&, const _Callable&); +#endif // _LIBCPP_CXX03_LANG +}; + +#ifndef _LIBCPP_CXX03_LANG + +template +class __call_once_param { + _Fp& __f_; + +public: + _LIBCPP_HIDE_FROM_ABI explicit __call_once_param(_Fp& __f) : __f_(__f) {} + + _LIBCPP_HIDE_FROM_ABI void operator()() { + typedef typename __make_tuple_indices::value, 1>::type _Index; + __execute(_Index()); + } + +private: + template + _LIBCPP_HIDE_FROM_ABI void __execute(__tuple_indices<_Indices...>) { + _VSTD::__invoke(_VSTD::get<0>(_VSTD::move(__f_)), _VSTD::get<_Indices>(_VSTD::move(__f_))...); + } +}; + +#else + +template +class __call_once_param { + _Fp& __f_; + +public: + _LIBCPP_HIDE_FROM_ABI explicit __call_once_param(_Fp& __f) : __f_(__f) {} + + _LIBCPP_HIDE_FROM_ABI void operator()() { __f_(); } +}; + +#endif + +template +void _LIBCPP_HIDE_FROM_ABI __call_once_proxy(void* __vp) { + __call_once_param<_Fp>* __p = static_cast<__call_once_param<_Fp>*>(__vp); + (*__p)(); +} + +_LIBCPP_EXPORTED_FROM_ABI void __call_once(volatile once_flag::_State_type&, void*, void (*)(void*)); + +#ifndef _LIBCPP_CXX03_LANG + +template +inline _LIBCPP_HIDE_FROM_ABI void call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args) { + if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) { + typedef tuple<_Callable&&, _Args&&...> _Gp; + _Gp __f(_VSTD::forward<_Callable>(__func), _VSTD::forward<_Args>(__args)...); + __call_once_param<_Gp> __p(__f); + std::__call_once(__flag.__state_, &__p, &__call_once_proxy<_Gp>); + } +} + +#else // _LIBCPP_CXX03_LANG + +template +inline _LIBCPP_HIDE_FROM_ABI void call_once(once_flag& __flag, _Callable& __func) { + if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) { + __call_once_param<_Callable> __p(__func); + std::__call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>); + } +} + +template +inline _LIBCPP_HIDE_FROM_ABI void call_once(once_flag& __flag, const _Callable& __func) { + if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) { + __call_once_param __p(__func); + std::__call_once(__flag.__state_, &__p, &__call_once_proxy); + } +} + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MUTEX_ONCE_FLAG_H diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in --- a/libcxx/include/module.modulemap.in +++ b/libcxx/include/module.modulemap.in @@ -1325,6 +1325,7 @@ module __mutex { module lock_guard { private header "__mutex/lock_guard.h" } module mutex { private header "__mutex/mutex.h" } + module once_flag { private header "__mutex/once_flag.h" } module tag_types { private header "__mutex/tag_types.h" } module unique_lock { private header "__mutex/unique_lock.h" } } diff --git a/libcxx/include/mutex b/libcxx/include/mutex --- a/libcxx/include/mutex +++ b/libcxx/include/mutex @@ -194,6 +194,7 @@ #include <__memory/shared_ptr.h> #include <__mutex/lock_guard.h> #include <__mutex/mutex.h> +#include <__mutex/once_flag.h> #include <__mutex/tag_types.h> #include <__mutex/unique_lock.h> #include <__thread/id.h> @@ -555,157 +556,6 @@ #endif // _LIBCPP_STD_VER >= 17 #endif // !_LIBCPP_HAS_NO_THREADS -struct _LIBCPP_TEMPLATE_VIS once_flag; - -#ifndef _LIBCPP_CXX03_LANG - -template -_LIBCPP_INLINE_VISIBILITY -void call_once(once_flag&, _Callable&&, _Args&&...); - -#else // _LIBCPP_CXX03_LANG - -template -_LIBCPP_INLINE_VISIBILITY -void call_once(once_flag&, _Callable&); - -template -_LIBCPP_INLINE_VISIBILITY -void call_once(once_flag&, const _Callable&); - -#endif // _LIBCPP_CXX03_LANG - -struct _LIBCPP_TEMPLATE_VIS once_flag -{ - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR - once_flag() _NOEXCEPT : __state_(0) {} - once_flag(const once_flag&) = delete; - once_flag& operator=(const once_flag&) = delete; - -#if defined(_LIBCPP_ABI_MICROSOFT) - typedef uintptr_t _State_type; -#else - typedef unsigned long _State_type; -#endif - -private: - _State_type __state_; - -#ifndef _LIBCPP_CXX03_LANG - template - friend - void call_once(once_flag&, _Callable&&, _Args&&...); -#else // _LIBCPP_CXX03_LANG - template - friend - void call_once(once_flag&, _Callable&); - - template - friend - void call_once(once_flag&, const _Callable&); -#endif // _LIBCPP_CXX03_LANG -}; - -#ifndef _LIBCPP_CXX03_LANG - -template -class __call_once_param -{ - _Fp& __f_; -public: - _LIBCPP_INLINE_VISIBILITY - explicit __call_once_param(_Fp& __f) : __f_(__f) {} - - _LIBCPP_INLINE_VISIBILITY - void operator()() - { - typedef typename __make_tuple_indices::value, 1>::type _Index; - __execute(_Index()); - } - -private: - template - _LIBCPP_INLINE_VISIBILITY - void __execute(__tuple_indices<_Indices...>) - { - _VSTD::__invoke(_VSTD::get<0>(_VSTD::move(__f_)), _VSTD::get<_Indices>(_VSTD::move(__f_))...); - } -}; - -#else - -template -class __call_once_param -{ - _Fp& __f_; -public: - _LIBCPP_INLINE_VISIBILITY - explicit __call_once_param(_Fp& __f) : __f_(__f) {} - - _LIBCPP_INLINE_VISIBILITY - void operator()() - { - __f_(); - } -}; - -#endif - -template -void _LIBCPP_INLINE_VISIBILITY -__call_once_proxy(void* __vp) -{ - __call_once_param<_Fp>* __p = static_cast<__call_once_param<_Fp>*>(__vp); - (*__p)(); -} - -_LIBCPP_EXPORTED_FROM_ABI void __call_once(volatile once_flag::_State_type&, void*, void (*)(void*)); - -#ifndef _LIBCPP_CXX03_LANG - -template -inline _LIBCPP_INLINE_VISIBILITY -void -call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args) -{ - if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) - { - typedef tuple<_Callable&&, _Args&&...> _Gp; - _Gp __f(_VSTD::forward<_Callable>(__func), _VSTD::forward<_Args>(__args)...); - __call_once_param<_Gp> __p(__f); - std::__call_once(__flag.__state_, &__p, &__call_once_proxy<_Gp>); - } -} - -#else // _LIBCPP_CXX03_LANG - -template -inline _LIBCPP_INLINE_VISIBILITY -void -call_once(once_flag& __flag, _Callable& __func) -{ - if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) - { - __call_once_param<_Callable> __p(__func); - std::__call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>); - } -} - -template -inline _LIBCPP_INLINE_VISIBILITY -void -call_once(once_flag& __flag, const _Callable& __func) -{ - if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) - { - __call_once_param __p(__func); - std::__call_once(__flag.__state_, &__p, &__call_once_proxy); - } -} - -#endif // _LIBCPP_CXX03_LANG - _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv --- a/libcxx/test/libcxx/transitive_includes/cxx03.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv @@ -141,7 +141,6 @@ codecvt initializer_list codecvt iosfwd codecvt limits -codecvt mutex codecvt new codecvt stdexcept codecvt string @@ -349,7 +348,6 @@ fstream iosfwd fstream istream fstream limits -fstream mutex fstream new fstream ostream fstream stdexcept @@ -404,6 +402,7 @@ iomanip version ios atomic ios cctype +ios cerrno ios clocale ios concepts ios cstddef @@ -414,7 +413,6 @@ ios initializer_list ios iosfwd ios limits -ios mutex ios new ios stdexcept ios string @@ -496,7 +494,6 @@ locale iosfwd locale iterator locale limits -locale mutex locale new locale stdexcept locale streambuf @@ -701,7 +698,6 @@ regex iosfwd regex iterator regex limits -regex mutex regex new regex stdexcept regex string diff --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv --- a/libcxx/test/libcxx/transitive_includes/cxx11.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv @@ -141,10 +141,10 @@ codecvt initializer_list codecvt iosfwd codecvt limits -codecvt mutex codecvt new codecvt stdexcept codecvt string +codecvt tuple codecvt type_traits codecvt typeinfo codecvt version @@ -349,11 +349,11 @@ fstream iosfwd fstream istream fstream limits -fstream mutex fstream new fstream ostream fstream stdexcept fstream string +fstream tuple fstream type_traits fstream typeinfo fstream version @@ -404,6 +404,7 @@ iomanip version ios atomic ios cctype +ios cerrno ios clocale ios concepts ios cstddef @@ -414,11 +415,11 @@ ios initializer_list ios iosfwd ios limits -ios mutex ios new ios stdexcept ios string ios system_error +ios tuple ios type_traits ios typeinfo ios version @@ -496,11 +497,11 @@ locale iosfwd locale iterator locale limits -locale mutex locale new locale stdexcept locale streambuf locale string +locale tuple locale type_traits locale typeinfo locale version @@ -702,10 +703,10 @@ regex iosfwd regex iterator regex limits -regex mutex regex new regex stdexcept regex string +regex tuple regex type_traits regex typeinfo regex utility diff --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv --- a/libcxx/test/libcxx/transitive_includes/cxx14.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv @@ -141,10 +141,10 @@ codecvt initializer_list codecvt iosfwd codecvt limits -codecvt mutex codecvt new codecvt stdexcept codecvt string +codecvt tuple codecvt type_traits codecvt typeinfo codecvt version @@ -351,11 +351,11 @@ fstream iosfwd fstream istream fstream limits -fstream mutex fstream new fstream ostream fstream stdexcept fstream string +fstream tuple fstream type_traits fstream typeinfo fstream version @@ -406,6 +406,7 @@ iomanip version ios atomic ios cctype +ios cerrno ios clocale ios concepts ios cstddef @@ -416,11 +417,11 @@ ios initializer_list ios iosfwd ios limits -ios mutex ios new ios stdexcept ios string ios system_error +ios tuple ios type_traits ios typeinfo ios version @@ -498,11 +499,11 @@ locale iosfwd locale iterator locale limits -locale mutex locale new locale stdexcept locale streambuf locale string +locale tuple locale type_traits locale typeinfo locale version @@ -704,10 +705,10 @@ regex iosfwd regex iterator regex limits -regex mutex regex new regex stdexcept regex string +regex tuple regex type_traits regex typeinfo regex utility diff --git a/libcxx/test/libcxx/transitive_includes/cxx17.csv b/libcxx/test/libcxx/transitive_includes/cxx17.csv --- a/libcxx/test/libcxx/transitive_includes/cxx17.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx17.csv @@ -141,10 +141,10 @@ codecvt initializer_list codecvt iosfwd codecvt limits -codecvt mutex codecvt new codecvt stdexcept codecvt string +codecvt tuple codecvt type_traits codecvt typeinfo codecvt version @@ -351,11 +351,11 @@ fstream iosfwd fstream istream fstream limits -fstream mutex fstream new fstream ostream fstream stdexcept fstream string +fstream tuple fstream type_traits fstream typeinfo fstream version @@ -406,6 +406,7 @@ iomanip version ios atomic ios cctype +ios cerrno ios clocale ios concepts ios cstddef @@ -416,11 +417,11 @@ ios initializer_list ios iosfwd ios limits -ios mutex ios new ios stdexcept ios string ios system_error +ios tuple ios type_traits ios typeinfo ios version @@ -498,11 +499,11 @@ locale iosfwd locale iterator locale limits -locale mutex locale new locale stdexcept locale streambuf locale string +locale tuple locale type_traits locale typeinfo locale version @@ -704,10 +705,10 @@ regex iosfwd regex iterator regex limits -regex mutex regex new regex stdexcept regex string +regex tuple regex type_traits regex typeinfo regex utility diff --git a/libcxx/test/libcxx/transitive_includes/cxx20.csv b/libcxx/test/libcxx/transitive_includes/cxx20.csv --- a/libcxx/test/libcxx/transitive_includes/cxx20.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx20.csv @@ -148,10 +148,10 @@ codecvt initializer_list codecvt iosfwd codecvt limits -codecvt mutex codecvt new codecvt stdexcept codecvt string +codecvt tuple codecvt type_traits codecvt typeinfo codecvt version @@ -358,11 +358,11 @@ fstream iosfwd fstream istream fstream limits -fstream mutex fstream new fstream ostream fstream stdexcept fstream string +fstream tuple fstream type_traits fstream typeinfo fstream version @@ -412,6 +412,7 @@ iomanip version ios atomic ios cctype +ios cerrno ios clocale ios concepts ios cstddef @@ -422,11 +423,11 @@ ios initializer_list ios iosfwd ios limits -ios mutex ios new ios stdexcept ios string ios system_error +ios tuple ios type_traits ios typeinfo ios version @@ -504,11 +505,11 @@ locale iosfwd locale iterator locale limits -locale mutex locale new locale stdexcept locale streambuf locale string +locale tuple locale type_traits locale typeinfo locale version @@ -710,10 +711,10 @@ regex iosfwd regex iterator regex limits -regex mutex regex new regex stdexcept regex string +regex tuple regex type_traits regex typeinfo regex utility diff --git a/libcxx/test/libcxx/transitive_includes/cxx23.csv b/libcxx/test/libcxx/transitive_includes/cxx23.csv --- a/libcxx/test/libcxx/transitive_includes/cxx23.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv @@ -98,10 +98,10 @@ codecvt initializer_list codecvt iosfwd codecvt limits -codecvt mutex codecvt new codecvt stdexcept codecvt string +codecvt tuple codecvt typeinfo codecvt version compare cmath @@ -250,11 +250,11 @@ fstream iosfwd fstream istream fstream limits -fstream mutex fstream new fstream ostream fstream stdexcept fstream string +fstream tuple fstream typeinfo fstream version functional array @@ -292,19 +292,22 @@ iomanip istream iomanip version ios cctype +ios cerrno ios clocale ios cstddef ios cstdint ios cstdlib ios cstring +ios ctime ios cwchar ios initializer_list ios iosfwd ios limits -ios mutex ios new +ios ratio ios stdexcept ios string +ios tuple ios typeinfo ios version iosfwd version @@ -357,11 +360,11 @@ locale ios locale iosfwd locale limits -locale mutex locale new locale stdexcept locale streambuf locale string +locale tuple locale typeinfo locale version map compare @@ -506,10 +509,10 @@ regex initializer_list regex iosfwd regex limits -regex mutex regex new regex stdexcept regex string +regex tuple regex typeinfo regex vector regex version diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv --- a/libcxx/test/libcxx/transitive_includes/cxx26.csv +++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv @@ -98,10 +98,10 @@ codecvt initializer_list codecvt iosfwd codecvt limits -codecvt mutex codecvt new codecvt stdexcept codecvt string +codecvt tuple codecvt typeinfo codecvt version compare cmath @@ -250,11 +250,11 @@ fstream iosfwd fstream istream fstream limits -fstream mutex fstream new fstream ostream fstream stdexcept fstream string +fstream tuple fstream typeinfo fstream version functional array @@ -292,19 +292,22 @@ iomanip istream iomanip version ios cctype +ios cerrno ios clocale ios cstddef ios cstdint ios cstdlib ios cstring +ios ctime ios cwchar ios initializer_list ios iosfwd ios limits -ios mutex ios new +ios ratio ios stdexcept ios string +ios tuple ios typeinfo ios version iosfwd version @@ -357,11 +360,11 @@ locale ios locale iosfwd locale limits -locale mutex locale new locale stdexcept locale streambuf locale string +locale tuple locale typeinfo locale version map compare @@ -506,10 +509,10 @@ regex initializer_list regex iosfwd regex limits -regex mutex regex new regex stdexcept regex string +regex tuple regex typeinfo regex vector regex version