2008-09-13 02:32:37 +02:00
|
|
|
// <thread> -*- C++ -*-
|
|
|
|
|
2017-01-01 13:07:43 +01:00
|
|
|
// Copyright (C) 2008-2017 Free Software Foundation, Inc.
|
2008-09-13 02:32:37 +02:00
|
|
|
//
|
|
|
|
// 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
|
2009-04-09 17:00:19 +02:00
|
|
|
// Free Software Foundation; either version 3, or (at your option)
|
2008-09-13 02:32:37 +02:00
|
|
|
// 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.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
|
|
// 3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
2008-09-13 02:32:37 +02:00
|
|
|
|
2010-12-19 10:21:16 +01:00
|
|
|
/** @file include/thread
|
2008-09-13 02:32:37 +02:00
|
|
|
* This is a Standard C++ Library header.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GLIBCXX_THREAD
|
|
|
|
#define _GLIBCXX_THREAD 1
|
|
|
|
|
|
|
|
#pragma GCC system_header
|
|
|
|
|
2012-11-10 18:27:22 +01:00
|
|
|
#if __cplusplus < 201103L
|
2010-02-10 20:14:33 +01:00
|
|
|
# include <bits/c++0x_warning.h>
|
2008-09-13 02:32:37 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <memory>
|
2016-10-13 12:37:13 +02:00
|
|
|
#include <tuple>
|
2015-11-12 17:13:06 +01:00
|
|
|
#include <cerrno>
|
2008-09-13 02:32:37 +02:00
|
|
|
#include <bits/functexcept.h>
|
2010-02-23 16:23:37 +01:00
|
|
|
#include <bits/functional_hash.h>
|
2016-10-13 12:37:13 +02:00
|
|
|
#include <bits/invoke.h>
|
2008-09-13 02:32:37 +02:00
|
|
|
#include <bits/gthr.h>
|
|
|
|
|
|
|
|
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
|
|
|
|
|
PR libstdc++/36104 part four
2011-01-30 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part four
* include/bits/c++config (_GLIBCXX_STD): Remove.
(_GLIBCXX_STD_D, _GLIBCXX_PR): Now _GLIBCXX_STD_C.
(_GLIBCXX_P): Now _GLIBCXX_STD_A.
(_GLIBCXX_NAMESPACE_DEBUG, _GLIBCXX_NAMESPACE_PARALLEL,
_GLIBCXX_NAMESPACE_PROFILE, _GLIBCXX_NAMESPACE_VERSION): Remove.
(_GLIBCXX_INLINE_DEBUG, _GLIBCXX_INLINE_PARALLEL,
_GLIBCXX_INLINE_PROFILE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE(X)): Remove.
(_GLIBCXX_END_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y)): Remove.
(_GLIBCXX_END_NESTED_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE_ALGO): Add.
(_GLIBCXX_END_NAMESPACE_ALGO): Add.
(_GLIBCXX_BEGIN_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_END_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_BEGIN_NAMESPACE_VERSION): Add.
(_GLIBCXX_END_NAMESPACE_VERSION): Add.
(_GLIBCXX_BEGIN_LDBL_NAMESPACE): To _GLIBCXX_BEGIN_NAMESPACE_LDBL.
(_GLIBCXX_END_LDBL_NAMESPACE): To _GLIBCXX_END_NAMESPACE_LDBL.
(_GLIBCXX_VISIBILITY_ATTR): Revert to _GLIBCXX_VISIBILITY.
* include/*: Use new macros for namespace scope.
* config/*: Same.
* src/*: Same.
* src/Makefile.am (sources): Remove debug_list.cc, add
compatibility-debug_list-2.cc.
(parallel_sources): Remove parallel_list.cc, add
compatibility-parallel_list-2.cc.
(compatibility-parallel_list-2.[o,lo]): New rule.
* src/Makefile.in: Regenerate.
* src/debug_list.cc: Remove.
* src/parallel_list.cc: Remove.
* src/compatibility-list-2.cc: New.
* src/compatibility-debug_list-2.cc: New.
* src/compatibility-parallel_list-2.cc: New.
* doc/doxygen/user.cfg.in: Adjust macros.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust line numbers, macros.
* testsuite/20_util/declval/requirements/1_neg.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/forward/c_neg.cc: Same.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Same.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/forward_list/capacity/1.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Same.
* testsuite/23_containers/list/capacity/29134.cc: Same.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/bool/capacity/29134.cc: Same.
* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/25_algorithms/sort/35588.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* testsuite/ext/profile/mutex_extensions_neg.cc: Same.
* testsuite/ext/profile/profiler_algos.cc: Same.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Same.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
From-SVN: r169421
2011-01-30 23:39:36 +01:00
|
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
|
|
|
{
|
|
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
2010-11-02 19:51:23 +01:00
|
|
|
|
2009-02-21 01:45:21 +01:00
|
|
|
/**
|
|
|
|
* @defgroup threads Threads
|
|
|
|
* @ingroup concurrency
|
|
|
|
*
|
|
|
|
* Classes for thread support.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-02-07 22:56:55 +01:00
|
|
|
/// thread
|
2009-02-05 18:47:56 +01:00
|
|
|
class thread
|
2008-09-13 02:32:37 +02:00
|
|
|
{
|
|
|
|
public:
|
2015-09-29 14:54:05 +02:00
|
|
|
// Abstract base class for types that wrap arbitrary functors to be
|
|
|
|
// invoked in the new thread of execution.
|
|
|
|
struct _State
|
|
|
|
{
|
|
|
|
virtual ~_State();
|
|
|
|
virtual void _M_run() = 0;
|
|
|
|
};
|
|
|
|
using _State_ptr = unique_ptr<_State>;
|
|
|
|
|
2009-02-14 00:08:50 +01:00
|
|
|
typedef __gthread_t native_handle_type;
|
2009-02-07 22:56:55 +01:00
|
|
|
|
|
|
|
/// thread::id
|
|
|
|
class id
|
2008-09-13 02:32:37 +02:00
|
|
|
{
|
2009-02-14 00:08:50 +01:00
|
|
|
native_handle_type _M_thread;
|
2009-02-07 22:56:55 +01:00
|
|
|
|
2008-09-13 02:32:37 +02:00
|
|
|
public:
|
2011-05-25 16:32:06 +02:00
|
|
|
id() noexcept : _M_thread() { }
|
2009-02-07 22:56:55 +01:00
|
|
|
|
|
|
|
explicit
|
|
|
|
id(native_handle_type __id) : _M_thread(__id) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class thread;
|
2010-02-23 16:23:37 +01:00
|
|
|
friend class hash<thread::id>;
|
2009-02-07 22:56:55 +01:00
|
|
|
|
|
|
|
friend bool
|
2016-04-18 18:16:14 +02:00
|
|
|
operator==(thread::id __x, thread::id __y) noexcept;
|
2009-02-07 22:56:55 +01:00
|
|
|
|
|
|
|
friend bool
|
2016-04-18 18:16:14 +02:00
|
|
|
operator<(thread::id __x, thread::id __y) noexcept;
|
2009-02-07 22:56:55 +01:00
|
|
|
|
|
|
|
template<class _CharT, class _Traits>
|
|
|
|
friend basic_ostream<_CharT, _Traits>&
|
2009-05-19 00:15:56 +02:00
|
|
|
operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id);
|
2009-02-07 22:56:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2009-02-14 00:08:50 +01:00
|
|
|
id _M_id;
|
2009-02-07 22:56:55 +01:00
|
|
|
|
|
|
|
public:
|
2011-05-25 16:32:06 +02:00
|
|
|
thread() noexcept = default;
|
2012-11-19 23:28:00 +01:00
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 2097. packaged_task constructors should be constrained
|
2010-08-06 21:41:23 +02:00
|
|
|
thread(thread&) = delete;
|
2009-02-07 22:56:55 +01:00
|
|
|
thread(const thread&) = delete;
|
2017-01-03 14:31:26 +01:00
|
|
|
thread(const thread&&) = delete;
|
2009-02-07 22:56:55 +01:00
|
|
|
|
2011-05-25 16:32:06 +02:00
|
|
|
thread(thread&& __t) noexcept
|
2009-02-07 22:56:55 +01:00
|
|
|
{ swap(__t); }
|
|
|
|
|
2008-09-13 02:32:37 +02:00
|
|
|
template<typename _Callable, typename... _Args>
|
2016-06-16 15:47:35 +02:00
|
|
|
explicit
|
2008-09-13 02:32:37 +02:00
|
|
|
thread(_Callable&& __f, _Args&&... __args)
|
2010-10-08 02:44:12 +02:00
|
|
|
{
|
2014-08-13 20:40:10 +02:00
|
|
|
#ifdef GTHR_ACTIVE_PROXY
|
2015-09-29 14:54:05 +02:00
|
|
|
// Create a reference to pthread_create, not just the gthr weak symbol.
|
|
|
|
auto __depend = reinterpret_cast<void(*)()>(&pthread_create);
|
2014-08-13 20:40:10 +02:00
|
|
|
#else
|
2015-09-29 14:54:05 +02:00
|
|
|
auto __depend = nullptr;
|
2014-08-13 20:40:10 +02:00
|
|
|
#endif
|
2015-09-29 14:54:05 +02:00
|
|
|
_M_start_thread(_S_make_state(
|
2016-10-13 12:37:13 +02:00
|
|
|
__make_invoker(std::forward<_Callable>(__f),
|
|
|
|
std::forward<_Args>(__args)...)),
|
2015-09-29 14:54:05 +02:00
|
|
|
__depend);
|
2010-10-08 02:44:12 +02:00
|
|
|
}
|
2008-09-13 02:32:37 +02:00
|
|
|
|
2009-01-15 15:01:04 +01:00
|
|
|
~thread()
|
2009-01-30 00:24:05 +01:00
|
|
|
{
|
|
|
|
if (joinable())
|
2009-06-16 22:34:43 +02:00
|
|
|
std::terminate();
|
2009-01-30 00:24:05 +01:00
|
|
|
}
|
2008-09-13 02:32:37 +02:00
|
|
|
|
|
|
|
thread& operator=(const thread&) = delete;
|
2009-02-07 22:56:55 +01:00
|
|
|
|
2011-05-25 16:32:06 +02:00
|
|
|
thread& operator=(thread&& __t) noexcept
|
2009-01-22 23:33:02 +01:00
|
|
|
{
|
|
|
|
if (joinable())
|
2009-06-16 22:34:43 +02:00
|
|
|
std::terminate();
|
2009-01-22 23:33:02 +01:00
|
|
|
swap(__t);
|
|
|
|
return *this;
|
|
|
|
}
|
2008-09-13 02:32:37 +02:00
|
|
|
|
2009-02-07 22:56:55 +01:00
|
|
|
void
|
2011-05-25 16:32:06 +02:00
|
|
|
swap(thread& __t) noexcept
|
2009-02-14 00:08:50 +01:00
|
|
|
{ std::swap(_M_id, __t._M_id); }
|
2008-09-13 02:32:37 +02:00
|
|
|
|
2009-02-07 22:56:55 +01:00
|
|
|
bool
|
2011-05-25 16:32:06 +02:00
|
|
|
joinable() const noexcept
|
2009-02-14 00:08:50 +01:00
|
|
|
{ return !(_M_id == id()); }
|
2008-09-13 02:32:37 +02:00
|
|
|
|
2009-02-07 22:56:55 +01:00
|
|
|
void
|
2008-09-13 02:32:37 +02:00
|
|
|
join();
|
|
|
|
|
2009-02-07 22:56:55 +01:00
|
|
|
void
|
2008-09-13 02:32:37 +02:00
|
|
|
detach();
|
|
|
|
|
2009-01-15 15:01:04 +01:00
|
|
|
thread::id
|
2011-05-25 16:32:06 +02:00
|
|
|
get_id() const noexcept
|
2009-02-14 00:08:50 +01:00
|
|
|
{ return _M_id; }
|
2008-09-13 02:32:37 +02:00
|
|
|
|
2009-01-30 00:24:05 +01:00
|
|
|
/** @pre thread is joinable
|
|
|
|
*/
|
2009-02-07 22:56:55 +01:00
|
|
|
native_handle_type
|
2008-09-13 02:32:37 +02:00
|
|
|
native_handle()
|
2009-02-14 00:08:50 +01:00
|
|
|
{ return _M_id._M_thread; }
|
2008-09-13 02:32:37 +02:00
|
|
|
|
2009-02-07 22:56:55 +01:00
|
|
|
// Returns a value that hints at the number of hardware thread contexts.
|
|
|
|
static unsigned int
|
2011-05-28 19:27:01 +02:00
|
|
|
hardware_concurrency() noexcept;
|
2008-09-13 02:32:37 +02:00
|
|
|
|
|
|
|
private:
|
2015-09-29 14:54:05 +02:00
|
|
|
template<typename _Callable>
|
|
|
|
struct _State_impl : public _State
|
|
|
|
{
|
|
|
|
_Callable _M_func;
|
|
|
|
|
|
|
|
_State_impl(_Callable&& __f) : _M_func(std::forward<_Callable>(__f))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void
|
|
|
|
_M_run() { _M_func(); }
|
|
|
|
};
|
2014-08-13 20:40:10 +02:00
|
|
|
|
2009-02-14 00:08:50 +01:00
|
|
|
void
|
2015-09-29 14:54:05 +02:00
|
|
|
_M_start_thread(_State_ptr, void (*)());
|
2009-02-14 00:08:50 +01:00
|
|
|
|
2008-09-13 02:32:37 +02:00
|
|
|
template<typename _Callable>
|
2015-09-29 14:54:05 +02:00
|
|
|
static _State_ptr
|
|
|
|
_S_make_state(_Callable&& __f)
|
2009-02-05 18:47:56 +01:00
|
|
|
{
|
2015-09-29 14:54:05 +02:00
|
|
|
using _Impl = _State_impl<_Callable>;
|
|
|
|
return _State_ptr{new _Impl{std::forward<_Callable>(__f)}};
|
2008-09-13 02:32:37 +02:00
|
|
|
}
|
2015-09-29 14:54:05 +02:00
|
|
|
#if _GLIBCXX_THREAD_ABI_COMPAT
|
|
|
|
public:
|
|
|
|
struct _Impl_base;
|
|
|
|
typedef shared_ptr<_Impl_base> __shared_base_type;
|
|
|
|
struct _Impl_base
|
|
|
|
{
|
|
|
|
__shared_base_type _M_this_ptr;
|
|
|
|
virtual ~_Impl_base() = default;
|
|
|
|
virtual void _M_run() = 0;
|
|
|
|
};
|
2008-09-13 02:32:37 +02:00
|
|
|
|
2015-09-29 14:54:05 +02:00
|
|
|
private:
|
|
|
|
void
|
|
|
|
_M_start_thread(__shared_base_type, void (*)());
|
|
|
|
|
|
|
|
void
|
|
|
|
_M_start_thread(__shared_base_type);
|
|
|
|
#endif
|
2016-10-13 12:37:13 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// A call wrapper that does INVOKE(forwarded tuple elements...)
|
|
|
|
template<typename _Tuple>
|
|
|
|
struct _Invoker
|
|
|
|
{
|
|
|
|
_Tuple _M_t;
|
|
|
|
|
|
|
|
template<size_t _Index>
|
|
|
|
static __tuple_element_t<_Index, _Tuple>&&
|
|
|
|
_S_declval();
|
|
|
|
|
|
|
|
template<size_t... _Ind>
|
|
|
|
auto
|
|
|
|
_M_invoke(_Index_tuple<_Ind...>)
|
|
|
|
noexcept(noexcept(std::__invoke(_S_declval<_Ind>()...)))
|
|
|
|
-> decltype(std::__invoke(_S_declval<_Ind>()...))
|
|
|
|
{ return std::__invoke(std::get<_Ind>(std::move(_M_t))...); }
|
|
|
|
|
|
|
|
using _Indices
|
|
|
|
= typename _Build_index_tuple<tuple_size<_Tuple>::value>::__type;
|
|
|
|
|
2016-10-17 14:23:09 +02:00
|
|
|
auto
|
2016-10-13 12:37:13 +02:00
|
|
|
operator()()
|
2016-10-17 14:23:09 +02:00
|
|
|
noexcept(noexcept(std::declval<_Invoker&>()._M_invoke(_Indices())))
|
|
|
|
-> decltype(std::declval<_Invoker&>()._M_invoke(_Indices()))
|
2016-10-13 12:37:13 +02:00
|
|
|
{ return _M_invoke(_Indices()); }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Alias for _Invoker<tuple<DECAY_COPY(_Tp)...>>
|
|
|
|
template<typename... _Tp>
|
|
|
|
using __invoker_type
|
|
|
|
= _Invoker<decltype(std::make_tuple(std::declval<_Tp>()...))>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Returns a call wrapper that does
|
|
|
|
// INVOKE(DECAY_COPY(__callable), DECAY_COPY(__args)).
|
|
|
|
template<typename _Callable, typename... _Args>
|
|
|
|
static __invoker_type<_Callable, _Args...>
|
|
|
|
__make_invoker(_Callable&& __callable, _Args&&... __args)
|
|
|
|
{
|
|
|
|
return { {
|
|
|
|
std::make_tuple(std::forward<_Callable>(__callable),
|
|
|
|
std::forward<_Args>(__args)...)
|
|
|
|
} };
|
|
|
|
}
|
2015-09-29 14:54:05 +02:00
|
|
|
};
|
2011-03-16 01:02:11 +01:00
|
|
|
|
2008-09-13 02:32:37 +02:00
|
|
|
inline void
|
2011-05-25 16:32:06 +02:00
|
|
|
swap(thread& __x, thread& __y) noexcept
|
2008-09-13 02:32:37 +02:00
|
|
|
{ __x.swap(__y); }
|
|
|
|
|
2016-04-18 18:16:14 +02:00
|
|
|
inline bool
|
|
|
|
operator==(thread::id __x, thread::id __y) noexcept
|
|
|
|
{
|
|
|
|
// pthread_equal is undefined if either thread ID is not valid, so we
|
|
|
|
// can't safely use __gthread_equal on default-constructed values (nor
|
|
|
|
// the non-zero value returned by this_thread::get_id() for
|
|
|
|
// single-threaded programs using GNU libc). Assume EqualityComparable.
|
|
|
|
return __x._M_thread == __y._M_thread;
|
|
|
|
}
|
|
|
|
|
2009-02-07 22:56:55 +01:00
|
|
|
inline bool
|
2011-05-25 16:32:06 +02:00
|
|
|
operator!=(thread::id __x, thread::id __y) noexcept
|
2009-02-07 22:56:55 +01:00
|
|
|
{ return !(__x == __y); }
|
|
|
|
|
2016-04-18 18:16:14 +02:00
|
|
|
inline bool
|
|
|
|
operator<(thread::id __x, thread::id __y) noexcept
|
|
|
|
{
|
|
|
|
// Pthreads doesn't define any way to do this, so we just have to
|
|
|
|
// assume native_handle_type is LessThanComparable.
|
|
|
|
return __x._M_thread < __y._M_thread;
|
|
|
|
}
|
|
|
|
|
2009-02-07 22:56:55 +01:00
|
|
|
inline bool
|
2011-05-25 16:32:06 +02:00
|
|
|
operator<=(thread::id __x, thread::id __y) noexcept
|
2009-02-07 22:56:55 +01:00
|
|
|
{ return !(__y < __x); }
|
|
|
|
|
|
|
|
inline bool
|
2011-05-25 16:32:06 +02:00
|
|
|
operator>(thread::id __x, thread::id __y) noexcept
|
2009-02-07 22:56:55 +01:00
|
|
|
{ return __y < __x; }
|
|
|
|
|
|
|
|
inline bool
|
2011-05-25 16:32:06 +02:00
|
|
|
operator>=(thread::id __x, thread::id __y) noexcept
|
2009-02-07 22:56:55 +01:00
|
|
|
{ return !(__x < __y); }
|
|
|
|
|
2010-02-23 16:23:37 +01:00
|
|
|
// DR 889.
|
|
|
|
/// std::hash specialization for thread::id.
|
|
|
|
template<>
|
|
|
|
struct hash<thread::id>
|
2010-09-22 19:50:36 +02:00
|
|
|
: public __hash_base<size_t, thread::id>
|
2010-02-23 16:23:37 +01:00
|
|
|
{
|
|
|
|
size_t
|
hash-long-double-aux.cc: Rename to...
2011-11-18 Paolo Carlini <paolo.carlini@oracle.com>
* src/hash-long-double-aux.cc: Rename to...
* src/hash-long-double-tr1-aux.cc: ... this.
* src/compatibility-ldbl.cc: Adjust.
* src/hash_tr1.cc: Likewise.
* src/hash_c++0x.cc: Don't use src/hash-long-double-aux.cc.
* include/bits/functional_hash.h (hash<_Tp*>::operator(), specs
for integer types, hash<float>::operator(), hash<double>::operator(),
hash<long double>::operator()): Declare noexcept.
* include/debug/bitset (hash<__debug::bitset>::operator()): Likewise.
* include/debug/vector (hash<__debug::vector>::operator()): Likewise.
* include/std/system_error (hash<error_code>::operator()): Likewise.
* include/std/thread (hash<thread::id>::operator()): Likewise.
* include/std/bitset (hash<bitset>::operator()): Likewise.
* include/std/typeindex (hash<type_index>::operator()): Likewise.
* include/profile/bitset (hash<__profile::vector>::operator()):
Likewise.
* include/profile/vector (hash<__profile::vector>::operator()):
Likewise.
* include/ext/vstring.h (hash<__vstring>::operator(),
hash<__wvstring>::operator(), hash<__u16vstring>::operator(),
hash<__u32vstring>::operator()): Likewise.
* include/bits/shared_ptr.h (hash<shared_ptr>::operator()): Likewise.
* include/bits/shared_ptr_base.h (hash<__shared_ptr>::operator()):
Likewise.
* include/bits/unique_ptr.h (hash<unique_ptr>::operator()): Likewise.
* include/bits/basic_string.h (hash<string>::operator(),
hash<wstring>::operator(), hash<u16string>::operator(),
hash<u32string>::operator()): Likewise.
* include/bits/vector.tcc (hash<vector>::operator()): Likewise.
* include/bits/stl_bvector.h (hash<vector>::operator()): Likewise.
* libsupc++/typeinfo (type_info::hash_code): Use noexcept instead of
throw().
From-SVN: r181473
2011-11-18 13:37:06 +01:00
|
|
|
operator()(const thread::id& __id) const noexcept
|
hash_bytes.cc: New file...
2010-09-13 Matt Austern <austern@google.com>
* src/hash_bytes.cc: New file, exports _Hash_bytes (a Murmur hash),
and _Fnv_hash_bytes (based on a FNV algorithm).
* src/compatibility-c++0x.cc (hash<string>::operator(),
hash<const string&>::operator(), hash<wstring>::operator(),
hash<const wstring&>::operator(), hash<error_code>::operator()):
Adjust, use _Hash_bytes.
* include/std/system_error (hash<error_code>::operator()): Likewise.
* include/std/thread (hash<thread::id>operator()): Likewise.
* include/std/bitset (hash<bitset>operator()): Likewise.
* include/bits/basic_string.h (hash<string>::operator(),
hash<wstring>::operator(), hash<u16string>::operator(),
hash<u32string>::operator()): Adjust.
* include/bits/vector.tcc (hash<vector<bool>>::operator()): Adjust.
* include/bits/functional_hash.h (_Hash_bytes, _Fnv_hash_bytes):
Declare.
(struct _Hash_impl, struct _Fnv_hash_impl): Add, use _Hash_bytes
and _Fnv_hash_bytes, respectively.
(hash<float>::operator(), hash<double>::operator()): Adjust.
* config/abi/pre/gnu.ver: Add exports.
* src/Makefile.am: Add.
* src/Makefile.in: Regenerate.
From-SVN: r164253
2010-09-13 20:23:56 +02:00
|
|
|
{ return std::_Hash_impl::hash(__id._M_thread); }
|
2010-02-23 16:23:37 +01:00
|
|
|
};
|
|
|
|
|
2009-02-07 22:56:55 +01:00
|
|
|
template<class _CharT, class _Traits>
|
|
|
|
inline basic_ostream<_CharT, _Traits>&
|
2009-05-19 00:15:56 +02:00
|
|
|
operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id)
|
2009-02-07 22:56:55 +01:00
|
|
|
{
|
|
|
|
if (__id == thread::id())
|
|
|
|
return __out << "thread::id of a non-executing thread";
|
|
|
|
else
|
|
|
|
return __out << __id._M_thread;
|
|
|
|
}
|
|
|
|
|
2009-02-21 01:45:21 +01:00
|
|
|
/** @namespace std::this_thread
|
2012-08-10 00:45:20 +02:00
|
|
|
* @brief ISO C++ 2011 entities sub-namespace for thread.
|
|
|
|
* 30.3.2 Namespace this_thread.
|
2009-02-21 01:45:21 +01:00
|
|
|
*/
|
2008-09-13 02:32:37 +02:00
|
|
|
namespace this_thread
|
|
|
|
{
|
2009-02-10 09:29:57 +01:00
|
|
|
/// get_id
|
2009-02-09 07:32:12 +01:00
|
|
|
inline thread::id
|
2015-12-04 18:32:40 +01:00
|
|
|
get_id() noexcept
|
|
|
|
{
|
|
|
|
#ifdef __GLIBC__
|
|
|
|
// For the GNU C library pthread_self() is usable without linking to
|
|
|
|
// libpthread.so but returns 0, so we cannot use it in single-threaded
|
|
|
|
// programs, because this_thread::get_id() != thread::id{} must be true.
|
|
|
|
// We know that pthread_t is an integral type in the GNU C library.
|
|
|
|
if (!__gthread_active_p())
|
|
|
|
return thread::id(1);
|
|
|
|
#endif
|
|
|
|
return thread::id(__gthread_self());
|
|
|
|
}
|
2008-09-13 02:32:37 +02:00
|
|
|
|
2009-02-10 09:29:57 +01:00
|
|
|
/// yield
|
2009-01-15 15:01:04 +01:00
|
|
|
inline void
|
2011-05-25 16:32:06 +02:00
|
|
|
yield() noexcept
|
2012-11-23 23:11:23 +01:00
|
|
|
{
|
|
|
|
#ifdef _GLIBCXX_USE_SCHED_YIELD
|
|
|
|
__gthread_yield();
|
2009-01-15 15:01:04 +01:00
|
|
|
#endif
|
2012-11-23 23:11:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
__sleep_for(chrono::seconds, chrono::nanoseconds);
|
2008-09-13 02:32:37 +02:00
|
|
|
|
2009-02-10 09:29:57 +01:00
|
|
|
/// sleep_for
|
2008-09-13 02:32:37 +02:00
|
|
|
template<typename _Rep, typename _Period>
|
2009-01-15 15:01:04 +01:00
|
|
|
inline void
|
2008-09-13 02:32:37 +02:00
|
|
|
sleep_for(const chrono::duration<_Rep, _Period>& __rtime)
|
|
|
|
{
|
2015-03-26 20:59:08 +01:00
|
|
|
if (__rtime <= __rtime.zero())
|
|
|
|
return;
|
2012-11-23 23:11:23 +01:00
|
|
|
auto __s = chrono::duration_cast<chrono::seconds>(__rtime);
|
|
|
|
auto __ns = chrono::duration_cast<chrono::nanoseconds>(__rtime - __s);
|
|
|
|
#ifdef _GLIBCXX_USE_NANOSLEEP
|
2009-02-07 22:56:55 +01:00
|
|
|
__gthread_time_t __ts =
|
2008-09-13 02:32:37 +02:00
|
|
|
{
|
|
|
|
static_cast<std::time_t>(__s.count()),
|
|
|
|
static_cast<long>(__ns.count())
|
|
|
|
};
|
2015-11-11 18:08:51 +01:00
|
|
|
while (::nanosleep(&__ts, &__ts) == -1 && errno == EINTR)
|
|
|
|
{ }
|
2012-11-23 23:11:23 +01:00
|
|
|
#else
|
|
|
|
__sleep_for(__s, __ns);
|
|
|
|
#endif
|
2008-09-13 02:32:37 +02:00
|
|
|
}
|
2011-05-27 23:37:53 +02:00
|
|
|
|
|
|
|
/// sleep_until
|
|
|
|
template<typename _Clock, typename _Duration>
|
|
|
|
inline void
|
|
|
|
sleep_until(const chrono::time_point<_Clock, _Duration>& __atime)
|
2015-03-26 20:59:08 +01:00
|
|
|
{
|
|
|
|
auto __now = _Clock::now();
|
2015-11-11 18:08:51 +01:00
|
|
|
if (_Clock::is_steady)
|
|
|
|
{
|
|
|
|
if (__now < __atime)
|
|
|
|
sleep_for(__atime - __now);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (__now < __atime)
|
|
|
|
{
|
|
|
|
sleep_for(__atime - __now);
|
|
|
|
__now = _Clock::now();
|
|
|
|
}
|
2015-03-26 20:59:08 +01:00
|
|
|
}
|
2008-09-13 02:32:37 +02:00
|
|
|
}
|
2009-02-21 01:45:21 +01:00
|
|
|
|
|
|
|
// @} group threads
|
PR libstdc++/36104 part four
2011-01-30 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part four
* include/bits/c++config (_GLIBCXX_STD): Remove.
(_GLIBCXX_STD_D, _GLIBCXX_PR): Now _GLIBCXX_STD_C.
(_GLIBCXX_P): Now _GLIBCXX_STD_A.
(_GLIBCXX_NAMESPACE_DEBUG, _GLIBCXX_NAMESPACE_PARALLEL,
_GLIBCXX_NAMESPACE_PROFILE, _GLIBCXX_NAMESPACE_VERSION): Remove.
(_GLIBCXX_INLINE_DEBUG, _GLIBCXX_INLINE_PARALLEL,
_GLIBCXX_INLINE_PROFILE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE(X)): Remove.
(_GLIBCXX_END_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y)): Remove.
(_GLIBCXX_END_NESTED_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE_ALGO): Add.
(_GLIBCXX_END_NAMESPACE_ALGO): Add.
(_GLIBCXX_BEGIN_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_END_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_BEGIN_NAMESPACE_VERSION): Add.
(_GLIBCXX_END_NAMESPACE_VERSION): Add.
(_GLIBCXX_BEGIN_LDBL_NAMESPACE): To _GLIBCXX_BEGIN_NAMESPACE_LDBL.
(_GLIBCXX_END_LDBL_NAMESPACE): To _GLIBCXX_END_NAMESPACE_LDBL.
(_GLIBCXX_VISIBILITY_ATTR): Revert to _GLIBCXX_VISIBILITY.
* include/*: Use new macros for namespace scope.
* config/*: Same.
* src/*: Same.
* src/Makefile.am (sources): Remove debug_list.cc, add
compatibility-debug_list-2.cc.
(parallel_sources): Remove parallel_list.cc, add
compatibility-parallel_list-2.cc.
(compatibility-parallel_list-2.[o,lo]): New rule.
* src/Makefile.in: Regenerate.
* src/debug_list.cc: Remove.
* src/parallel_list.cc: Remove.
* src/compatibility-list-2.cc: New.
* src/compatibility-debug_list-2.cc: New.
* src/compatibility-parallel_list-2.cc: New.
* doc/doxygen/user.cfg.in: Adjust macros.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust line numbers, macros.
* testsuite/20_util/declval/requirements/1_neg.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/forward/c_neg.cc: Same.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Same.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/forward_list/capacity/1.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Same.
* testsuite/23_containers/list/capacity/29134.cc: Same.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/bool/capacity/29134.cc: Same.
* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/25_algorithms/sort/35588.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* testsuite/ext/profile/mutex_extensions_neg.cc: Same.
* testsuite/ext/profile/profiler_algos.cc: Same.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Same.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
From-SVN: r169421
2011-01-30 23:39:36 +01:00
|
|
|
|
2017-07-23 10:41:35 +02:00
|
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
PR libstdc++/36104 part four
2011-01-30 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part four
* include/bits/c++config (_GLIBCXX_STD): Remove.
(_GLIBCXX_STD_D, _GLIBCXX_PR): Now _GLIBCXX_STD_C.
(_GLIBCXX_P): Now _GLIBCXX_STD_A.
(_GLIBCXX_NAMESPACE_DEBUG, _GLIBCXX_NAMESPACE_PARALLEL,
_GLIBCXX_NAMESPACE_PROFILE, _GLIBCXX_NAMESPACE_VERSION): Remove.
(_GLIBCXX_INLINE_DEBUG, _GLIBCXX_INLINE_PARALLEL,
_GLIBCXX_INLINE_PROFILE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE(X)): Remove.
(_GLIBCXX_END_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y)): Remove.
(_GLIBCXX_END_NESTED_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE_ALGO): Add.
(_GLIBCXX_END_NAMESPACE_ALGO): Add.
(_GLIBCXX_BEGIN_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_END_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_BEGIN_NAMESPACE_VERSION): Add.
(_GLIBCXX_END_NAMESPACE_VERSION): Add.
(_GLIBCXX_BEGIN_LDBL_NAMESPACE): To _GLIBCXX_BEGIN_NAMESPACE_LDBL.
(_GLIBCXX_END_LDBL_NAMESPACE): To _GLIBCXX_END_NAMESPACE_LDBL.
(_GLIBCXX_VISIBILITY_ATTR): Revert to _GLIBCXX_VISIBILITY.
* include/*: Use new macros for namespace scope.
* config/*: Same.
* src/*: Same.
* src/Makefile.am (sources): Remove debug_list.cc, add
compatibility-debug_list-2.cc.
(parallel_sources): Remove parallel_list.cc, add
compatibility-parallel_list-2.cc.
(compatibility-parallel_list-2.[o,lo]): New rule.
* src/Makefile.in: Regenerate.
* src/debug_list.cc: Remove.
* src/parallel_list.cc: Remove.
* src/compatibility-list-2.cc: New.
* src/compatibility-debug_list-2.cc: New.
* src/compatibility-parallel_list-2.cc: New.
* doc/doxygen/user.cfg.in: Adjust macros.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust line numbers, macros.
* testsuite/20_util/declval/requirements/1_neg.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/forward/c_neg.cc: Same.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Same.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/forward_list/capacity/1.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Same.
* testsuite/23_containers/list/capacity/29134.cc: Same.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/bool/capacity/29134.cc: Same.
* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/25_algorithms/sort/35588.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* testsuite/ext/profile/mutex_extensions_neg.cc: Same.
* testsuite/ext/profile/profiler_algos.cc: Same.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Same.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
From-SVN: r169421
2011-01-30 23:39:36 +01:00
|
|
|
} // namespace
|
2008-09-13 02:32:37 +02:00
|
|
|
|
|
|
|
#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
|
|
|
|
|
2012-11-10 18:27:22 +01:00
|
|
|
#endif // C++11
|
2008-09-13 02:32:37 +02:00
|
|
|
|
|
|
|
#endif // _GLIBCXX_THREAD
|