[libcxx-commits] [libcxx] e3add3e - [libcxx] Fix building for windows after 54fa9ecd3088508
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 25 11:34:02 PST 2020
Author: Martin Storsjö
Date: 2020-02-25T21:33:52+02:00
New Revision: e3add3e5a192ec7f73922a4278f52d335d1f9be5
URL: https://github.com/llvm/llvm-project/commit/e3add3e5a192ec7f73922a4278f52d335d1f9be5
DIFF: https://github.com/llvm/llvm-project/commit/e3add3e5a192ec7f73922a4278f52d335d1f9be5.diff
LOG: [libcxx] Fix building for windows after 54fa9ecd3088508
Move the implementation of __libcpp_thread_poll_with_backoff
and __libcpp_timed_backoff_policy::operator() out of the
_LIBCPP_HAS_THREAD_API_PTHREAD block. None of the code in these
methods is pthreads specific.
Also add "inline _LIBCPP_INLINE_VISIBILITY" to
__libcpp_timed_backoff_policy::operator(), to avoid errors due to
multiple definitions of the operator. Contrary to
__libcpp_thread_poll_with_backoff (which is a template function),
this is a normal non-templated method.
Differential Revision: https://reviews.llvm.org/D75102
Added:
Modified:
libcxx/include/__threading_support
Removed:
################################################################################
diff --git a/libcxx/include/__threading_support b/libcxx/include/__threading_support
index 948022554703..d2ee0c693a15 100644
--- a/libcxx/include/__threading_support
+++ b/libcxx/include/__threading_support
@@ -494,40 +494,6 @@ void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
}
-bool __libcpp_timed_backoff_policy::operator()(chrono::nanoseconds __elapsed) const
-{
- if(__elapsed > chrono::milliseconds(128))
- __libcpp_thread_sleep_for(chrono::milliseconds(8));
- else if(__elapsed > chrono::microseconds(64))
- __libcpp_thread_sleep_for(__elapsed / 2);
- else if(__elapsed > chrono::microseconds(4))
- __libcpp_thread_yield();
- else
- ; // poll
- return false;
-}
-
-static _LIBCPP_CONSTEXPR const int __libcpp_polling_count = 64;
-
-template<class _Fn, class _BFn>
-bool __libcpp_thread_poll_with_backoff(_Fn && __f, _BFn && __bf, chrono::nanoseconds __max_elapsed)
-{
- auto const __start = chrono::high_resolution_clock::now();
- for(int __count = 0;;) {
- if(__f())
- return true; // _Fn completion means success
- if(__count < __libcpp_polling_count) {
- __count += 1;
- continue;
- }
- chrono::nanoseconds const __elapsed = chrono::high_resolution_clock::now() - __start;
- if(__max_elapsed != chrono::nanoseconds::zero() && __max_elapsed < __elapsed)
- return false; // timeout failure
- if(__bf(__elapsed))
- return false; // _BFn completion means failure
- }
-}
-
// Thread local storage
int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
{
@@ -703,6 +669,41 @@ int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
#endif
+inline _LIBCPP_INLINE_VISIBILITY
+bool __libcpp_timed_backoff_policy::operator()(chrono::nanoseconds __elapsed) const
+{
+ if(__elapsed > chrono::milliseconds(128))
+ __libcpp_thread_sleep_for(chrono::milliseconds(8));
+ else if(__elapsed > chrono::microseconds(64))
+ __libcpp_thread_sleep_for(__elapsed / 2);
+ else if(__elapsed > chrono::microseconds(4))
+ __libcpp_thread_yield();
+ else
+ ; // poll
+ return false;
+}
+
+static _LIBCPP_CONSTEXPR const int __libcpp_polling_count = 64;
+
+template<class _Fn, class _BFn>
+bool __libcpp_thread_poll_with_backoff(_Fn && __f, _BFn && __bf, chrono::nanoseconds __max_elapsed)
+{
+ auto const __start = chrono::high_resolution_clock::now();
+ for(int __count = 0;;) {
+ if(__f())
+ return true; // _Fn completion means success
+ if(__count < __libcpp_polling_count) {
+ __count += 1;
+ continue;
+ }
+ chrono::nanoseconds const __elapsed = chrono::high_resolution_clock::now() - __start;
+ if(__max_elapsed != chrono::nanoseconds::zero() && __max_elapsed < __elapsed)
+ return false; // timeout failure
+ if(__bf(__elapsed))
+ return false; // _BFn completion means failure
+ }
+}
+
#endif // !_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL || _LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL
class _LIBCPP_TYPE_VIS thread;
More information about the libcxx-commits
mailing list