Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58838 - in sandbox/task/libs/task/src: . detail spin
From: oliver.kowalke_at_[hidden]
Date: 2010-01-09 10:06:08


Author: olli
Date: 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
New Revision: 58838
URL: http://svn.boost.org/trac/boost/changeset/58838

Log:
update

Added:
   sandbox/task/libs/task/src/detail/
   sandbox/task/libs/task/src/detail/guard.cpp (contents, props changed)
   sandbox/task/libs/task/src/detail/worker.cpp (contents, props changed)
   sandbox/task/libs/task/src/detail/worker_group.cpp (contents, props changed)
   sandbox/task/libs/task/src/detail/wsq.cpp (contents, props changed)
Removed:
   sandbox/task/libs/task/src/guard.cpp
   sandbox/task/libs/task/src/worker.cpp
   sandbox/task/libs/task/src/worker_group.cpp
   sandbox/task/libs/task/src/wsq.cpp
Text files modified:
   sandbox/task/libs/task/src/spin/auto_reset_event.cpp | 6 +++---
   sandbox/task/libs/task/src/spin/count_down_event.cpp | 6 +++---
   sandbox/task/libs/task/src/spin/manual_reset_event.cpp | 6 +++---
   sandbox/task/libs/task/src/spin/mutex.cpp | 2 +-
   4 files changed, 10 insertions(+), 10 deletions(-)

Added: sandbox/task/libs/task/src/detail/guard.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/detail/guard.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
@@ -0,0 +1,28 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/task/detail/guard.hpp"
+
+#include <boost/assert.hpp>
+
+namespace boost {
+namespace tasks {
+namespace detail {
+
+guard::guard( atomic< unsigned int > & active_worker) :
+ active_worker_( active_worker)
+{
+ BOOST_ASSERT( 0 <= active_worker_.load() );
+ active_worker_.fetch_add( 1);
+}
+
+guard::~guard()
+{
+ active_worker_.fetch_sub( 1);
+ BOOST_ASSERT( 0 <= active_worker_.load() );
+}
+
+}}}

Added: sandbox/task/libs/task/src/detail/worker.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/detail/worker.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
@@ -0,0 +1,51 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/task/detail/worker.hpp"
+
+namespace boost {
+namespace tasks {
+namespace detail {
+
+thread_specific_ptr< worker > worker::tss_;
+
+const thread::id
+worker::get_id() const
+{ return impl_->get_id(); }
+
+void
+worker::join() const
+{ impl_->join(); }
+
+void
+worker::interrupt() const
+{ impl_->interrupt(); }
+
+void
+worker::put( callable const& ca)
+{ impl_->put( ca); }
+
+bool
+worker::try_steal( callable & ca)
+{ return impl_->try_steal( ca); }
+
+void
+worker::run()
+{
+ // FIXME: ugly
+ worker::tss_.reset( new worker( * this) );
+ impl_->run();
+}
+
+void
+worker::yield()
+{ impl_->yield(); }
+
+worker *
+worker::tss_get()
+{ return worker::tss_.get(); }
+
+}}}

Added: sandbox/task/libs/task/src/detail/worker_group.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/detail/worker_group.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
@@ -0,0 +1,88 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/task/detail/worker_group.hpp"
+
+#include <boost/foreach.hpp>
+#include <boost/utility.hpp>
+
+namespace boost {
+namespace tasks {
+namespace detail {
+
+worker_group::worker_group() :
+ cont_(),
+ id_idx_( cont_.get< id_idx_tag >() ),
+ rnd_idx_( cont_.get< rnd_idx_tag >() )
+{}
+
+worker_group::~worker_group()
+{
+ if ( ! empty() )
+ join_all();
+}
+
+const worker
+worker_group::operator[]( std::size_t pos) const
+{ return rnd_idx_[pos]; }
+
+std::size_t
+worker_group::size() const
+{ return cont_.size(); }
+
+bool
+worker_group::empty() const
+{ return cont_.empty(); }
+
+const worker_group::iterator
+worker_group::begin()
+{ return id_idx_.begin(); }
+
+const worker_group::const_iterator
+worker_group::begin() const
+{ return id_idx_.begin(); }
+
+const worker_group::iterator
+worker_group::end()
+{ return id_idx_.end(); }
+
+const worker_group::const_iterator
+worker_group::end() const
+{ return id_idx_.end(); }
+
+const worker_group::const_iterator
+worker_group::find( thread::id const& id) const
+{ return id_idx_.find( id); }
+
+void
+worker_group::insert( worker const& w)
+{ cont_.insert( w); }
+
+worker_group::iterator
+worker_group::erase( iterator const& i)
+{ return id_idx_.erase( i); }
+
+void
+worker_group::join_all()
+{
+ BOOST_FOREACH( worker w, cont_)
+ {
+ try
+ { w.join(); }
+ catch (...)
+ {}
+ }
+ cont_.clear();
+}
+
+void
+worker_group::interrupt_all()
+{
+ BOOST_FOREACH( worker w, cont_)
+ { w.interrupt(); }
+}
+
+}}}

