// <thread> -*- C++ -*-
-// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2008, 2009, 2010, 2011 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
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
-/** @file thread
+/** @file include/thread
* This is a Standard C++ Library header.
*/
#include <memory>
#include <mutex>
#include <condition_variable>
-#include <cstddef>
#include <bits/functexcept.h>
+#include <bits/functional_hash.h>
#include <bits/gthr.h>
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
-namespace std
+namespace std _GLIBCXX_VISIBILITY(default)
{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
/**
* @defgroup threads Threads
* @ingroup concurrency
private:
friend class thread;
+ friend class hash<thread::id>;
friend bool
operator==(thread::id __x, thread::id __y)
{
__shared_base_type _M_this_ptr;
- inline virtual ~_Impl_base();
+ virtual ~_Impl_base();
virtual void _M_run() = 0;
};
public:
thread() = default;
+ thread(thread&) = delete;
thread(const thread&) = delete;
thread(thread&& __t)
{ swap(__t); }
- template<typename _Callable>
- explicit thread(_Callable __f)
- {
- _M_start_thread(_M_make_routine<_Callable>
- (std::forward<_Callable>(__f)));
- }
-
template<typename _Callable, typename... _Args>
+ explicit
thread(_Callable&& __f, _Args&&... __args)
- { _M_start_thread(_M_make_routine(std::bind(__f, __args...))); }
+ {
+ _M_start_thread(_M_make_routine(std::bind<void>(
+ std::forward<_Callable>(__f),
+ std::forward<_Args>(__args)...)));
+ }
~thread()
{
}
};
- inline thread::_Impl_base::~_Impl_base() = default;
-
inline void
swap(thread& __x, thread& __y)
{ __x.swap(__y); }
operator>=(thread::id __x, thread::id __y)
{ return !(__x < __y); }
+ // DR 889.
+ /// std::hash specialization for thread::id.
+ template<>
+ struct hash<thread::id>
+ : public __hash_base<size_t, thread::id>
+ {
+ size_t
+ operator()(const thread::id& __id) const
+ { return std::_Hash_impl::hash(__id._M_thread); }
+ };
+
template<class _CharT, class _Traits>
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id)
return __out << __id._M_thread;
}
+_GLIBCXX_END_NAMESPACE_VERSION
+
/** @namespace std::this_thread
* @brief ISO C++ 0x entities sub namespace for thread.
* 30.2.2 Namespace this_thread.
*/
namespace this_thread
{
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+
/// get_id
inline thread::id
get_id() { return thread::id(__gthread_self()); }
::nanosleep(&__ts, 0);
}
#endif
+
+ _GLIBCXX_END_NAMESPACE_VERSION
}
// @} group threads
-}
+
+} // namespace
#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1