comparison DEPENDENCIES/generic/include/boost/thread/detail/thread.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
2 #define BOOST_THREAD_THREAD_COMMON_HPP 2 #define BOOST_THREAD_THREAD_COMMON_HPP
3 // Distributed under the Boost Software License, Version 1.0. (See 3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at 4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt) 5 // http://www.boost.org/LICENSE_1_0.txt)
6 // (C) Copyright 2007-2010 Anthony Williams 6 // (C) Copyright 2007-2010 Anthony Williams
7 // (C) Copyright 20011-2012 Vicente J. Botet Escriba 7 // (C) Copyright 2011-2012 Vicente J. Botet Escriba
8 8
9 #include <boost/thread/detail/config.hpp> 9 #include <boost/thread/detail/config.hpp>
10 #include <boost/predef/platform.h>
10 11
11 #include <boost/thread/exceptions.hpp> 12 #include <boost/thread/exceptions.hpp>
12 #ifndef BOOST_NO_IOSTREAM 13 #ifndef BOOST_NO_IOSTREAM
13 #include <ostream> 14 #include <ostream>
14 #endif 15 #endif
22 #include <boost/thread/detail/invoke.hpp> 23 #include <boost/thread/detail/invoke.hpp>
23 #include <boost/thread/detail/is_convertible.hpp> 24 #include <boost/thread/detail/is_convertible.hpp>
24 #include <boost/assert.hpp> 25 #include <boost/assert.hpp>
25 #include <list> 26 #include <list>
26 #include <algorithm> 27 #include <algorithm>
27 #include <boost/ref.hpp> 28 #include <boost/core/ref.hpp>
28 #include <boost/cstdint.hpp> 29 #include <boost/cstdint.hpp>
29 #include <boost/bind.hpp> 30 #include <boost/bind.hpp>
30 #include <stdlib.h> 31 #include <stdlib.h>
31 #include <memory> 32 #include <memory>
32 #include <boost/utility/enable_if.hpp> 33 #include <boost/core/enable_if.hpp>
33 #include <boost/type_traits/remove_reference.hpp> 34 #include <boost/type_traits/remove_reference.hpp>
34 #include <boost/io/ios_state.hpp> 35 #include <boost/io/ios_state.hpp>
35 #include <boost/type_traits/is_same.hpp> 36 #include <boost/type_traits/is_same.hpp>
36 #include <boost/type_traits/decay.hpp> 37 #include <boost/type_traits/decay.hpp>
37 #include <boost/functional/hash.hpp> 38 #include <boost/functional/hash.hpp>
62 class thread_data: 63 class thread_data:
63 public detail::thread_data_base 64 public detail::thread_data_base
64 { 65 {
65 public: 66 public:
66 BOOST_THREAD_NO_COPYABLE(thread_data) 67 BOOST_THREAD_NO_COPYABLE(thread_data)
67 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
68 thread_data(BOOST_THREAD_RV_REF(F) f_, BOOST_THREAD_RV_REF(ArgTypes)... args_): 68 thread_data(BOOST_THREAD_RV_REF(F) f_, BOOST_THREAD_RV_REF(ArgTypes)... args_):
69 fp(boost::forward<F>(f_), boost::forward<ArgTypes>(args_)...) 69 fp(boost::forward<F>(f_), boost::forward<ArgTypes>(args_)...)
70 {} 70 {}
71 #endif
72 template <std::size_t ...Indices> 71 template <std::size_t ...Indices>
73 void run2(tuple_indices<Indices...>) 72 void run2(tuple_indices<Indices...>)
74 { 73 {
75 74
76 invoke(std::move(std::get<0>(fp)), std::move(std::get<Indices>(fp))...); 75 invoke(std::move(std::get<0>(fp)), std::move(std::get<Indices>(fp))...);
172 detail::thread_data_ptr thread_info; 171 detail::thread_data_ptr thread_info;
173 172
174 private: 173 private:
175 bool start_thread_noexcept(); 174 bool start_thread_noexcept();
176 bool start_thread_noexcept(const attributes& attr); 175 bool start_thread_noexcept(const attributes& attr);
177 public: 176 //public:
178 void start_thread() 177 void start_thread()
179 { 178 {
180 if (!start_thread_noexcept()) 179 if (!start_thread_noexcept())
181 { 180 {
182 boost::throw_exception(thread_resource_error()); 181 boost::throw_exception(thread_resource_error());
291 } 290 }
292 #else 291 #else
293 template <class F> 292 template <class F>
294 explicit thread(F f 293 explicit thread(F f
295 , typename disable_if_c< 294 , typename disable_if_c<
296 boost::thread_detail::is_convertible<F&,BOOST_THREAD_RV_REF(F)>::value 295 boost::thread_detail::is_rv<F>::value // todo ass a thread_detail::is_rv
296 //boost::thread_detail::is_convertible<F&,BOOST_THREAD_RV_REF(F)>::value
297 //|| is_same<typename decay<F>::type, thread>::value 297 //|| is_same<typename decay<F>::type, thread>::value
298 , dummy* >::type=0 298 , dummy* >::type=0
299 ): 299 ):
300 thread_info(make_thread_info(f)) 300 thread_info(make_thread_info(f))
301 { 301 {
302 start_thread(); 302 start_thread();
303 } 303 }
304 template <class F> 304 template <class F>
305 thread(attributes const& attrs, F f 305 thread(attributes const& attrs, F f
306 , typename disable_if<boost::thread_detail::is_convertible<F&,BOOST_THREAD_RV_REF(F) >, dummy* >::type=0 306 , typename disable_if<boost::thread_detail::is_rv<F>, dummy* >::type=0
307 //, typename disable_if<boost::thread_detail::is_convertible<F&,BOOST_THREAD_RV_REF(F) >, dummy* >::type=0
307 ): 308 ):
308 thread_info(make_thread_info(f)) 309 thread_info(make_thread_info(f))
309 { 310 {
310 start_thread(attrs); 311 start_thread(attrs);
311 } 312 }
332 #endif 333 #endif
333 { 334 {
334 start_thread(attrs); 335 start_thread(attrs);
335 } 336 }
336 #endif 337 #endif
337 thread(BOOST_THREAD_RV_REF(thread) x) 338 thread(BOOST_THREAD_RV_REF(thread) x) BOOST_NOEXCEPT
338 { 339 {
339 thread_info=BOOST_THREAD_RV(x).thread_info; 340 thread_info=BOOST_THREAD_RV(x).thread_info;
340 BOOST_THREAD_RV(x).thread_info.reset(); 341 BOOST_THREAD_RV(x).thread_info.reset();
341 } 342 }
342 #if 0 // This should not be needed anymore. Use instead BOOST_THREAD_MAKE_RV_REF. 343 #if 0 // This should not be needed anymore. Use instead BOOST_THREAD_MAKE_RV_REF.
464 bool join_noexcept(); 465 bool join_noexcept();
465 public: 466 public:
466 inline void join(); 467 inline void join();
467 468
468 #ifdef BOOST_THREAD_USES_CHRONO 469 #ifdef BOOST_THREAD_USES_CHRONO
470 #if defined(BOOST_THREAD_PLATFORM_WIN32)
469 template <class Rep, class Period> 471 template <class Rep, class Period>
470 bool try_join_for(const chrono::duration<Rep, Period>& rel_time) 472 bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
471 { 473 {
474 chrono::milliseconds rel_time2= chrono::ceil<chrono::milliseconds>(rel_time);
475 return do_try_join_until(rel_time2.count());
476 }
477 #else
478 template <class Rep, class Period>
479 bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
480 {
472 return try_join_until(chrono::steady_clock::now() + rel_time); 481 return try_join_until(chrono::steady_clock::now() + rel_time);
473 } 482 }
483 #endif
474 template <class Clock, class Duration> 484 template <class Clock, class Duration>
475 bool try_join_until(const chrono::time_point<Clock, Duration>& t) 485 bool try_join_until(const chrono::time_point<Clock, Duration>& t)
476 { 486 {
477 using namespace chrono; 487 using namespace chrono;
478 system_clock::time_point s_now = system_clock::now(); 488 system_clock::time_point s_now = system_clock::now();
544 } 554 }
545 #endif 555 #endif
546 void detach(); 556 void detach();
547 557
548 static unsigned hardware_concurrency() BOOST_NOEXCEPT; 558 static unsigned hardware_concurrency() BOOST_NOEXCEPT;
559 static unsigned physical_concurrency() BOOST_NOEXCEPT;
549 560
550 #define BOOST_THREAD_DEFINES_THREAD_NATIVE_HANDLE 561 #define BOOST_THREAD_DEFINES_THREAD_NATIVE_HANDLE
551 typedef detail::thread_data_base::native_handle_type native_handle_type; 562 typedef detail::thread_data_base::native_handle_type native_handle_type;
552 native_handle_type native_handle(); 563 native_handle_type native_handle();
553 564
747 } 758 }
748 } 759 }
749 #endif 760 #endif
750 void thread::join() { 761 void thread::join() {
751 if (this_thread::get_id() == get_id()) 762 if (this_thread::get_id() == get_id())
752 boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself")); 763 boost::throw_exception(thread_resource_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost thread: trying joining itself"));
753 764
754 BOOST_THREAD_VERIFY_PRECONDITION( join_noexcept(), 765 BOOST_THREAD_VERIFY_PRECONDITION( join_noexcept(),
755 thread_resource_error(system::errc::invalid_argument, "boost thread: thread not joinable") 766 thread_resource_error(static_cast<int>(system::errc::invalid_argument), "boost thread: thread not joinable")
756 ); 767 );
757 } 768 }
758 769
759 #ifdef BOOST_THREAD_PLATFORM_PTHREAD 770 #ifdef BOOST_THREAD_PLATFORM_PTHREAD
760 bool thread::do_try_join_until(struct timespec const &timeout) 771 bool thread::do_try_join_until(struct timespec const &timeout)
761 #else 772 #else
762 bool thread::do_try_join_until(uintmax_t timeout) 773 bool thread::do_try_join_until(uintmax_t timeout)
763 #endif 774 #endif
764 { 775 {
765 if (this_thread::get_id() == get_id()) 776 if (this_thread::get_id() == get_id())
766 boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself")); 777 boost::throw_exception(thread_resource_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost thread: trying joining itself"));
767 bool res; 778 bool res;
768 if (do_try_join_until_noexcept(timeout, res)) 779 if (do_try_join_until_noexcept(timeout, res))
769 { 780 {
770 return res; 781 return res;
771 } 782 }
772 else 783 else
773 { 784 {
774 BOOST_THREAD_THROW_ELSE_RETURN( 785 BOOST_THREAD_THROW_ELSE_RETURN(
775 (thread_resource_error(system::errc::invalid_argument, "boost thread: thread not joinable")), 786 (thread_resource_error(static_cast<int>(system::errc::invalid_argument), "boost thread: thread not joinable")),
776 false 787 false
777 ); 788 );
778 } 789 }
779 } 790 }
780 791