Added: sandbox/task/libs/task/src/detail/wsq.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/detail/wsq.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
@@ -0,0 +1,118 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/task/detail/wsq.hpp"
+
+#include <boost/thread/locks.hpp>
+
+namespace boost {
+namespace tasks {
+namespace detail {
+
+wsq::wsq() :
+initial_size_( 32),
+array_( new callable[ initial_size_]),
+capacity_( initial_size_),
+mask_( initial_size_ - 1),
+head_idx_( 0),
+tail_idx_( 0),
+mtx_()
+{}
+
+bool
+wsq::empty() const
+{ return head_idx_.load() >= tail_idx_.load(); }
+
+std::size_t
+wsq::size() const
+{ return tail_idx_.load() - head_idx_.load(); }
+
+void
+wsq::put( callable const& ca)
+{
+ unsigned int tail( tail_idx_.load() );
+ if ( tail <= head_idx_.load() + mask_)
+ {
+ array_[tail & mask_] = ca;
+ tail_idx_.fetch_add( 1);
+ }
+ else
+ {
+ lock_guard< recursive_mutex > lk( mtx_);
+ unsigned int head( head_idx_.load() );
+ int count( size() );
+
+ if ( count >= mask_)
+ {
+ capacity_ <<= 1;
+ shared_array< callable > array( new callable[capacity_]);
+ for ( int i( 0); i != count; ++i)
+ array[i] = array_[(i + head) & mask_];
+ array_.swap( array);
+ head_idx_.store( 0);
+ tail = count;
+ tail_idx_.store( tail);
+ mask_ = (mask_ << 1) | 1;
+ }
+ array_[tail & mask_] = ca;
+ tail_idx_.fetch_add( 1);
+ }
+}
+
+bool
+wsq::try_take( callable & ca)
+{
+ unsigned int tail( tail_idx_.load() );
+ if ( tail == 0)
+ return false;
+ tail -= 1;
+ tail_idx_.exchange( tail);
+ //tail_idx_.store( tail);
+ if ( head_idx_.load() <= tail)
+ {
+ ca.swap( array_[tail & mask_]);
+ return true;
+ }
+ else
+ {
+ lock_guard< recursive_mutex > lk( mtx_);
+ if ( head_idx_.load() <= tail)
+ {
+ ca.swap( array_[tail & mask_]);
+ return true;
+ }
+ else
+ {
+ tail_idx_.fetch_add( 1);
+ return false;
+ }
+ }
+}
+
+bool
+wsq::try_steal( callable & ca)
+{
+ recursive_mutex::scoped_try_lock lk( mtx_);
+ if ( lk.owns_lock() )
+ {
+ unsigned int head( head_idx_.load() );
+ head_idx_.exchange( head + 1);
+ //head_idx_.store( head + 1);
+ if ( head < tail_idx_.load() )
+ {
+ ca.swap( array_[head & mask_]);
+ return true;
+ }
+ else
+ {
+ head_idx_.store( head);
+ return false;
+ }
+ }
+ return false;
+}
+
+}}}

Deleted: sandbox/task/libs/task/src/guard.cpp
==============================================================================
--- sandbox/task/libs/task/src/guard.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
+++ (empty file)
@@ -1,28 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/detail/guard.hpp"
-
-#include <boost/assert.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-guard::guard( atomic< unsigned int > & active_worker) :
- active_worker_( active_worker)
-{
- BOOST_ASSERT( 0 <= active_worker_.load() );
- active_worker_.fetch_add( 1);
-}
-
-guard::~guard()
-{
- active_worker_.fetch_sub( 1);
- BOOST_ASSERT( 0 <= active_worker_.load() );
-}
-
-}}}

Modified: sandbox/task/libs/task/src/spin/auto_reset_event.cpp
==============================================================================
--- sandbox/task/libs/task/src/spin/auto_reset_event.cpp (original)
+++ sandbox/task/libs/task/src/spin/auto_reset_event.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
@@ -30,7 +30,7 @@
         {
                 this_thread::interruption_point();
                 if ( this_task::runs_in_pool() )
- this_task::block();
+ this_task::yield();
                 else
                         this_thread::yield();
                 this_thread::interruption_point();
@@ -47,7 +47,7 @@
 }
 
 bool
