Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55662 - in sandbox/task/boost/task: . detail
From: oliver.kowalke_at_[hidden]
Date: 2009-08-19 04:54:34


Author: olli
Date: 2009-08-19 04:54:33 EDT (Wed, 19 Aug 2009)
New Revision: 55662
URL: http://svn.boost.org/trac/boost/changeset/55662

Log:
- user-mode-scheduler local_rr_ums intriduced
- static_pool with second template argument == UMS

Text files modified:
   sandbox/task/boost/task/detail/pool_base.hpp | 10 ++++++--
   sandbox/task/boost/task/detail/worker.hpp | 42 ++++++++++++++++++++--------------------
   sandbox/task/boost/task/static_pool.hpp | 31 +++++++++++++++--------------
   3 files changed, 44 insertions(+), 39 deletions(-)

Modified: sandbox/task/boost/task/detail/pool_base.hpp
==============================================================================
--- sandbox/task/boost/task/detail/pool_base.hpp (original)
+++ sandbox/task/boost/task/detail/pool_base.hpp 2009-08-19 04:54:33 EDT (Wed, 19 Aug 2009)
@@ -39,18 +39,19 @@
 namespace detail
 {
 
-template< typename Channel >
+template< typename Channel, typename UMS >
 class pool_base
 {
 private:
         friend class worker;
 
- template< typename T, typename X >
+ template< typename T, typename X, typename Z >
         friend class worker_object;
 
         typedef Channel channel;
         typedef typename channel::item channel_item;
-
+
+ UMS ums_;
         worker_group wg_;
         shared_mutex mtx_wg_;
         volatile uint32_t state_;
@@ -78,6 +79,7 @@
                 wg_.insert(
                         worker(
                                 * this,
+ ums_,
                                 psize,
                                 asleep,
                                 max_scns,
@@ -104,6 +106,7 @@
                 wg_.insert(
                         worker(
                                 * this,
+ ums_,
                                 psize,
                                 asleep,
                                 max_scns,
@@ -137,6 +140,7 @@
                 scanns const& max_scns,
                 stacksize const& stack_size)
         :
+ ums_(),
         wg_(),
         mtx_wg_(),
         state_( 0),

Modified: sandbox/task/boost/task/detail/worker.hpp
==============================================================================
--- sandbox/task/boost/task/detail/worker.hpp (original)
+++ sandbox/task/boost/task/detail/worker.hpp 2009-08-19 04:54:33 EDT (Wed, 19 Aug 2009)
@@ -68,6 +68,7 @@
 
 template<
         typename Pool,
+ typename UMS,
         typename Worker
>
 class worker_object : public worker_base,
@@ -96,11 +97,10 @@
         typedef shared_ptr< thread > thread_t;
 
         Pool & pool_;
+ UMS & ums_;
         thread_t thrd_;
         fiber::sptr_t fib_;
         wsq wsq_;
- std::list< fiber::sptr_t > blocked_fibers_;
- std::list< fiber::sptr_t > runnable_fibers_;
         semaphore shtdwn_sem_;
         semaphore shtdwn_now_sem_;
         bool shtdwn_;
@@ -124,12 +124,13 @@
 
         void try_blocked_fibers_()
         {
- if ( ! blocked_fibers_.empty() )
+ if ( ums_.has_blocked() )
                 {
                         fiber::sptr_t this_fib = fib_;
- runnable_fibers_.push_back( this_fib);
- fiber::sptr_t blocked_fib = blocked_fibers_.front();
- blocked_fibers_.pop_front();
+ ums_.put_runnable( this_fib);
+ fiber::sptr_t blocked_fib;
+ ums_.try_take_blocked( blocked_fib);
+ BOOST_ASSERT( blocked_fib);
                         fib_ = blocked_fib;
                         this_fib->switch_to( blocked_fib);
                         fib_ = this_fib;
@@ -183,7 +184,7 @@
                                         if ( take_global_callable_( ca, asleep_) )
                                                 execute_( ca);
                                 }
- else if ( blocked_fibers_.empty() )
+ else if ( ! ums_.has_blocked() )
                                 {
                                         try
                                         { this_thread::sleep( asleep_); }
@@ -206,7 +207,7 @@
 
         bool shutdown_()
         {
- if ( shutdown__() && pool_.channel_.empty() && blocked_fibers_.empty() )
+ if ( shutdown__() && pool_.channel_.empty() && ! ums_.has_blocked() )
                         return true;
                 else if ( shutdown_now__() )
                         return true;
@@ -226,6 +227,7 @@
 public:
         worker_object(
                 Pool & pool,
+ UMS & ums,
                 poolsize const& psize,
                 posix_time::time_duration const& asleep,
                 scanns const& max_scns,
@@ -233,11 +235,10 @@
                 function< void() > const& fn)
         :
         pool_( pool),
+ ums_( ums),
         thrd_( new thread( fn) ),
         fib_(),
         wsq_(),
- blocked_fibers_(),
- runnable_fibers_(),
         shtdwn_sem_( 0),
         shtdwn_now_sem_( 0),
         shtdwn_( false),
@@ -279,6 +280,8 @@
 
                 fiber::convert_thread_to_fiber();
 
+ ums_.attach();
+
                 fiber::sptr_t fib(
                         fiber::create(
                                 bind( & worker_object::run_, this),
@@ -297,19 +300,14 @@
         void block()
         {
                 fiber::sptr_t this_fib = fib_;
- blocked_fibers_.push_back( this_fib);
+ ums_.put_blocked( this_fib);
                 fiber::sptr_t runnable_fib;
- if ( runnable_fibers_.empty() )
- {
+ if ( ums_.has_runnable() )
+ ums_.try_take_runnable( runnable_fib);
+ else
                         runnable_fib = fiber::create(
                                         bind( & worker_object::run_, this),
                                         stack_size_);
- }
- else
- {
- runnable_fib = runnable_fibers_.front();
- runnable_fibers_.pop_front();
- }
                 BOOST_ASSERT( runnable_fib);
                 fib_ = runnable_fib;
                 this_fib->switch_to( runnable_fib);
@@ -325,9 +323,10 @@
         shared_ptr< worker_base > impl_;
 
 public:
- template< typename Pool >
+ template< typename Pool, typename UMS >
         worker(
                 Pool & pool,
+ UMS & ums,
                 poolsize const& psize,
                 posix_time::time_duration const& asleep,
                 scanns const& max_scns,
@@ -335,8 +334,9 @@
                 function< void() > const& fn)
         :
         impl_(
- new worker_object< Pool, worker >(
+ new worker_object< Pool, UMS, worker >(
                         pool,
+ ums,
                         psize,
                         asleep,
                         max_scns,

Modified: sandbox/task/boost/task/static_pool.hpp
==============================================================================
--- sandbox/task/boost/task/static_pool.hpp (original)
+++ sandbox/task/boost/task/static_pool.hpp 2009-08-19 04:54:33 EDT (Wed, 19 Aug 2009)
@@ -19,6 +19,7 @@
 #include <boost/task/detail/worker_group.hpp>
 #include <boost/task/exceptions.hpp>
 #include <boost/task/handle.hpp>
+#include <boost/task/local_rr_ums.hpp>
 #include <boost/task/poolsize.hpp>
 #include <boost/task/scanns.hpp>
 #include <boost/task/stacksize.hpp>
@@ -29,21 +30,21 @@
 
 namespace boost { namespace task
 {
-template< typename Channel >
+template< typename Channel, typename UMS = local_rr_ums >
 class static_pool
 {
 public:
         typedef Channel channel;
 
 private:
- template< typename T, typename X >
+ template< typename T, typename X, typename Z >
         friend class detail::worker_object;
 
 # if defined(BOOST_HAS_PROCESSOR_BINDINGS)
         struct tag_bind_to_processors {};
 # endif
         
- shared_ptr< detail::pool_base< Channel > > pool_;
+ shared_ptr< detail::pool_base< Channel, UMS > > pool_;
 
         static_pool( static_pool &);
         static_pool & operator=( static_pool &);
@@ -58,7 +59,7 @@
                 posix_time::time_duration const& asleep = posix_time::microseconds( 10),
                 scanns const& max_scns = scanns( 20),
                 stacksize const& stack_size = stacksize( 64000) )
- : pool_( new detail::pool_base< Channel >( psize, asleep, max_scns, stack_size) )
+ : pool_( new detail::pool_base< Channel, UMS >( psize, asleep, max_scns, stack_size) )
         {}
 
         explicit static_pool(
@@ -68,7 +69,7 @@
                 posix_time::time_duration const& asleep = posix_time::microseconds( 100),
                 scanns const& max_scns = scanns( 20),
                 stacksize const& stack_size = stacksize( 64000) )
- : pool_( new detail::pool_base< Channel >( psize, hwm, lwm, asleep, max_scns, stack_size) )
+ : pool_( new detail::pool_base< Channel, UMS >( psize, hwm, lwm, asleep, max_scns, stack_size) )
         {}
 
 # if defined(BOOST_HAS_PROCESSOR_BINDINGS)
@@ -77,7 +78,7 @@
                 posix_time::time_duration const& asleep = posix_time::microseconds( 10),
                 scanns const& max_scns = scanns( 20),
                 stacksize const& stack_size = stacksize( 64000) )
- : pool_( new detail::pool_base< Channel >( asleep, max_scns, stack_size) )
+ : pool_( new detail::pool_base< Channel, UMS >( asleep, max_scns, stack_size) )
         {}
 
         explicit static_pool(
@@ -87,7 +88,7 @@
                 posix_time::time_duration const& asleep = posix_time::microseconds( 100),
                 scanns const& max_scns = scanns( 20),
                 stacksize const& stack_size = stacksize( 64000) )
- : pool_( new detail::pool_base< Channel >( hwm, lwm, asleep, max_scns, stack_size) )
+ : pool_( new detail::pool_base< Channel, UMS >( hwm, lwm, asleep, max_scns, stack_size) )
         {}
 
         static tag_bind_to_processors bind_to_processors()
@@ -244,7 +245,7 @@
                 return pool_->submit( boost::move( t), attr);
         }
 
- typedef typename shared_ptr< detail::pool_base< Channel > >::unspecified_bool_type unspecified_bool_type;
+ typedef typename shared_ptr< detail::pool_base< Channel, UMS > >::unspecified_bool_type unspecified_bool_type;
 
         operator unspecified_bool_type() const // throw()
         { return pool_; }
@@ -257,18 +258,18 @@
 };
 }
 
-template< typename Channel >
-void swap( task::static_pool< Channel > & l, task::static_pool< Channel > & r)
+template< typename Channel, typename UMS >
+void swap( task::static_pool< Channel, UMS > & l, task::static_pool< Channel, UMS > & r)
 { return l.swap( r); }
 
 # if defined(BOOST_HAS_RVALUE_REFS)
-template< typename Channel >
-task::static_pool< Channel > && move( task::static_pool< Channel > && t)
+template< typename Channel, typename UMS >
+task::static_pool< Channel, UMS > && move( task::static_pool< Channel, UMS > && t)
 { return t; }
 # else
-template< typename Channel >
-task::static_pool< Channel > move( boost::detail::thread_move_t< task::static_pool< Channel > > t)
-{ return task::static_pool< Channel >( t); }
+template< typename Channel, typename UMS >
+task::static_pool< Channel, UMS > move( boost::detail::thread_move_t< task::static_pool< Channel, UMS > > t)
+{ return task::static_pool< Channel, UMS >( t); }
 # endif
 
 }


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