Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56950 - sandbox/task/boost/task
From: oliver.kowalke_at_[hidden]
Date: 2009-10-17 06:27:01


Author: olli
Date: 2009-10-17 06:27:00 EDT (Sat, 17 Oct 2009)
New Revision: 56950
URL: http://svn.boost.org/trac/boost/changeset/56950

Log:
- correction related to UMS template argument of static_pool and async

Text files modified:
   sandbox/task/boost/task/async.hpp | 8 +-
   sandbox/task/boost/task/distrib_rr_ums.hpp | 138 ++++++++++++++++++++++++++-------------
   2 files changed, 96 insertions(+), 50 deletions(-)

Modified: sandbox/task/boost/task/async.hpp
==============================================================================
--- sandbox/task/boost/task/async.hpp (original)
+++ sandbox/task/boost/task/async.hpp 2009-10-17 06:27:00 EDT (Sat, 17 Oct 2009)
@@ -28,12 +28,12 @@
 handle< R > async( task< R > t, EP ep)
 { return ep( boost::move( t) ); }
 
-template< typename R, typename Queue >
-handle< R > async( task< R > t, static_pool< Queue > & pool)
+template< typename R, typename Queue, typename UMS >
+handle< R > async( task< R > t, static_pool< Queue, UMS > & pool)
 { return pool.submit( boost::move( t) ); }
 
-template< typename R, typename Queue, typename Attr >
-handle< R > async( task< R > t, Attr attr, static_pool< Queue > & pool)
+template< typename R, typename Attr, typename Queue, typename UMS >
+handle< R > async( task< R > t, Attr attr, static_pool< Queue, UMS > & pool)
 { return pool.submit( boost::move( t), attr); }
 
 }}

Modified: sandbox/task/boost/task/distrib_rr_ums.hpp
==============================================================================
--- sandbox/task/boost/task/distrib_rr_ums.hpp (original)
+++ sandbox/task/boost/task/distrib_rr_ums.hpp 2009-10-17 06:27:00 EDT (Sat, 17 Oct 2009)
@@ -7,6 +7,8 @@
 #ifndef BOOST_TASK_DISTRIB_RR_UMS_H
 #define BOOST_TASK_DISTRIB_RR_UMS_H
 
+#include <list>
+
 #include <boost/assert.hpp>
 #include <boost/cstdint.hpp>
 #include <boost/shared_ptr.hpp>
@@ -23,73 +25,117 @@
 class distrib_rr_ums
 {
 private:
+// class twolock_fifo
+// {
+// struct node
+// {
+// typedef shared_ptr< node > sptr_t;
+//
+// detail::fiber::sptr_t fib;
+// sptr_t next;
+// };
+//
+// node::sptr_t head_;
+// mutex head_mtx_;
+// node::sptr_t tail_;
+// mutex tail_mtx_;
+//
+// bool empty_()
+// { return head_ == get_tail_(); }
+//
+// node::sptr_t get_tail_()
+// {
+// lock_guard< mutex > lk( tail_mtx_);
+// node::sptr_t tmp = tail_;
+// return tmp;
+// }
+//
+// node::sptr_t pop_head_()
+// {
+// node::sptr_t old_head = head_;
+// head_ = old_head->next;
+// return old_head;
+// }
+//
+// public:
+// twolock_fifo() :
+// head_( new node),
+// head_mtx_(),
+// tail_( head_),
+// tail_mtx_()
+// {}
+//
+// bool empty()
+// {
+// unique_lock< mutex > lk( head_mtx_);
+// return empty_();
+// }
+//
+// void put( detail::fiber::sptr_t const& fib)
+// {
+// node::sptr_t new_node( new node);
+// {
+// unique_lock< mutex > lk( tail_mtx_);
+// tail_->fib = fib;
+// tail_->next = new_node;
+// tail_ = new_node;
+// }
+// }
+//
+// bool try_take( detail::fiber::sptr_t & fib)
+// {
+// unique_lock< mutex > lk( head_mtx_);
+// if ( empty_() )
+// return false;
+// fib.swap( head_->fib);
+// pop_head_();
+// return fib;
+// }
+// };
+
         class twolock_fifo
         {
- struct node
- {
- typedef shared_ptr< node > sptr_t;
+ private:
+ mutex mtx_;
+ std::list< detail::fiber::sptr_t > lst_;
 
- detail::fiber::sptr_t fib;
- sptr_t next;
- };
+ bool empty_() const
+ { return lst_.empty(); }
 
- node::sptr_t head_;
- mutex head_mtx_;
- node::sptr_t tail_;
- mutex tail_mtx_;
-
- bool empty_()
- { return head_ == get_tail_(); }
-
- node::sptr_t get_tail_()
- {
- lock_guard< mutex > lk( tail_mtx_);
- node::sptr_t tmp = tail_;
- return tmp;
- }
+ void put_( detail::fiber::sptr_t const& fib)
+ { lst_.push_back( fib); }
 
- node::sptr_t pop_head_()
+ bool try_take_( detail::fiber::sptr_t & fib)
                 {
- node::sptr_t old_head = head_;
- head_ = old_head->next;
- return old_head;
+ if ( empty_() ) return false;
+ fib = lst_.front();
+ lst_.pop_front();
+ return fib;
                 }
 
         public:
                 twolock_fifo() :
- head_( new node),
- head_mtx_(),
- tail_( head_),
- tail_mtx_()
+ mtx_(), lst_()
                 {}
-
+
                 bool empty()
                 {
- unique_lock< mutex > lk( head_mtx_);
+ mutex::scoped_lock lk( mtx_);
                         return empty_();
                 }
-
+
                 void put( detail::fiber::sptr_t const& fib)
                 {
- node::sptr_t new_node( new node);
- {
- unique_lock< mutex > lk( tail_mtx_);
- tail_->fib = fib;
- tail_->next = new_node;
- tail_ = new_node;
- }
+ mutex::scoped_lock lk( mtx_);
+ put_( fib);
                 }
-
+
                 bool try_take( detail::fiber::sptr_t & fib)
                 {
- unique_lock< mutex > lk( head_mtx_);
- if ( empty_() )
- return false;
- fib.swap( head_->fib);
- pop_head_();
- return fib;
+ mutex::scoped_lock lk( mtx_);
+ return try_take_( fib);
                 }
- };
+ };
 
         twolock_fifo runnable_;
         twolock_fifo blocked_;


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