From f1630545574e2e8bb7e3f9be7f0d8abb4263252f Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Fri, 30 Mar 2012 04:46:47 +0000 Subject: [PATCH] Thread: Added more noexcept [SVN r77640] --- include/boost/thread/detail/config.hpp | 4 ++ include/boost/thread/detail/thread.hpp | 46 +++++++++---------- .../thread/detail/thread_interruption.hpp | 31 ++++++++++--- include/boost/thread/pthread/thread_data.hpp | 11 +++-- include/boost/thread/win32/thread_data.hpp | 6 +-- src/pthread/thread.cpp | 14 +++--- src/win32/thread.cpp | 16 +++---- 7 files changed, 75 insertions(+), 53 deletions(-) diff --git a/include/boost/thread/detail/config.hpp b/include/boost/thread/detail/config.hpp index 6716a217..1bb2ec46 100644 --- a/include/boost/thread/detail/config.hpp +++ b/include/boost/thread/detail/config.hpp @@ -23,6 +23,10 @@ #define BOOST_THREAD_USES_SYSTEM #endif +#if defined __IBMCPP__ +#define BOOST_THREAD_DONT_USE_CHRONO +#endif + #if ! defined BOOST_THREAD_DONT_USE_CHRONO && ! defined BOOST_THREAD_DONT_USE_SYSTEM #define BOOST_THREAD_USES_CHRONO #endif diff --git a/include/boost/thread/detail/thread.hpp b/include/boost/thread/detail/thread.hpp index 58f79a5b..c3b4751d 100644 --- a/include/boost/thread/detail/thread.hpp +++ b/include/boost/thread/detail/thread.hpp @@ -144,7 +144,6 @@ namespace boost class BOOST_THREAD_DECL thread { public: - //typedef int boost_move_emulation_t; typedef thread_attributes attributes; #ifndef BOOST_NO_DELETED_FUNCTIONS @@ -353,14 +352,14 @@ namespace boost } #else #if defined BOOST_THREAD_USES_MOVE - thread& operator=(boost::rv& x) + thread& operator=(boost::rv& x) BOOST_NOEXCEPT { thread new_thread(boost::move(x)); swap(new_thread); return *this; } #else - thread& operator=(detail::thread_move_t x) + thread& operator=(detail::thread_move_t x) BOOST_NOEXCEPT { thread new_thread(x); swap(new_thread); @@ -370,30 +369,30 @@ namespace boost #endif #if defined BOOST_THREAD_USES_MOVE - ::boost::rv& move() + ::boost::rv& move() BOOST_NOEXCEPT { return *static_cast< ::boost::rv* >(this); } - const ::boost::rv& move() const + const ::boost::rv& move() const BOOST_NOEXCEPT { return *static_cast* >(this); } - operator ::boost::rv&() + operator ::boost::rv&() BOOST_NOEXCEPT { return *static_cast< ::boost::rv* >(this); } - operator const ::boost::rv&() const + operator const ::boost::rv&() const BOOST_NOEXCEPT { return *static_cast* >(this); } #else - operator detail::thread_move_t() + operator detail::thread_move_t() BOOST_NOEXCEPT { return move(); } - detail::thread_move_t move() + detail::thread_move_t move() BOOST_NOEXCEPT { detail::thread_move_t x(*this); return x; @@ -476,7 +475,7 @@ namespace boost bool joinable() const BOOST_NOEXCEPT; void join(); #if defined(BOOST_THREAD_PLATFORM_WIN32) - bool timed_join(const system_time& abs_time); + bool timed_join(const system_time& abs_time); // DEPRECATED V2 #ifdef BOOST_THREAD_USES_CHRONO template @@ -504,7 +503,8 @@ namespace boost public: #else - bool timed_join(const system_time& abs_time) { + bool timed_join(const system_time& abs_time) // DEPRECATED V2 + { struct timespec const ts=detail::get_timespec(abs_time); return do_try_join_until(ts); } @@ -547,12 +547,12 @@ namespace boost #endif template - inline bool timed_join(TimeDuration const& rel_time) + inline bool timed_join(TimeDuration const& rel_time) // DEPRECATED V2 { return timed_join(get_system_time()+rel_time); } - void detach(); + void detach() BOOST_NOEXCEPT; static unsigned hardware_concurrency() BOOST_NOEXCEPT; @@ -561,22 +561,22 @@ namespace boost native_handle_type native_handle(); // backwards compatibility - bool operator==(const thread& other) const; - bool operator!=(const thread& other) const; + bool operator==(const thread& other) const; // DEPRECATED V2 + bool operator!=(const thread& other) const; // DEPRECATED V2 static inline void yield() BOOST_NOEXCEPT { this_thread::yield(); } - static inline void sleep(const system_time& xt) + static inline void sleep(const system_time& xt) // DEPRECATED V2 { this_thread::sleep(xt); } // extensions void interrupt(); - bool interruption_requested() const; + bool interruption_requested() const BOOST_NOEXCEPT; }; inline void swap(thread& lhs,thread& rhs) BOOST_NOEXCEPT @@ -585,17 +585,17 @@ namespace boost } #ifndef BOOST_NO_RVALUE_REFERENCES - inline thread&& move(thread& t) + inline thread&& move(thread& t) BOOST_NOEXCEPT { return static_cast(t); } - inline thread&& move(thread&& t) + inline thread&& move(thread&& t) BOOST_NOEXCEPT { return static_cast(t); } #else #if !defined BOOST_THREAD_USES_MOVE - inline detail::thread_move_t move(detail::thread_move_t t) + inline detail::thread_move_t move(detail::thread_move_t t) BOOST_NOEXCEPT { return t; } @@ -616,10 +616,10 @@ namespace boost thread::id BOOST_THREAD_DECL get_id() BOOST_NOEXCEPT; void BOOST_THREAD_DECL interruption_point(); - bool BOOST_THREAD_DECL interruption_enabled(); - bool BOOST_THREAD_DECL interruption_requested(); + bool BOOST_THREAD_DECL interruption_enabled() BOOST_NOEXCEPT; + bool BOOST_THREAD_DECL interruption_requested() BOOST_NOEXCEPT; - inline BOOST_SYMBOL_VISIBLE void sleep(xtime const& abs_time) + inline BOOST_SYMBOL_VISIBLE void sleep(xtime const& abs_time) // DEPRECATED V2 { sleep(system_time(abs_time)); } diff --git a/include/boost/thread/detail/thread_interruption.hpp b/include/boost/thread/detail/thread_interruption.hpp index 60c0e65b..6d655956 100644 --- a/include/boost/thread/detail/thread_interruption.hpp +++ b/include/boost/thread/detail/thread_interruption.hpp @@ -4,6 +4,9 @@ // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // (C) Copyright 2007-9 Anthony Williams +// (C) Copyright 2012 Vicente J. Botet Escriba + +#include namespace boost { @@ -11,23 +14,37 @@ namespace boost { class BOOST_THREAD_DECL disable_interruption { + bool interruption_was_enabled; + friend class restore_interruption; + public: +#ifndef BOOST_NO_DELETED_FUNCTIONS + disable_interruption(const disable_interruption&) = delete; + disable_interruption& operator=(const disable_interruption&) = delete; +#else + private: disable_interruption(const disable_interruption&); disable_interruption& operator=(const disable_interruption&); - - bool interruption_was_enabled; - friend class restore_interruption; public: - disable_interruption(); - ~disable_interruption(); +#endif + disable_interruption() BOOST_NOEXCEPT; + ~disable_interruption() BOOST_NOEXCEPT; }; class BOOST_THREAD_DECL restore_interruption { + public: +#ifndef BOOST_NO_DELETED_FUNCTIONS + restore_interruption(const restore_interruption&) = delete; + restore_interruption& operator=(const restore_interruption&) = delete; +#else + private: restore_interruption(const restore_interruption&); restore_interruption& operator=(const restore_interruption&); public: - explicit restore_interruption(disable_interruption& d); - ~restore_interruption(); +#endif + + explicit restore_interruption(disable_interruption& d) BOOST_NOEXCEPT; + ~restore_interruption() BOOST_NOEXCEPT; }; } } diff --git a/include/boost/thread/pthread/thread_data.hpp b/include/boost/thread/pthread/thread_data.hpp index f17e5b47..3f76b73e 100644 --- a/include/boost/thread/pthread/thread_data.hpp +++ b/include/boost/thread/pthread/thread_data.hpp @@ -25,7 +25,7 @@ namespace boost { class thread_attributes { public: - thread_attributes() { + thread_attributes() BOOST_NOEXCEPT { int res = pthread_attr_init(&val_); BOOST_VERIFY(!res && "pthread_attr_init failed"); } @@ -34,7 +34,7 @@ namespace boost BOOST_VERIFY(!res && "pthread_attr_destroy failed"); } // stack - void set_stack_size(std::size_t size) { + void set_stack_size(std::size_t size) BOOST_NOEXCEPT { if (size==0) return; std::size_t page_size = getpagesize(); #ifdef PTHREAD_STACK_MIN @@ -45,18 +45,19 @@ namespace boost BOOST_VERIFY(!res && "pthread_attr_setstacksize failed"); } - std::size_t get_stack_size() const { + std::size_t get_stack_size() const BOOST_NOEXCEPT { std::size_t size; int res = pthread_attr_getstacksize(&val_, &size); BOOST_VERIFY(!res && "pthread_attr_getstacksize failed"); return size; } +#define BOOST_THREAD_DEFINES_THREAD_ATTRIBUTES_NATIVE_HANDLE typedef pthread_attr_t native_handle_type; - native_handle_type* native_handle() { + native_handle_type* native_handle() BOOST_NOEXCEPT { return &val_; } - const native_handle_type* native_handle() const { + const native_handle_type* native_handle() const BOOST_NOEXCEPT { return &val_; } diff --git a/include/boost/thread/win32/thread_data.hpp b/include/boost/thread/win32/thread_data.hpp index 55d8523b..cc5816f8 100644 --- a/include/boost/thread/win32/thread_data.hpp +++ b/include/boost/thread/win32/thread_data.hpp @@ -19,18 +19,18 @@ namespace boost { class thread_attributes { public: - thread_attributes() { + thread_attributes() BOOST_NOEXCEPT { val_.stack_size = 0; //val_.lpThreadAttributes=0; } ~thread_attributes() { } // stack size - void set_stack_size(std::size_t size) { + void set_stack_size(std::size_t size) BOOST_NOEXCEPT { val_.stack_size = size; } - std::size_t get_stack_size() const { + std::size_t get_stack_size() const BOOST_NOEXCEPT { return val_.stack_size; } diff --git a/src/pthread/thread.cpp b/src/pthread/thread.cpp index 1912b94a..26bcef79 100644 --- a/src/pthread/thread.cpp +++ b/src/pthread/thread.cpp @@ -358,7 +358,7 @@ namespace boost } - void thread::detach() + void thread::detach() BOOST_NOEXCEPT { detail::thread_data_ptr local_thread_info; thread_info.swap(local_thread_info); @@ -560,13 +560,13 @@ namespace boost } } - bool interruption_enabled() + bool interruption_enabled() BOOST_NOEXCEPT { boost::detail::thread_data_base* const thread_info=detail::get_current_thread_data(); return thread_info && thread_info->interrupt_enabled; } - bool interruption_requested() + bool interruption_requested() BOOST_NOEXCEPT { boost::detail::thread_data_base* const thread_info=detail::get_current_thread_data(); if(!thread_info) @@ -580,7 +580,7 @@ namespace boost } } - disable_interruption::disable_interruption(): + disable_interruption::disable_interruption() BOOST_NOEXCEPT: interruption_was_enabled(interruption_enabled()) { if(interruption_was_enabled) @@ -589,7 +589,7 @@ namespace boost } } - disable_interruption::~disable_interruption() + disable_interruption::~disable_interruption() BOOST_NOEXCEPT { if(detail::get_current_thread_data()) { @@ -597,7 +597,7 @@ namespace boost } } - restore_interruption::restore_interruption(disable_interruption& d) + restore_interruption::restore_interruption(disable_interruption& d) BOOST_NOEXCEPT { if(d.interruption_was_enabled) { @@ -605,7 +605,7 @@ namespace boost } } - restore_interruption::~restore_interruption() + restore_interruption::~restore_interruption() BOOST_NOEXCEPT { if(detail::get_current_thread_data()) { diff --git a/src/win32/thread.cpp b/src/win32/thread.cpp index 09ba7316..84de0fbb 100644 --- a/src/win32/thread.cpp +++ b/src/win32/thread.cpp @@ -341,7 +341,7 @@ namespace boost #endif - void thread::detach() + void thread::detach() BOOST_NOEXCEPT { release_handle(); } @@ -360,7 +360,7 @@ namespace boost } } - bool thread::interruption_requested() const + bool thread::interruption_requested() const BOOST_NOEXCEPT { detail::thread_data_ptr local_thread_info=(get_thread_info)(); return local_thread_info.get() && (detail::win32::WaitForSingleObject(local_thread_info->interruption_handle,0)==0); @@ -550,12 +550,12 @@ namespace boost } } - bool interruption_enabled() + bool interruption_enabled() BOOST_NOEXCEPT { return get_current_thread_data() && get_current_thread_data()->interruption_enabled; } - bool interruption_requested() + bool interruption_requested() BOOST_NOEXCEPT { return get_current_thread_data() && (detail::win32::WaitForSingleObject(get_current_thread_data()->interruption_handle,0)==0); } @@ -565,7 +565,7 @@ namespace boost detail::win32::Sleep(0); } - disable_interruption::disable_interruption(): + disable_interruption::disable_interruption() BOOST_NOEXCEPT: interruption_was_enabled(interruption_enabled()) { if(interruption_was_enabled) @@ -574,7 +574,7 @@ namespace boost } } - disable_interruption::~disable_interruption() + disable_interruption::~disable_interruption() BOOST_NOEXCEPT { if(get_current_thread_data()) { @@ -582,7 +582,7 @@ namespace boost } } - restore_interruption::restore_interruption(disable_interruption& d) + restore_interruption::restore_interruption(disable_interruption& d) BOOST_NOEXCEPT { if(d.interruption_was_enabled) { @@ -590,7 +590,7 @@ namespace boost } } - restore_interruption::~restore_interruption() + restore_interruption::~restore_interruption() BOOST_NOEXCEPT { if(get_current_thread_data()) {