-auto_reset_event::wait( system_time const& abs_time)
+auto_reset_event::timed_wait( system_time const& abs_time)
 {
         if ( get_system_time() >= abs_time) return false;
 
@@ -56,7 +56,7 @@
         {
                 this_thread::interruption_point();
                 if ( this_task::runs_in_pool() )
- this_task::block();
+ this_task::yield();
                 else
                         this_thread::yield();
                 this_thread::interruption_point();

Modified: sandbox/task/libs/task/src/spin/count_down_event.cpp
==============================================================================
--- sandbox/task/libs/task/src/spin/count_down_event.cpp (original)
+++ sandbox/task/libs/task/src/spin/count_down_event.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
@@ -52,7 +52,7 @@
         {
                 this_thread::interruption_point();
                 if ( this_task::runs_in_pool() )
- this_task::block();
+ this_task::yield();
                 else
                         this_thread::yield();
                 this_thread::interruption_point();
@@ -60,7 +60,7 @@
 }
 
 bool
-count_down_event::wait( system_time const& abs_time)
+count_down_event::timed_wait( system_time const& abs_time)
 {
         if ( get_system_time() >= abs_time) return false;
 
@@ -68,7 +68,7 @@
         {
                 this_thread::interruption_point();
                 if ( this_task::runs_in_pool() )
- this_task::block();
+ this_task::yield();
                 else
                         this_thread::yield();
                 this_thread::interruption_point();

Modified: sandbox/task/libs/task/src/spin/manual_reset_event.cpp
==============================================================================
--- sandbox/task/libs/task/src/spin/manual_reset_event.cpp (original)
+++ sandbox/task/libs/task/src/spin/manual_reset_event.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
@@ -54,7 +54,7 @@
         {
                 this_thread::interruption_point();
                 if ( this_task::runs_in_pool() )
- this_task::block();
+ this_task::yield();
                 else
                         this_thread::yield();
                 this_thread::interruption_point();
@@ -65,7 +65,7 @@
 }
 
 bool
-manual_reset_event::wait( system_time const& abs_time)
+manual_reset_event::timed_wait( system_time const& abs_time)
 {
         if ( get_system_time() >= abs_time) return false;
 
@@ -73,7 +73,7 @@
         {
                 this_thread::interruption_point();
                 if ( this_task::runs_in_pool() )
- this_task::block();
+ this_task::yield();
                 else
                         this_thread::yield();
                 this_thread::interruption_point();

Modified: sandbox/task/libs/task/src/spin/mutex.cpp
==============================================================================
--- sandbox/task/libs/task/src/spin/mutex.cpp (original)
+++ sandbox/task/libs/task/src/spin/mutex.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
@@ -54,7 +54,7 @@
 
                 this_thread::interruption_point();
                 if ( this_task::runs_in_pool() )
- this_task::block();
+ this_task::yield();
                 else
                         this_thread::yield();
                 this_thread::interruption_point();

Deleted: sandbox/task/libs/task/src/worker.cpp
==============================================================================
--- sandbox/task/libs/task/src/worker.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
+++ (empty file)
@@ -1,51 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/detail/worker.hpp"
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-thread_specific_ptr< worker > worker::tss_;
-
-const thread::id
-worker::get_id() const
-{ return impl_->get_id(); }
-
-void
-worker::join() const
-{ impl_->join(); }
-
-void
-worker::interrupt() const
-{ impl_->interrupt(); }
-
-void
-worker::put( callable const& ca)
-{ impl_->put( ca); }
-
-bool
-worker::try_steal( callable & ca)
-{ return impl_->try_steal( ca); }
-
-void
-worker::run()
-{
- // FIXME: ugly
- worker::tss_.reset( new worker( * this) );
- impl_->run();
-}
-
-void
-worker::block()
-{ impl_->block(); }
-
-worker *
-worker::tss_get()
-{ return worker::tss_.get(); }
-
-}}}

Deleted: sandbox/task/libs/task/src/worker_group.cpp
==============================================================================
--- sandbox/task/libs/task/src/worker_group.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
+++ (empty file)
@@ -1,88 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/detail/worker_group.hpp"
-
-#include <boost/foreach.hpp>
-#include <boost/utility.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-worker_group::worker_group() :
- cont_(),
- id_idx_( cont_.get< id_idx_tag >() ),
- rnd_idx_( cont_.get< rnd_idx_tag >() )
-{}
-
-worker_group::~worker_group()
-{
- if ( ! empty() )
- join_all();
-}
-
-const worker
-worker_group::operator[]( std::size_t pos) const
-{ return rnd_idx_[pos]; }
-
-std::size_t
-worker_group::size() const
-{ return cont_.size(); }
-
-bool
-worker_group::empty() const
-{ return cont_.empty(); }
-
-const worker_group::iterator
-worker_group::begin()
-{ return id_idx_.begin(); }
-
-const worker_group::const_iterator
-worker_group::begin() const
-{ return id_idx_.begin(); }
-
-const worker_group::iterator
-worker_group::end()
-{ return id_idx_.end(); }
-
-const worker_group::const_iterator
-worker_group::end() const
-{ return id_idx_.end(); }
-
-const worker_group::const_iterator
-worker_group::find( thread::id const& id) const
-{ return id_idx_.find( id); }
-
-void
-worker_group::insert( worker const& w)
-{ cont_.insert( w); }
-
-worker_group::iterator
-worker_group::erase( iterator const& i)
-{ return id_idx_.erase( i); }
-
-void
-worker_group::join_all()
-{
- BOOST_FOREACH( worker w, cont_)
- {
- try
- { w.join(); }
- catch (...)
- {}
- }
- cont_.clear();
-}
-
-void
-worker_group::interrupt_all()
-{
- BOOST_FOREACH( worker w, cont_)
- { w.interrupt(); }
-}
-
-}}}

