Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85732 - in trunk: boost/thread boost/thread/detail libs/thread/src/pthread libs/thread/src/win32
From: vicente.botet_at_[hidden]
Date: 2013-09-17 16:57:46


Author: viboes
Date: 2013-09-17 16:57:46 EDT (Tue, 17 Sep 2013)
New Revision: 85732
URL: http://svn.boost.org/trac/boost/changeset/85732

Log:
Thread: refactor make_ready_at_thread_exit + inhibit at_thread_exit functions from external threads.

Text files modified:
   trunk/boost/thread/detail/thread.hpp | 13 +++++++++++++
   trunk/boost/thread/future.hpp | 13 +++++++------
   trunk/libs/thread/src/pthread/thread.cpp | 37 +++++++++++++++++++++++++++++--------
   trunk/libs/thread/src/win32/thread.cpp | 11 +++++++++++
   4 files changed, 60 insertions(+), 14 deletions(-)

Modified: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- trunk/boost/thread/detail/thread.hpp Tue Sep 17 16:37:20 2013 (r85731)
+++ trunk/boost/thread/detail/thread.hpp 2013-09-17 16:57:46 EDT (Tue, 17 Sep 2013) (r85732)
@@ -826,6 +826,19 @@
         };
 
         void BOOST_THREAD_DECL add_thread_exit_function(thread_exit_function_base*);
+ struct shared_state_base;
+#if defined(BOOST_THREAD_PLATFORM_WIN32)
+ inline void make_ready_at_thread_exit(shared_ptr<shared_state_base> as)
+ {
+ detail::thread_data_base* const current_thread_data(detail::get_current_thread_data());
+ if(current_thread_data)
+ {
+ current_thread_data->make_ready_at_thread_exit(as);
+ }
+ }
+#else
+ void BOOST_THREAD_DECL make_ready_at_thread_exit(shared_ptr<shared_state_base> as);
+#endif
     }
 
     namespace this_thread

Modified: trunk/boost/thread/future.hpp
==============================================================================
--- trunk/boost/thread/future.hpp Tue Sep 17 16:37:20 2013 (r85731)
+++ trunk/boost/thread/future.hpp 2013-09-17 16:57:46 EDT (Tue, 17 Sep 2013) (r85732)
@@ -418,7 +418,7 @@
               {
                   throw_exception(promise_already_satisfied());
               }
- get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
+ detail::make_ready_at_thread_exit(shared_from_this());
             }
 #endif
 
@@ -431,7 +431,8 @@
               }
               exception=e;
               this->is_constructed = true;
- get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
+ detail::make_ready_at_thread_exit(shared_from_this());
+
             }
 
             bool has_value() const
@@ -688,7 +689,7 @@
               result.reset(new T(result_));
 
               this->is_constructed = true;
- get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
+ detail::make_ready_at_thread_exit(shared_from_this());
             }
             //void set_value_at_thread_exit(BOOST_THREAD_RV_REF(T) result_)
             void set_value_at_thread_exit(rvalue_source_type result_)
@@ -699,7 +700,7 @@
               result.reset(new T(boost::move(result_)));
               //future_traits<T>::init(result,static_cast<rvalue_source_type>(result_));
               this->is_constructed = true;
- get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
+ detail::make_ready_at_thread_exit(shared_from_this());
             }
 
 
@@ -760,7 +761,7 @@
               //future_traits<T>::init(result,result_);
               result= &result_;
               this->is_constructed = true;
- get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
+ detail::make_ready_at_thread_exit(shared_from_this());
             }
 
         private:
@@ -806,7 +807,7 @@
                   throw_exception(promise_already_satisfied());
               }
               this->is_constructed = true;
- get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
+ detail::make_ready_at_thread_exit(shared_from_this());
             }
         private:
             shared_state(shared_state const&);

Modified: trunk/libs/thread/src/pthread/thread.cpp
==============================================================================
--- trunk/libs/thread/src/pthread/thread.cpp Tue Sep 17 16:37:20 2013 (r85731)
+++ trunk/libs/thread/src/pthread/thread.cpp 2013-09-17 16:57:46 EDT (Tue, 17 Sep 2013) (r85732)
@@ -187,7 +187,9 @@
                 return 0;
             }
         }
-
+ }
+ namespace detail
+ {
         struct externally_launched_thread:
             detail::thread_data_base
         {
@@ -197,7 +199,12 @@
                 interrupt_enabled=false;
 #endif
             }
-
+ ~externally_launched_thread() {
+ BOOST_ASSERT(notify.empty());
+ notify.clear();
+ BOOST_ASSERT(async_states_.empty());
+ async_states_.clear();
+ }
             void run()
             {}
             void notify_all_at_thread_exit(condition_variable*, mutex*)
@@ -208,18 +215,18 @@
             void operator=(externally_launched_thread&);
         };
 
- detail::thread_data_base* make_external_thread_data()
+ thread_data_base* make_external_thread_data()
         {
- detail::thread_data_base* const me(new externally_launched_thread());
+ thread_data_base* const me(new externally_launched_thread());
             me->self.reset(me);
             set_current_thread_data(me);
             return me;
         }
 
 
- detail::thread_data_base* get_or_make_current_thread_data()
+ thread_data_base* get_or_make_current_thread_data()
         {
- detail::thread_data_base* current_thread_data(detail::get_current_thread_data());
+ thread_data_base* current_thread_data(get_current_thread_data());
             if(!current_thread_data)
             {
                 current_thread_data=make_external_thread_data();
@@ -701,8 +708,11 @@
 
         void erase_tss_node(void const* key)
         {
- detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
- current_thread_data->tss_data.erase(key);
+ detail::thread_data_base* const current_thread_data(get_current_thread_data());
+ if(current_thread_data)
+ {
+ current_thread_data->tss_data.erase(key);
+ }
         }
 
         void set_tss_data(void const* key,
@@ -740,6 +750,17 @@
         current_thread_data->notify_all_at_thread_exit(&cond, lk.release());
       }
     }
+namespace detail {
+
+ void BOOST_THREAD_DECL make_ready_at_thread_exit(shared_ptr<shared_state_base> as)
+ {
+ detail::thread_data_base* const current_thread_data(detail::get_current_thread_data());
+ if(current_thread_data)
+ {
+ current_thread_data->make_ready_at_thread_exit(as);
+ }
+ }
+}
 
 
 

Modified: trunk/libs/thread/src/win32/thread.cpp
==============================================================================
--- trunk/libs/thread/src/win32/thread.cpp Tue Sep 17 16:37:20 2013 (r85731)
+++ trunk/libs/thread/src/win32/thread.cpp 2013-09-17 16:57:46 EDT (Tue, 17 Sep 2013) (r85732)
@@ -754,5 +754,16 @@
         current_thread_data->notify_all_at_thread_exit(&cond, lk.release());
       }
     }
+//namespace detail {
+//
+// void BOOST_THREAD_DECL make_ready_at_thread_exit(shared_ptr<shared_state_base> as)
+// {
+// detail::thread_data_base* const current_thread_data(detail::get_current_thread_data());
+// if(current_thread_data)
+// {
+// current_thread_data->make_ready_at_thread_exit(as);
+// }
+// }
+//}
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk