diff options
Diffstat (limited to 'boost/thread/pthread/thread_data.hpp')
-rw-r--r-- | boost/thread/pthread/thread_data.hpp | 119 |
1 files changed, 97 insertions, 22 deletions
diff --git a/boost/thread/pthread/thread_data.hpp b/boost/thread/pthread/thread_data.hpp index 5f84799f85..801f470b46 100644 --- a/boost/thread/pthread/thread_data.hpp +++ b/boost/thread/pthread/thread_data.hpp @@ -8,18 +8,29 @@ #include <boost/thread/detail/config.hpp> #include <boost/thread/exceptions.hpp> +#include <boost/thread/lock_guard.hpp> +#include <boost/thread/lock_types.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/pthread/condition_variable_fwd.hpp> + #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> -#include <boost/thread/mutex.hpp> -#include <boost/optional.hpp> -#include <pthread.h> #include <boost/assert.hpp> -#include <boost/thread/pthread/condition_variable_fwd.hpp> -#include <map> -#include <unistd.h> #ifdef BOOST_THREAD_USES_CHRONO #include <boost/chrono/system_clocks.hpp> #endif + +#include <map> +#include <vector> +#include <utility> + +#if defined(__ANDROID__) +#include <asm/page.h> // http://code.google.com/p/android/issues/detail?id=39983 +#endif + +#include <pthread.h> +#include <unistd.h> + #include <boost/config/abi_prefix.hpp> namespace boost @@ -70,6 +81,7 @@ namespace boost namespace detail { + struct shared_state_base; struct tss_cleanup_function; struct thread_exit_callback_node; struct tss_data_node @@ -100,27 +112,57 @@ namespace boost bool joined; boost::detail::thread_exit_callback_node* thread_exit_callbacks; std::map<void const*,boost::detail::tss_data_node> tss_data; - bool interrupt_enabled; - bool interrupt_requested; + pthread_mutex_t* cond_mutex; pthread_cond_t* current_cond; + typedef std::vector<std::pair<condition_variable*, mutex*> + //, hidden_allocator<std::pair<condition_variable*, mutex*> > + > notify_list_t; + notify_list_t notify; + typedef std::vector<shared_ptr<shared_state_base> > async_states_t; + async_states_t async_states_; + +//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS + // These data must be at the end so that the access to the other fields doesn't change + // when BOOST_THREAD_PROVIDES_INTERRUPTIONS is defined. + // Another option is to have them always + bool interrupt_enabled; + bool interrupt_requested; +//#endif thread_data_base(): + thread_handle(0), done(false),join_started(false),joined(false), thread_exit_callbacks(0), - interrupt_enabled(true), - interrupt_requested(false), - current_cond(0) + cond_mutex(0), + current_cond(0), + notify(), + async_states_() +//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS + , interrupt_enabled(true) + , interrupt_requested(false) +//#endif {} virtual ~thread_data_base(); typedef pthread_t native_handle_type; virtual void run()=0; + virtual void notify_all_at_thread_exit(condition_variable* cv, mutex* m) + { + notify.push_back(std::pair<condition_variable*, mutex*>(cv, m)); + } + + void make_ready_at_thread_exit(shared_ptr<shared_state_base> as) + { + async_states_.push_back(as); + } + }; BOOST_THREAD_DECL thread_data_base* get_current_thread_data(); +#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS class interruption_checker { thread_data_base* const thread_info; @@ -172,35 +214,68 @@ namespace boost } } }; +#endif } namespace this_thread { + namespace hiden + { + void BOOST_THREAD_DECL sleep_for(const timespec& ts); + void BOOST_THREAD_DECL sleep_until(const timespec& ts); + } + #ifdef BOOST_THREAD_USES_CHRONO - void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns); +#ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY + + inline + void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns) + { + return boost::this_thread::hiden::sleep_for(boost::detail::to_timespec(ns)); + } #endif +#endif // BOOST_THREAD_USES_CHRONO + + namespace no_interruption_point + { + namespace hiden + { + void BOOST_THREAD_DECL sleep_for(const timespec& ts); + void BOOST_THREAD_DECL sleep_until(const timespec& ts); + } + + #ifdef BOOST_THREAD_USES_CHRONO + #ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY + + inline + void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns) + { + return boost::this_thread::hiden::sleep_for(boost::detail::to_timespec(ns)); + } + #endif + #endif // BOOST_THREAD_USES_CHRONO + + } // no_interruption_point + void BOOST_THREAD_DECL yield() BOOST_NOEXCEPT; +#if defined BOOST_THREAD_USES_DATETIME #ifdef __DECXXX /// Workaround of DECCXX issue of incorrect template substitution - template<typename TimeDuration> - inline void sleep(TimeDuration const& rel_time) + template<> +#endif + inline void sleep(system_time const& abs_time) { - this_thread::sleep(get_system_time()+rel_time); + return boost::this_thread::hiden::sleep_until(boost::detail::to_timespec(abs_time)); } - template<> - void BOOST_THREAD_DECL sleep(system_time const& abs_time); -#else - void BOOST_THREAD_DECL sleep(system_time const& abs_time); - template<typename TimeDuration> inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time) { this_thread::sleep(get_system_time()+rel_time); } -#endif - } +#endif // BOOST_THREAD_USES_DATETIME + } // this_thread } #include <boost/config/abi_suffix.hpp> |