Deleted: sandbox/task/libs/task/src/wsq.cpp
==============================================================================
--- sandbox/task/libs/task/src/wsq.cpp 2010-01-09 10:06:05 EST (Sat, 09 Jan 2010)
+++ (empty file)
@@ -1,118 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/detail/wsq.hpp"
-
-#include <boost/thread/locks.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-wsq::wsq() :
-initial_size_( 32),
-array_( new callable[ initial_size_]),
-capacity_( initial_size_),
-mask_( initial_size_ - 1),
-head_idx_( 0),
-tail_idx_( 0),
-mtx_()
-{}
-
-bool
-wsq::empty() const
-{ return head_idx_.load() >= tail_idx_.load(); }
-
-std::size_t
-wsq::size() const
-{ return tail_idx_.load() - head_idx_.load(); }
-
-void
-wsq::put( callable const& ca)
-{
- unsigned int tail( tail_idx_.load() );
- if ( tail <= head_idx_.load() + mask_)
- {
- array_[tail & mask_] = ca;
- tail_idx_.fetch_add( 1);
- }
- else
- {
- lock_guard< recursive_mutex > lk( mtx_);
- unsigned int head( head_idx_.load() );
- int count( size() );
-
- if ( count >= mask_)
- {
- capacity_ <<= 1;
- shared_array< callable > array( new callable[capacity_]);
- for ( int i( 0); i != count; ++i)
- array[i] = array_[(i + head) & mask_];
- array_.swap( array);
- head_idx_.store( 0);
- tail = count;
- tail_idx_.store( tail);
- mask_ = (mask_ << 1) | 1;
- }
- array_[tail & mask_] = ca;
- tail_idx_.fetch_add( 1);
- }
-}
-
-bool
-wsq::try_take( callable & ca)
-{
- unsigned int tail( tail_idx_.load() );
- if ( tail == 0)
- return false;
- tail -= 1;
- tail_idx_.exchange( tail);
- //tail_idx_.store( tail);
- if ( head_idx_.load() <= tail)
- {
- ca.swap( array_[tail & mask_]);
- return true;
- }
- else
- {
- lock_guard< recursive_mutex > lk( mtx_);
- if ( head_idx_.load() <= tail)
- {
- ca.swap( array_[tail & mask_]);
- return true;
- }
- else
- {
- tail_idx_.fetch_add( 1);
- return false;
- }
- }
-}
-
-bool
-wsq::try_steal( callable & ca)
-{
- recursive_mutex::scoped_try_lock lk( mtx_);
- if ( lk.owns_lock() )
- {
- unsigned int head( head_idx_.load() );
- head_idx_.exchange( head + 1);
- //head_idx_.store( head + 1);
- if ( head < tail_idx_.load() )
- {
- ca.swap( array_[head & mask_]);
- return true;
- }
- else
- {
- head_idx_.store( head);
- return false;
- }
- }
- return false;
-}
-
-}}}


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