# include <bits/c++0x_warning.h>
#else
-#include <bits/c++config.h>
+#include <chrono> // std::chrono::*
+
+#ifdef _GLIBCXX_USE_NANOSLEEP
+# include <cerrno> // errno, EINTR
+# include <time.h> // nanosleep
+#endif
#if defined(_GLIBCXX_HAS_GTHREADS)
#include <bits/gthr.h>
-#include <chrono> // std::chrono::*
#include <memory> // std::unique_ptr
#include <tuple> // std::tuple
# include <stop_token> // std::stop_source, std::stop_token, std::nostopstate
#endif
-#ifdef _GLIBCXX_USE_NANOSLEEP
-# include <cerrno> // errno, EINTR
-# include <time.h> // nanosleep
-#endif
-
#include <bits/functional_hash.h> // std::hash
#include <bits/invoke.h> // std::__invoke
+#endif // _GLIBCXX_HAS_GTHREADS
+
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
* @{
*/
+#if defined(_GLIBCXX_HAS_GTHREADS)
/// thread
class thread
{
else
return __out << __id._M_thread;
}
+#endif // _GLIBCXX_HAS_GTHREADS
/** @namespace std::this_thread
* @brief ISO C++ 2011 namespace for interacting with the current thread
*/
namespace this_thread
{
+#if defined _GLIBCXX_HAS_GTHREADS
/// get_id
inline thread::id
get_id() noexcept
#endif
return thread::id(__gthread_self());
}
+#endif // _GLIBCXX_HAS_GTHREADS
/// yield
inline void
yield() noexcept
{
-#ifdef _GLIBCXX_USE_SCHED_YIELD
+#if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
__gthread_yield();
#endif
}
auto __s = chrono::duration_cast<chrono::seconds>(__rtime);
auto __ns = chrono::duration_cast<chrono::nanoseconds>(__rtime - __s);
#ifdef _GLIBCXX_USE_NANOSLEEP
- __gthread_time_t __ts =
+ struct ::timespec __ts =
{
static_cast<std::time_t>(__s.count()),
static_cast<long>(__ns.count())
}
}
- // @} group threads
-
#ifdef __cpp_lib_jthread
class jthread
thread _M_thread;
};
#endif // __cpp_lib_jthread
+
+ // @} group threads
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
-#endif // _GLIBCXX_HAS_GTHREADS
#endif // C++11
#endif // _GLIBCXX_THREAD
#include <cerrno>
#include <cxxabi_forced.h>
+#ifndef _GLIBCXX_USE_NANOSLEEP
+# ifdef _GLIBCXX_HAVE_SLEEP
+# include <unistd.h>
+# elif defined(_GLIBCXX_HAVE_WIN32_SLEEP)
+# include <windows.h>
+# else
+# error "No sleep function known for this target"
+# endif
+#endif
+
#ifdef _GLIBCXX_HAS_GTHREADS
#if defined(_GLIBCXX_USE_GET_NPROCS)
# define _GLIBCXX_NPROCS 0
#endif
-#ifndef _GLIBCXX_USE_NANOSLEEP
-# ifdef _GLIBCXX_HAVE_SLEEP
-# include <unistd.h>
-# elif defined(_GLIBCXX_HAVE_WIN32_SLEEP)
-# include <windows.h>
-# else
-# error "No sleep function known for this target"
-# endif
-#endif
-
namespace std _GLIBCXX_VISIBILITY(default)
{
extern "C"
return __n;
}
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace std
+
+#endif // _GLIBCXX_HAS_GTHREADS
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace this_thread
{
void
__sleep_for(chrono::seconds __s, chrono::nanoseconds __ns)
{
#ifdef _GLIBCXX_USE_NANOSLEEP
- __gthread_time_t __ts =
+ struct ::timespec __ts =
{
static_cast<std::time_t>(__s.count()),
static_cast<long>(__ns.count())
#endif
}
}
-
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
-
-#endif // _GLIBCXX_HAS_GTHREADS
+++ /dev/null
-// { dg-do run }
-// { dg-options "-pthread" }
-// { dg-require-effective-target c++11 }
-// { dg-require-effective-target pthread }
-// { dg-require-gthreads "" }
-
-// Copyright (C) 2008-2020 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library. This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 3, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING3. If not see
-// <http://www.gnu.org/licenses/>.
-
-
-#include <thread>
-#include <system_error>
-#include <testsuite_hooks.h>
-
-int main()
-{
- try
- {
- std::this_thread::yield();
- }
- catch (const std::system_error&)
- {
- VERIFY( false );
- }
- catch (...)
- {
- VERIFY( false );
- }
-
- return 0;
-}
+++ /dev/null
-// { dg-do run }
-// { dg-options "-pthread" }
-// { dg-require-effective-target c++11 }
-// { dg-require-effective-target pthread }
-// { dg-require-gthreads "" }
-// { dg-require-sleep "" }
-
-// Copyright (C) 2008-2020 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library. This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 3, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING3. If not see
-// <http://www.gnu.org/licenses/>.
-
-
-#include <chrono>
-#include <thread>
-#include <system_error>
-#include <testsuite_hooks.h>
-
-namespace chr = std::chrono;
-
-void foo()
-{
- chr::system_clock::time_point begin = chr::system_clock::now();
- chr::microseconds ms(500);
-
- std::this_thread::sleep_for(ms);
-
- VERIFY( (chr::system_clock::now() - begin) >= ms );
-}
-
-int main()
-{
- try
- {
- std::thread t(foo);
- t.join();
- }
- catch (const std::system_error&)
- {
- VERIFY( false );
- }
- catch (...)
- {
- VERIFY( false );
- }
-
- return 0;
-}
+++ /dev/null
-// { dg-do run }
-// { dg-options "-pthread" }
-// { dg-require-effective-target c++11 }
-// { dg-require-effective-target pthread }
-// { dg-require-gthreads "" }
-// { dg-require-sleep "" }
-
-// Copyright (C) 2008-2020 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library. This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 3, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING3. If not see
-// <http://www.gnu.org/licenses/>.
-
-
-#include <chrono>
-#include <thread>
-#include <system_error>
-#include <testsuite_hooks.h>
-
-namespace chr = std::chrono;
-
-void foo()
-{
- chr::system_clock::time_point begin = chr::system_clock::now();
- chr::microseconds ms(500);
-
- std::this_thread::sleep_until(chr::system_clock::now() + ms);
-
- VERIFY( (chr::system_clock::now() - begin) >= ms );
-}
-
-int main()
-{
- try
- {
- std::thread t(foo);
- t.join();
- }
- catch (const std::system_error&)
- {
- VERIFY( false );
- }
- catch (...)
- {
- VERIFY( false );
- }
-
- return 0;
-}
// { dg-do run { target c++11 } }
// { dg-require-time "" }
+// { dg-require-sleep "" }
#include <thread>
#include <chrono>
// { dg-require-cstdint "" }
// { dg-require-gthreads "" }
// { dg-require-time "" }
+// { dg-require-sleep "" }
#include <thread>
#include <chrono>
--- /dev/null
+// { dg-do run }
+// { dg-options "-pthread" }
+// { dg-require-effective-target c++11 }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+// { dg-require-sleep "" }
+
+// Copyright (C) 2008-2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <chrono>
+#include <thread>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+namespace chr = std::chrono;
+
+void foo()
+{
+ chr::system_clock::time_point begin = chr::system_clock::now();
+ chr::microseconds ms(500);
+
+ std::this_thread::sleep_for(ms);
+
+ VERIFY( (chr::system_clock::now() - begin) >= ms );
+}
+
+int main()
+{
+ try
+ {
+ std::thread t(foo);
+ t.join();
+ }
+ catch (const std::system_error&)
+ {
+ VERIFY( false );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+
+ return 0;
+}
--- /dev/null
+// { dg-do run { target c++11 } }
+// { dg-require-sleep "" }
+
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <chrono>
+#include <thread>
+#include <testsuite_hooks.h>
+
+// This tests this_thread::sleep_until without using -pthread
+
+namespace chr = std::chrono;
+
+void
+test01()
+{
+ chr::system_clock::time_point begin = chr::system_clock::now();
+ chr::microseconds ms(500);
+
+ std::this_thread::sleep_for(ms);
+
+ VERIFY( (chr::system_clock::now() - begin) >= ms );
+}
+
+int main()
+{
+ test01();
+}
--- /dev/null
+// { dg-do run }
+// { dg-options "-pthread" }
+// { dg-require-effective-target c++11 }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+// { dg-require-sleep "" }
+
+// Copyright (C) 2008-2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <chrono>
+#include <thread>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+namespace chr = std::chrono;
+
+void foo()
+{
+ chr::system_clock::time_point begin = chr::system_clock::now();
+ chr::microseconds ms(500);
+
+ std::this_thread::sleep_until(chr::system_clock::now() + ms);
+
+ VERIFY( (chr::system_clock::now() - begin) >= ms );
+}
+
+int main()
+{
+ try
+ {
+ std::thread t(foo);
+ t.join();
+ }
+ catch (const std::system_error&)
+ {
+ VERIFY( false );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+
+ return 0;
+}
--- /dev/null
+// { dg-do run { target c++11 } }
+// { dg-require-sleep "" }
+
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <chrono>
+#include <thread>
+#include <testsuite_hooks.h>
+
+// This tests this_thread::sleep_until without using -pthread
+
+namespace chr = std::chrono;
+
+void
+test01()
+{
+ chr::system_clock::time_point begin = chr::system_clock::now();
+ chr::microseconds ms(500);
+
+ std::this_thread::sleep_until(chr::system_clock::now() + ms);
+
+ VERIFY( (chr::system_clock::now() - begin) >= ms );
+}
+
+int main()
+{
+ test01();
+}
--- /dev/null
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-pthread" { target pthread } }
+
+// Copyright (C) 2008-2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <thread>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+int main()
+{
+ try
+ {
+ std::this_thread::yield();
+ }
+ catch (const std::system_error&)
+ {
+ VERIFY( false );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+
+ return 0;
+}