Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58536 - in sandbox/task: boost/task boost/task/detail libs/task/test
From: oliver.kowalke_at_[hidden]
Date: 2009-12-27 18:10:30


Author: olli
Date: 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
New Revision: 58536
URL: http://svn.boost.org/trac/boost/changeset/58536

Log:
- dependencies to boost.fiber, boost.atomic and boos.move added
- rename of queues

Added:
   sandbox/task/boost/task/bounded_fifo.hpp (contents, props changed)
   sandbox/task/boost/task/bounded_prio_queue.hpp (contents, props changed)
   sandbox/task/boost/task/bounded_smart_queue.hpp (contents, props changed)
   sandbox/task/boost/task/detail/future_traits.hpp (contents, props changed)
   sandbox/task/boost/task/unbounded_fifo.hpp (contents, props changed)
   sandbox/task/boost/task/unbounded_prio_queue.hpp (contents, props changed)
   sandbox/task/boost/task/unbounded_smart_queue.hpp (contents, props changed)
   sandbox/task/libs/task/test/test_bounded_pool.cpp (contents, props changed)
   sandbox/task/libs/task/test/test_spin_bounded_channel.cpp (contents, props changed)
   sandbox/task/libs/task/test/test_spin_unbounded_channel.cpp (contents, props changed)
   sandbox/task/libs/task/test/test_unbounded_pool.cpp (contents, props changed)
Removed:
   sandbox/task/boost/task/bounded_onelock_fifo.hpp
   sandbox/task/boost/task/bounded_onelock_prio_queue.hpp
   sandbox/task/boost/task/bounded_onelock_smart_queue.hpp
   sandbox/task/boost/task/bounded_twolock_fifo.hpp
   sandbox/task/boost/task/detail/atomic.hpp
   sandbox/task/boost/task/detail/atomic_aix.hpp
   sandbox/task/boost/task/detail/atomic_gcc.hpp
   sandbox/task/boost/task/detail/atomic_gcc_ppc.hpp
   sandbox/task/boost/task/detail/atomic_gcc_x86.hpp
   sandbox/task/boost/task/detail/atomic_hpux.hpp
   sandbox/task/boost/task/detail/atomic_interlocked.hpp
   sandbox/task/boost/task/detail/atomic_interprocess.hpp
   sandbox/task/boost/task/detail/atomic_solaris.hpp
   sandbox/task/boost/task/detail/atomic_sync.hpp
   sandbox/task/boost/task/detail/has_sync.hpp
   sandbox/task/boost/task/unbounded_onelock_fifo.hpp
   sandbox/task/boost/task/unbounded_onelock_prio_queue.hpp
   sandbox/task/boost/task/unbounded_onelock_smart_queue.hpp
   sandbox/task/boost/task/unbounded_twolock_fifo.hpp
   sandbox/task/libs/task/test/test_bounded_buffer.cpp
   sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp
   sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp
   sandbox/task/libs/task/test/test_unbounded_buffer.cpp
   sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp
   sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp

Added: sandbox/task/boost/task/bounded_fifo.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/bounded_fifo.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,285 @@
+
+// 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)
+
+#ifndef BOOST_TASKS_BOUNDED_FIFO_H
+#define BOOST_TASKS_BOUNDED_FIFO_H
+
+#include <cstddef>
+
+#include <boost/assert.hpp>
+#include <boost/atomic.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
+#include <boost/task/callable.hpp>
+#include <boost/task/detail/meta.hpp>
+#include <boost/task/exceptions.hpp>
+#include <boost/task/watermark.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace tasks {
+
+class bounded_fifo
+{
+public:
+ typedef detail::has_no_attribute attribute_tag_type;
+ typedef callable value_type;
+
+private:
+ struct node
+ {
+ typedef shared_ptr< node > sptr_t;
+
+ value_type va;
+ sptr_t next;
+ };
+
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
+ };
+
+ atomic< state > state_;
+ atomic< std::size_t > count_;
+ node::sptr_t head_;
+ mutable mutex head_mtx_;
+ node::sptr_t tail_;
+ mutable mutex tail_mtx_;
+ condition not_empty_cond_;
+ condition not_full_cond_;
+ std::size_t hwm_;
+ std::size_t lwm_;
+
+ bool active_() const
+ { return ACTIVE == state_.load(); }
+
+ void deactivate_()
+ { state_.store( DEACTIVE); }
+
+ std::size_t size_() const
+ { return count_.load(); }
+
+ bool empty_() const
+ { return head_ == get_tail_(); }
+
+ bool full_() const
+ { return size_() >= hwm_; }
+
+ node::sptr_t get_tail_() const
+ {
+ 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;
+ count_.fetch_sub( 1);
+ return old_head;
+ }
+
+public:
+ bounded_fifo(
+ high_watermark const& hwm,
+ low_watermark const& lwm) :
+ state_( ACTIVE),
+ count_( 0),
+ head_( new node),
+ head_mtx_(),
+ tail_( head_),
+ tail_mtx_(),
+ not_empty_cond_(),
+ not_full_cond_(),
+ hwm_( hwm),
+ lwm_( lwm)
+ {}
+
+ void upper_bound_( std::size_t hwm)
+ {
+ if ( lwm_ > hwm )
+ throw invalid_watermark();
+ std::size_t tmp( hwm_);
+ hwm_ = hwm;
+ if ( hwm_ > tmp) not_full_cond_.notify_one();
+ }
+
+ std::size_t upper_bound() const
+ { return hwm_; }
+
+ void lower_bound_( std::size_t lwm)
+ {
+ if ( lwm > hwm_ )
+ throw invalid_watermark();
+ std::size_t tmp( lwm_);
+ lwm_ = lwm;
+ if ( lwm_ > tmp) not_full_cond_.notify_one();
+ }
+
+ std::size_t lower_bound() const
+ { return lwm_; }
+
+ bool active() const
+ { return active_(); }
+
+ void deactivate()
+ { deactivate_(); }
+
+ bool empty() const
+ {
+ unique_lock< mutex > lk( head_mtx_);
+ return empty_();
+ }
+
+ void put( value_type const& va)
+ {
+ node::sptr_t new_node( new node);
+ {
+ unique_lock< mutex > lk( tail_mtx_);
+
+ if ( full_() )
+ {
+ while ( active_() && full_() )
+ not_full_cond_.wait( lk);
+ }
+ if ( ! active_() )
+ throw task_rejected("queue is not active");
+
+ tail_->va = va;
+ tail_->next = new_node;
+ tail_ = new_node;
+ count_.fetch_add( 1);
+ }
+ not_empty_cond_.notify_one();
+ }
+
+ template< typename TimeDuration >
+ void put(
+ value_type const& va,
+ TimeDuration const& rel_time)
+ {
+ node::sptr_t new_node( new node);
+ {
+ unique_lock< mutex > lk( tail_mtx_);
+
+ if ( full_() )
+ {
+ while ( active_() && full_() )
+ if ( ! not_full_cond_.wait( lk, rel_time) )
+ throw task_rejected("timed out");
+ }
+ if ( ! active_() )
+ throw task_rejected("queue is not active");
+
+ tail_->va = va;
+ tail_->next = new_node;
+ tail_ = new_node;
+ count_.fetch_add( 1);
+ }
+ not_empty_cond_.notify_one();
+ }
+
+ bool take( value_type & va)
+ {
+ unique_lock< mutex > lk( head_mtx_);
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ while ( active_() && empty_() )
+ not_empty_cond_.wait( lk);
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ va.swap( head_->va);
+ pop_head_();
+ if ( size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // for submiting an action object
+ not_full_cond_.notify_all();
+ }
+ return ! va.empty();
+ }
+
+ template< typename TimeDuration >
+ bool take(
+ value_type & va,
+ TimeDuration const& rel_time)
+ {
+ unique_lock< mutex > lk( head_mtx_);
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ while ( active_() && empty_() )
+ if ( ! not_empty_cond_.timed_wait( lk, rel_time) )
+ return false;
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ va.swap( head_->va);
+ pop_head_();
+ if ( size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // for submiting an action object
+ not_full_cond_.notify_all();
+ }
+ return ! va.empty();
+ }
+
+ bool try_take( value_type & va)
+ {
+ unique_lock< mutex > lk( head_mtx_);
+ if ( empty_() )
+ return false;
+ va.swap( head_->va);
+ pop_head_();
+ bool valid = ! va.empty();
+ if ( valid && size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // in order to submit an task
+ not_full_cond_.notify_all();
+ }
+ return valid;
+ }
+};
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_TASKS_BOUNDED_FIFO_H

Deleted: sandbox/task/boost/task/bounded_onelock_fifo.hpp
==============================================================================
--- sandbox/task/boost/task/bounded_onelock_fifo.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,312 +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)
-
-#ifndef BOOST_TASKS_BOUNDED_ONELOCK_FIFO_H
-#define BOOST_TASKS_BOUNDED_ONELOCK_FIFO_H
-
-#include <cstddef>
-#include <list>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/shared_mutex.hpp>
-
-#include <boost/task/callable.hpp>
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/detail/meta.hpp>
-#include <boost/task/exceptions.hpp>
-#include <boost/task/watermark.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-
-class bounded_onelock_fifo
-{
-public:
- typedef detail::has_no_attribute attribute_tag_type;
- typedef callable value_type;
-
-private:
- typedef std::list< value_type > queue_type;
-
- volatile uint32_t state_;
- queue_type queue_;
- shared_mutex mtx_;
- condition not_empty_cond_;
- condition not_full_cond_;
- std::size_t hwm_;
- std::size_t lwm_;
-
- bool active_() const
- { return 0 == state_; }
-
- void deactivate_()
- { detail::atomic_fetch_add( & state_, 1); }
-
- bool empty_() const
- { return queue_.empty(); }
-
- bool full_() const
- { return size_() >= hwm_; }
-
- std::size_t size_() const
- { return queue_.size(); }
-
- void upper_bound_( std::size_t hwm)
- {
- if ( lwm_ > hwm )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- std::size_t tmp( hwm_);
- hwm_ = hwm;
- if ( hwm_ > tmp) not_full_cond_.notify_one();
- }
-
- void lower_bound_( std::size_t lwm)
- {
- if ( lwm > hwm_ )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- std::size_t tmp( lwm_);
- lwm_ = lwm;
- if ( lwm_ > tmp) not_full_cond_.notify_one();
- }
-
- void put_(
- value_type const& va,
- unique_lock< shared_mutex > & lk)
- {
- if ( full_() )
- {
- not_full_cond_.wait(
- lk,
- bind(
- & bounded_onelock_fifo::producers_activate_,
- this) );
- }
- if ( ! active_() )
- throw task_rejected("queue is not active");
- queue_.push_back( va);
- not_empty_cond_.notify_one();
- }
-
- template< typename Duration >
- void put_(
- value_type const& va,
- Duration const& rel_time,
- unique_lock< shared_mutex > & lk)
- {
- if ( full_() )
- {
- if ( ! not_full_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & bounded_onelock_fifo::producers_activate_,
- this) ) )
- throw task_rejected("timed out");
- }
- if ( ! active_() )
- throw task_rejected("queue is not active");
- queue_.push_back( va);
- not_empty_cond_.notify_one();
- }
-
- bool take_(
- value_type & va,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- not_empty_cond_.wait(
- lk,
- bind(
- & bounded_onelock_fifo::consumers_activate_,
- this) );
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va.swap( queue_.front() );
- queue_.pop_front();
- if ( size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // for submiting an action object
- not_full_cond_.notify_all();
- }
- return ! va.empty();
- }
-
- template< typename Duration >
- bool take_(
- value_type & va,
- Duration const& rel_time,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- if ( ! not_empty_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & bounded_onelock_fifo::consumers_activate_,
- this) ) )
- return false;
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va.swap( queue_.front() );
- queue_.pop_front();
- if ( size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // in order to submit an task
- not_full_cond_.notify_all();
- }
- return ! va.empty();
- }
-
- bool try_take_( value_type & va)
- {
- if ( empty_() )
- return false;
- va.swap( queue_.front() );
- queue_.pop_front();
- bool valid = ! va.empty();
- if ( valid && size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // in order to submit an task
- not_full_cond_.notify_all();
- }
- return valid;
- }
-
- bool producers_activate_() const
- { return ! active_() || ! full_(); }
-
- bool consumers_activate_() const
- { return ! active_() || ! empty_(); }
-
-public:
- bounded_onelock_fifo(
- high_watermark const& hwm,
- low_watermark const& lwm) :
- state_( 0),
- queue_(),
- mtx_(),
- not_empty_cond_(),
- not_full_cond_(),
- hwm_( hwm),
- lwm_( lwm)
- {
- if ( lwm_ > hwm_ )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- }
-
- void deactivate()
- { deactivate_(); }
-
- bool empty()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return empty_();
- }
-
- std::size_t upper_bound()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return hwm_;
- }
-
- void upper_bound( std::size_t hwm)
- {
- unique_lock< shared_mutex > lk( mtx_);
- upper_bound_( hwm);
- }
-
- std::size_t lower_bound()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return lwm_;
- }
-
- void lower_bound( std::size_t lwm)
- {
- unique_lock< shared_mutex > lk( mtx_);
- lower_bound_( lwm);
- }
-
- void put( value_type const& va)
- {
- unique_lock< shared_mutex > lk( mtx_);
- put_( va, lk);
- }
-
- template< typename Duration >
- void put(
- value_type const& va,
- Duration const& rel_time)
- {
- unique_lock< shared_mutex > lk( mtx_);
- put_( va, rel_time, lk);
- }
-
- bool take( value_type & va)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( va, lk);
- }
-
- template< typename Duration >
- bool take(
- value_type & va,
- Duration const& rel_time)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( va, rel_time, lk);
- }
-
- bool try_take( value_type & va)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return try_take_( va);
- }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_BOUNDED_ONELOCK_FIFO_H

Deleted: sandbox/task/boost/task/bounded_onelock_prio_queue.hpp
==============================================================================
--- sandbox/task/boost/task/bounded_onelock_prio_queue.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,349 +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)
-
-#ifndef BOOST_TASKS_BOUNDED_ONELOCK_PRIO_QUEUE_H
-#define BOOST_TASKS_BOUNDED_ONELOCK_PRIO_QUEUE_H
-
-#include <algorithm>
-#include <cstddef>
-#include <functional>
-#include <queue>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/shared_mutex.hpp>
-
-#include <boost/task/callable.hpp>
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/detail/meta.hpp>
-#include <boost/task/exceptions.hpp>
-#include <boost/task/watermark.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-
-template<
- typename Attr,
- typename Comp = std::less< Attr >
->
-class bounded_onelock_prio_queue
-{
-public:
- typedef detail::has_attribute attribute_tag_type;
- typedef Attr attribute_type;
-
- struct value_type
- {
- callable ca;
- attribute_type attr;
-
- value_type(
- callable const& ca_,
- attribute_type const& attr_) :
- ca( ca_), attr( attr_)
- { BOOST_ASSERT( ! ca.empty() ); }
-
- void swap( value_type & other)
- {
- ca.swap( other.ca);
- std::swap( attr, other.attr);
- }
- };
-
-private:
- struct compare : public std::binary_function< value_type, value_type, bool >
- {
- bool operator()( value_type const& va1, value_type const& va2)
- { return Comp()( va1.attr, va2.attr); }
- };
-
- typedef std::priority_queue<
- value_type,
- std::deque< value_type >,
- compare
- > queue_type;
-
- volatile uint32_t state_;
- queue_type queue_;
- shared_mutex mtx_;
- condition not_empty_cond_;
- condition not_full_cond_;
- std::size_t hwm_;
- std::size_t lwm_;
-
- bool active_() const
- { return 0 == state_; }
-
- void deactivate_()
- { detail::atomic_fetch_add( & state_, 1); }
-
- bool empty_() const
- { return queue_.empty(); }
-
- bool full_() const
- { return size_() >= hwm_; }
-
- std::size_t size_() const
- { return queue_.size(); }
-
- void upper_bound_( std::size_t hwm)
- {
- if ( lwm_ > hwm )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- std::size_t tmp( hwm_);
- hwm_ = hwm;
- if ( hwm_ > tmp) not_full_cond_.notify_one();
- }
-
- void lower_bound_( std::size_t lwm)
- {
- if ( lwm > hwm_ )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- std::size_t tmp( lwm_);
- lwm_ = lwm;
- if ( lwm_ > tmp) not_full_cond_.notify_one();
- }
-
- void put_(
- value_type const& va,
- unique_lock< shared_mutex > & lk)
- {
- if ( full_() )
- {
- not_full_cond_.wait(
- lk,
- bind(
- & bounded_onelock_prio_queue::producers_activate_,
- this) );
- }
- if ( ! active_() )
- throw task_rejected("queue is not active");
- queue_.push( va);
- not_empty_cond_.notify_one();
- }
-
- template< typename Duration >
- void put_(
- value_type const& va,
- Duration const& rel_time,
- unique_lock< shared_mutex > & lk)
- {
- if ( full_() )
- {
- if ( ! not_full_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & bounded_onelock_prio_queue::producers_activate_,
- this) ) )
- throw task_rejected("timed out");
- }
- if ( ! active_() )
- throw task_rejected("queue is not active");
- queue_.push( va);
- not_empty_cond_.notify_one();
- }
-
- bool take_(
- callable & ca,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- not_empty_cond_.wait(
- lk,
- bind(
- & bounded_onelock_prio_queue::consumers_activate_,
- this) );
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- callable tmp( queue_.top().ca);
- queue_.pop();
- ca.swap( tmp);
- if ( size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // for submiting an action object
- not_full_cond_.notify_all();
- }
- return ! ca.empty();
- }
-
- template< typename Duration >
- bool take_(
- callable & ca,
- Duration const& rel_time,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- if ( ! not_empty_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & bounded_onelock_prio_queue::consumers_activate_,
- this) ) )
- return false;
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- callable tmp( queue_.top().ca);
- queue_.pop();
- ca.swap( tmp);
- if ( size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // in order to submit an task
- not_full_cond_.notify_all();
- }
- return ! ca.empty();
- }
-
- bool try_take_( callable & ca)
- {
- if ( empty_() )
- return false;
- callable tmp( queue_.top().ca);
- queue_.pop();
- ca.swap( tmp);
- bool valid = ! ca.empty();
- if ( valid && size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // in order to submit an task
- not_full_cond_.notify_all();
- }
- return valid;
- }
-
- bool producers_activate_() const
- { return ! active_() || ! full_(); }
-
- bool consumers_activate_() const
- { return ! active_() || ! empty_(); }
-
-public:
- bounded_onelock_prio_queue(
- high_watermark const& hwm,
- low_watermark const& lwm) :
- state_( 0),
- queue_(),
- mtx_(),
- not_empty_cond_(),
- not_full_cond_(),
- hwm_( hwm),
- lwm_( lwm)
- {
- if ( lwm_ > hwm_ )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- }
-
- void deactivate()
- { deactivate_(); }
-
- bool empty()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return empty_();
- }
-
- std::size_t upper_bound()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return hwm_;
- }
-
- void upper_bound( std::size_t hwm)
- {
- unique_lock< shared_mutex > lk( mtx_);
- upper_bound_( hwm);
- }
-
- std::size_t lower_bound()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return lwm_;
- }
-
- void lower_bound( std::size_t lwm)
- {
- unique_lock< shared_mutex > lk( mtx_);
- lower_bound_( lwm);
- }
-
- void put( value_type const& va)
- {
- unique_lock< shared_mutex > lk( mtx_);
- put_( va, lk);
- }
-
- template< typename Duration >
- void put(
- value_type const& va,
- Duration const& rel_time)
- {
- unique_lock< shared_mutex > lk( mtx_);
- put_( va, rel_time, lk);
- }
-
- bool take( callable & ca)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( ca, lk);
- }
-
- template< typename Duration >
- bool take(
- callable & ca,
- Duration const& rel_time)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( ca, rel_time, lk);
- }
-
- bool try_take( callable & ca)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return try_take_( ca);
- }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_BOUNDED_ONELOCK_PRIO_QUEUE_H

Deleted: sandbox/task/boost/task/bounded_onelock_smart_queue.hpp
==============================================================================
--- sandbox/task/boost/task/bounded_onelock_smart_queue.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,356 +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)
-
-#ifndef BOOST_TASKS_BOUNDED_ONELOCK_SMART_QUEUE_H
-#define BOOST_TASKS_BOUNDED_ONELOCK_SMART_QUEUE_H
-
-#include <algorithm>
-#include <cstddef>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
-#include <boost/multi_index_container.hpp>
-#include <boost/multi_index/member.hpp>
-#include <boost/multi_index/ordered_index.hpp>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/shared_mutex.hpp>
-
-#include <boost/task/callable.hpp>
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/detail/meta.hpp>
-#include <boost/task/detail/smart.hpp>
-#include <boost/task/exceptions.hpp>
-#include <boost/task/watermark.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-
-template<
- typename Attr,
- typename Comp,
- typename Enq = detail::replace_oldest,
- typename Deq = detail::take_oldest
->
-class bounded_onelock_smart_queue
-{
-public:
- typedef detail::has_attribute attribute_tag_type;
- typedef Attr attribute_type;
-
- struct value_type
- {
- callable ca;
- attribute_type attr;
-
- value_type(
- callable const& ca_,
- attribute_type const& attr_) :
- ca( ca_), attr( attr_)
- { BOOST_ASSERT( ! ca.empty() ); }
-
- void swap( value_type & other)
- {
- ca.swap( other.ca);
- std::swap( attr, other.attr);
- }
- };
-
-private:
- typedef multi_index::multi_index_container<
- value_type,
- multi_index::indexed_by<
- multi_index::ordered_non_unique<
- multi_index::member<
- value_type,
- Attr,
- & value_type::attr
- >,
- Comp
- >
- >
- > queue_type;
- typedef typename queue_type::template nth_index< 0 >::type queue_index;
-
- volatile uint32_t state_;
- queue_type queue_;
- queue_index & idx_;
- shared_mutex mtx_;
- condition not_empty_cond_;
- condition not_full_cond_;
- Enq enq_op_;
- Deq deq_op_;
- std::size_t hwm_;
- std::size_t lwm_;
-
- bool active_() const
- { return 0 == state_; }
-
- void deactivate_()
- { detail::atomic_fetch_add( & state_, 1); }
-
- bool empty_() const
- { return queue_.empty(); }
-
- bool full_() const
- { return size_() >= hwm_; }
-
- std::size_t size_() const
- { return queue_.size(); }
-
- void upper_bound_( std::size_t hwm)
- {
- if ( lwm_ > hwm )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- std::size_t tmp( hwm_);
- hwm_ = hwm;
- if ( hwm_ > tmp) not_full_cond_.notify_one();
- }
-
- void lower_bound_( std::size_t lwm)
- {
- if ( lwm > hwm_ )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- std::size_t tmp( lwm_);
- lwm_ = lwm;
- if ( lwm_ > tmp) not_full_cond_.notify_one();
- }
-
- void put_(
- value_type const& va,
- unique_lock< shared_mutex > & lk)
- {
- if ( full_() )
- {
- not_full_cond_.wait(
- lk,
- bind(
- & bounded_onelock_smart_queue::producers_activate_,
- this) );
- }
- if ( ! active_() )
- throw task_rejected("queue is not active");
- enq_op_( idx_, va);
- not_empty_cond_.notify_one();
- }
-
- template< typename Duration >
- void put_(
- value_type const& va,
- Duration const& rel_time,
- unique_lock< shared_mutex > & lk)
- {
- if ( full_() )
- {
- if ( ! not_full_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & bounded_onelock_smart_queue::producers_activate_,
- this) ) )
- throw task_rejected("timed out");
- }
- if ( ! active_() )
- throw task_rejected("queue is not active");
- enq_op_( idx_, va);
- not_empty_cond_.notify_one();
- }
-
- bool take_(
- callable & ca,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- not_empty_cond_.wait(
- lk,
- bind(
- & bounded_onelock_smart_queue::consumers_activate_,
- this) );
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- deq_op_( idx_, ca);
- if ( size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // for submiting an action object
- not_full_cond_.notify_all();
- }
- return ! ca.empty();
- }
-
- template< typename Duration >
- bool take_(
- callable & ca,
- Duration const& rel_time,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- if ( ! not_empty_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & bounded_onelock_smart_queue::consumers_activate_,
- this) ) )
- return false;
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- deq_op_( idx_, ca);
- if ( size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // in order to submit an task
- not_full_cond_.notify_all();
- }
- return ! ca.empty();
- }
-
- bool try_take_( callable & ca)
- {
- if ( empty_() )
- return false;
- deq_op_( idx_, ca);
- bool valid = ! ca.empty();
- if ( valid && size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // in order to submit an task
- not_full_cond_.notify_all();
- }
- return valid;
- }
-
- bool producers_activate_() const
- { return ! active_() || ! full_(); }
-
- bool consumers_activate_() const
- { return ! active_() || ! empty_(); }
-
-public:
- bounded_onelock_smart_queue(
- high_watermark const& hwm,
- low_watermark const& lwm) :
- state_( 0),
- queue_(),
- idx_( queue_.get< 0 >() ),
- mtx_(),
- not_empty_cond_(),
- not_full_cond_(),
- enq_op_(),
- deq_op_(),
- hwm_( hwm),
- lwm_( lwm)
- {
- if ( lwm_ > hwm_ )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- }
-
- void deactivate()
- { deactivate_(); }
-
- bool empty()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return empty_();
- }
-
- std::size_t upper_bound()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return hwm_;
- }
-
- void upper_bound( std::size_t hwm)
- {
- unique_lock< shared_mutex > lk( mtx_);
- upper_bound_( hwm);
- }
-
- std::size_t lower_bound()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return lwm_;
- }
-
- void lower_bound( std::size_t lwm)
- {
- unique_lock< shared_mutex > lk( mtx_);
- lower_bound_( lwm);
- }
-
- void put( value_type const& va)
- {
- unique_lock< shared_mutex > lk( mtx_);
- put_( va, lk);
- }
-
- template< typename Duration >
- void put(
- value_type const& va,
- Duration const& rel_time)
- {
- unique_lock< shared_mutex > lk( mtx_);
- put_( va, rel_time, lk);
- }
-
- bool take( callable & ca)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( ca, lk);
- }
-
- template< typename Duration >
- bool take(
- callable & ca,
- Duration const& rel_time)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( ca, rel_time, lk);
- }
-
- bool try_take( callable & ca)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return try_take_( ca);
- }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_BOUNDED_ONELOCK_SMART_QUEUE_H

Added: sandbox/task/boost/task/bounded_prio_queue.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/bounded_prio_queue.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,358 @@
+
+// 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)
+
+#ifndef BOOST_TASKS_BOUNDED_PRIO_QUEUE_H
+#define BOOST_TASKS_BOUNDED_PRIO_QUEUE_H
+
+#include <algorithm>
+#include <cstddef>
+#include <functional>
+#include <queue>
+
+#include <boost/assert.hpp>
+#include <boost/atomic.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
+#include <boost/task/callable.hpp>
+#include <boost/task/detail/meta.hpp>
+#include <boost/task/exceptions.hpp>
+#include <boost/task/watermark.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace tasks {
+
+template<
+ typename Attr,
+ typename Comp = std::less< Attr >
+>
+class bounded_prio_queue
+{
+public:
+ typedef detail::has_attribute attribute_tag_type;
+ typedef Attr attribute_type;
+
+ struct value_type
+ {
+ callable ca;
+ attribute_type attr;
+
+ value_type(
+ callable const& ca_,
+ attribute_type const& attr_) :
+ ca( ca_), attr( attr_)
+ { BOOST_ASSERT( ! ca.empty() ); }
+
+ void swap( value_type & other)
+ {
+ ca.swap( other.ca);
+ std::swap( attr, other.attr);
+ }
+ };
+
+private:
+ struct compare : public std::binary_function< value_type, value_type, bool >
+ {
+ bool operator()( value_type const& va1, value_type const& va2)
+ { return Comp()( va1.attr, va2.attr); }
+ };
+
+ typedef std::priority_queue<
+ value_type,
+ std::deque< value_type >,
+ compare
+ > queue_type;
+
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
+ };
+
+ atomic< state > state_;
+ queue_type queue_;
+ mutable shared_mutex mtx_;
+ condition not_empty_cond_;
+ condition not_full_cond_;
+ std::size_t hwm_;
+ std::size_t lwm_;
+
+ bool active_() const
+ { return ACTIVE == state_.load(); }
+
+ void deactivate_()
+ { state_.store( DEACTIVE); }
+
+ bool empty_() const
+ { return queue_.empty(); }
+
+ bool full_() const
+ { return size_() >= hwm_; }
+
+ std::size_t size_() const
+ { return queue_.size(); }
+
+ void upper_bound_( std::size_t hwm)
+ {
+ if ( lwm_ > hwm )
+ throw invalid_watermark();
+ std::size_t tmp( hwm_);
+ hwm_ = hwm;
+ if ( hwm_ > tmp) not_full_cond_.notify_one();
+ }
+
+ void lower_bound_( std::size_t lwm)
+ {
+ if ( lwm > hwm_ )
+ throw invalid_watermark();
+ std::size_t tmp( lwm_);
+ lwm_ = lwm;
+ if ( lwm_ > tmp) not_full_cond_.notify_one();
+ }
+
+ void put_(
+ value_type const& va,
+ unique_lock< shared_mutex > & lk)
+ {
+ if ( full_() )
+ {
+ not_full_cond_.wait(
+ lk,
+ bind(
+ & bounded_prio_queue::producers_activate_,
+ this) );
+ }
+ if ( ! active_() )
+ throw task_rejected("queue is not active");
+ queue_.push( va);
+ not_empty_cond_.notify_one();
+ }
+
+ template< typename TimeDuration >
+ void put_(
+ value_type const& va,
+ TimeDuration const& rel_time,
+ unique_lock< shared_mutex > & lk)
+ {
+ if ( full_() )
+ {
+ if ( ! not_full_cond_.timed_wait(
+ lk,
+ rel_time,
+ bind(
+ & bounded_prio_queue::producers_activate_,
+ this) ) )
+ throw task_rejected("timed out");
+ }
+ if ( ! active_() )
+ throw task_rejected("queue is not active");
+ queue_.push( va);
+ not_empty_cond_.notify_one();
+ }
+
+ bool take_(
+ callable & ca,
+ unique_lock< shared_mutex > & lk)
+ {
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ not_empty_cond_.wait(
+ lk,
+ bind(
+ & bounded_prio_queue::consumers_activate_,
+ this) );
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ callable tmp( queue_.top().ca);
+ queue_.pop();
+ ca.swap( tmp);
+ if ( size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // for submiting an action object
+ not_full_cond_.notify_all();
+ }
+ return ! ca.empty();
+ }
+
+ template< typename TimeDuration >
+ bool take_(
+ callable & ca,
+ TimeDuration const& rel_time,
+ unique_lock< shared_mutex > & lk)
+ {
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ if ( ! not_empty_cond_.timed_wait(
+ lk,
+ rel_time,
+ bind(
+ & bounded_prio_queue::consumers_activate_,
+ this) ) )
+ return false;
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ callable tmp( queue_.top().ca);
+ queue_.pop();
+ ca.swap( tmp);
+ if ( size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // in order to submit an task
+ not_full_cond_.notify_all();
+ }
+ return ! ca.empty();
+ }
+
+ bool try_take_( callable & ca)
+ {
+ if ( empty_() )
+ return false;
+ callable tmp( queue_.top().ca);
+ queue_.pop();
+ ca.swap( tmp);
+ bool valid = ! ca.empty();
+ if ( valid && size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // in order to submit an task
+ not_full_cond_.notify_all();
+ }
+ return valid;
+ }
+
+ bool producers_activate_() const
+ { return ! active_() || ! full_(); }
+
+ bool consumers_activate_() const
+ { return ! active_() || ! empty_(); }
+
+public:
+ bounded_prio_queue(
+ high_watermark const& hwm,
+ low_watermark const& lwm) :
+ state_( ACTIVE),
+ queue_(),
+ mtx_(),
+ not_empty_cond_(),
+ not_full_cond_(),
+ hwm_( hwm),
+ lwm_( lwm)
+ {
+ if ( lwm_ > hwm_ )
+ throw invalid_watermark();
+ }
+
+ bool active() const
+ { return active_(); }
+
+ void deactivate()
+ { deactivate_(); }
+
+ bool empty() const
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return empty_();
+ }
+
+ std::size_t upper_bound() const
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return hwm_;
+ }
+
+ void upper_bound( std::size_t hwm)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ upper_bound_( hwm);
+ }
+
+ std::size_t lower_bound() const
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return lwm_;
+ }
+
+ void lower_bound( std::size_t lwm)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ lower_bound_( lwm);
+ }
+
+ void put( value_type const& va)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ put_( va, lk);
+ }
+
+ template< typename TimeDuration >
+ void put(
+ value_type const& va,
+ TimeDuration const& rel_time)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ put_( va, rel_time, lk);
+ }
+
+ bool take( callable & ca)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, lk);
+ }
+
+ template< typename TimeDuration >
+ bool take(
+ callable & ca,
+ TimeDuration const& rel_time)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, rel_time, lk);
+ }
+
+ bool try_take( callable & ca)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return try_take_( ca);
+ }
+};
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_TASKS_BOUNDED_PRIO_QUEUE_H

Added: sandbox/task/boost/task/bounded_smart_queue.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/bounded_smart_queue.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,365 @@
+
+// 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)
+
+#ifndef BOOST_TASKS_BOUNDED_SMART_QUEUE_H
+#define BOOST_TASKS_BOUNDED_SMART_QUEUE_H
+
+#include <algorithm>
+#include <cstddef>
+
+#include <boost/assert.hpp>
+#include <boost/atomic.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/member.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
+#include <boost/task/callable.hpp>
+#include <boost/task/detail/meta.hpp>
+#include <boost/task/detail/smart.hpp>
+#include <boost/task/exceptions.hpp>
+#include <boost/task/watermark.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace tasks {
+
+template<
+ typename Attr,
+ typename Comp,
+ typename Enq = detail::replace_oldest,
+ typename Deq = detail::take_oldest
+>
+class bounded_smart_queue
+{
+public:
+ typedef detail::has_attribute attribute_tag_type;
+ typedef Attr attribute_type;
+
+ struct value_type
+ {
+ callable ca;
+ attribute_type attr;
+
+ value_type(
+ callable const& ca_,
+ attribute_type const& attr_) :
+ ca( ca_), attr( attr_)
+ { BOOST_ASSERT( ! ca.empty() ); }
+
+ void swap( value_type & other)
+ {
+ ca.swap( other.ca);
+ std::swap( attr, other.attr);
+ }
+ };
+
+private:
+ typedef multi_index::multi_index_container<
+ value_type,
+ multi_index::indexed_by<
+ multi_index::ordered_non_unique<
+ multi_index::member<
+ value_type,
+ Attr,
+ & value_type::attr
+ >,
+ Comp
+ >
+ >
+ > queue_type;
+ typedef typename queue_type::template nth_index< 0 >::type queue_index;
+
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
+ };
+
+ atomic< state > state_;
+ queue_type queue_;
+ queue_index & idx_;
+ mutable shared_mutex mtx_;
+ condition not_empty_cond_;
+ condition not_full_cond_;
+ Enq enq_op_;
+ Deq deq_op_;
+ std::size_t hwm_;
+ std::size_t lwm_;
+
+ bool active_() const
+ { return ACTIVE == state_.load(); }
+
+ void deactivate_()
+ { state_.store( DEACTIVE); }
+
+ bool empty_() const
+ { return queue_.empty(); }
+
+ bool full_() const
+ { return size_() >= hwm_; }
+
+ std::size_t size_() const
+ { return queue_.size(); }
+
+ void upper_bound_( std::size_t hwm)
+ {
+ if ( lwm_ > hwm )
+ throw invalid_watermark();
+ std::size_t tmp( hwm_);
+ hwm_ = hwm;
+ if ( hwm_ > tmp) not_full_cond_.notify_one();
+ }
+
+ void lower_bound_( std::size_t lwm)
+ {
+ if ( lwm > hwm_ )
+ throw invalid_watermark();
+ std::size_t tmp( lwm_);
+ lwm_ = lwm;
+ if ( lwm_ > tmp) not_full_cond_.notify_one();
+ }
+
+ void put_(
+ value_type const& va,
+ unique_lock< shared_mutex > & lk)
+ {
+ if ( full_() )
+ {
+ not_full_cond_.wait(
+ lk,
+ bind(
+ & bounded_smart_queue::producers_activate_,
+ this) );
+ }
+ if ( ! active_() )
+ throw task_rejected("queue is not active");
+ enq_op_( idx_, va);
+ not_empty_cond_.notify_one();
+ }
+
+ template< typename TimeDuration >
+ void put_(
+ value_type const& va,
+ TimeDuration const& rel_time,
+ unique_lock< shared_mutex > & lk)
+ {
+ if ( full_() )
+ {
+ if ( ! not_full_cond_.timed_wait(
+ lk,
+ rel_time,
+ bind(
+ & bounded_smart_queue::producers_activate_,
+ this) ) )
+ throw task_rejected("timed out");
+ }
+ if ( ! active_() )
+ throw task_rejected("queue is not active");
+ enq_op_( idx_, va);
+ not_empty_cond_.notify_one();
+ }
+
+ bool take_(
+ callable & ca,
+ unique_lock< shared_mutex > & lk)
+ {
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ not_empty_cond_.wait(
+ lk,
+ bind(
+ & bounded_smart_queue::consumers_activate_,
+ this) );
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ deq_op_( idx_, ca);
+ if ( size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // for submiting an action object
+ not_full_cond_.notify_all();
+ }
+ return ! ca.empty();
+ }
+
+ template< typename TimeDuration >
+ bool take_(
+ callable & ca,
+ TimeDuration const& rel_time,
+ unique_lock< shared_mutex > & lk)
+ {
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ if ( ! not_empty_cond_.timed_wait(
+ lk,
+ rel_time,
+ bind(
+ & bounded_smart_queue::consumers_activate_,
+ this) ) )
+ return false;
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ deq_op_( idx_, ca);
+ if ( size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // in order to submit an task
+ not_full_cond_.notify_all();
+ }
+ return ! ca.empty();
+ }
+
+ bool try_take_( callable & ca)
+ {
+ if ( empty_() )
+ return false;
+ deq_op_( idx_, ca);
+ bool valid = ! ca.empty();
+ if ( valid && size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // in order to submit an task
+ not_full_cond_.notify_all();
+ }
+ return valid;
+ }
+
+ bool producers_activate_() const
+ { return ! active_() || ! full_(); }
+
+ bool consumers_activate_() const
+ { return ! active_() || ! empty_(); }
+
+public:
+ bounded_smart_queue(
+ high_watermark const& hwm,
+ low_watermark const& lwm) :
+ state_( ACTIVE),
+ queue_(),
+ idx_( queue_.get< 0 >() ),
+ mtx_(),
+ not_empty_cond_(),
+ not_full_cond_(),
+ enq_op_(),
+ deq_op_(),
+ hwm_( hwm),
+ lwm_( lwm)
+ {
+ if ( lwm_ > hwm_ )
+ throw invalid_watermark();
+ }
+
+ bool active() const
+ { return active_(); }
+
+ void deactivate()
+ { deactivate_(); }
+
+ bool empty() const
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return empty_();
+ }
+
+ std::size_t upper_bound() const
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return hwm_;
+ }
+
+ void upper_bound( std::size_t hwm)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ upper_bound_( hwm);
+ }
+
+ std::size_t lower_bound() const
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return lwm_;
+ }
+
+ void lower_bound( std::size_t lwm)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ lower_bound_( lwm);
+ }
+
+ void put( value_type const& va)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ put_( va, lk);
+ }
+
+ template< typename TimeDuration >
+ void put(
+ value_type const& va,
+ TimeDuration const& rel_time)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ put_( va, rel_time, lk);
+ }
+
+ bool take( callable & ca)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, lk);
+ }
+
+ template< typename TimeDuration >
+ bool take(
+ callable & ca,
+ TimeDuration const& rel_time)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, rel_time, lk);
+ }
+
+ bool try_take( callable & ca)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return try_take_( ca);
+ }
+};
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_TASKS_BOUNDED_SMART_QUEUE_H

Deleted: sandbox/task/boost/task/bounded_twolock_fifo.hpp
==============================================================================
--- sandbox/task/boost/task/bounded_twolock_fifo.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,277 +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)
-
-#ifndef BOOST_TASKS_BOUNDED_TWOLOCK_FIFO_H
-#define BOOST_TASKS_BOUNDED_TWOLOCK_FIFO_H
-
-#include <cstddef>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/foreach.hpp>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/shared_mutex.hpp>
-
-#include <boost/task/callable.hpp>
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/detail/meta.hpp>
-#include <boost/task/exceptions.hpp>
-#include <boost/task/watermark.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-
-class bounded_twolock_fifo
-{
-public:
- typedef detail::has_no_attribute attribute_tag_type;
- typedef callable value_type;
-
-private:
- struct node
- {
- typedef shared_ptr< node > sptr_t;
-
- value_type va;
- sptr_t next;
- };
-
- volatile uint32_t state_;
- volatile uint32_t count_;
- node::sptr_t head_;
- mutex head_mtx_;
- node::sptr_t tail_;
- mutex tail_mtx_;
- condition not_empty_cond_;
- condition not_full_cond_;
- std::size_t hwm_;
- std::size_t lwm_;
-
- bool active_() const
- { return 0 == state_; }
-
- void deactivate_()
- { detail::atomic_fetch_add( & state_, 1); }
-
- uint32_t size_()
- { return count_; }
-
- bool empty_()
- { return head_ == get_tail_(); }
-
- bool full_()
- { return size_() >= hwm_; }
-
- 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;
- detail::atomic_fetch_sub( & count_, 1);
- return old_head;
- }
-
-public:
- bounded_twolock_fifo(
- high_watermark const& hwm,
- low_watermark const& lwm) :
- state_( 0),
- count_( 0),
- head_( new node),
- head_mtx_(),
- tail_( head_),
- tail_mtx_(),
- not_empty_cond_(),
- not_full_cond_(),
- hwm_( hwm),
- lwm_( lwm)
- {}
-
- void upper_bound_( std::size_t hwm)
- {
- if ( lwm_ > hwm )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- std::size_t tmp( hwm_);
- hwm_ = hwm;
- if ( hwm_ > tmp) not_full_cond_.notify_one();
- }
-
- std::size_t upper_bound()
- { return hwm_; }
-
- void lower_bound_( std::size_t lwm)
- {
- if ( lwm > hwm_ )
- throw invalid_watermark("low watermark must be less than or equal to high watermark");
- std::size_t tmp( lwm_);
- lwm_ = lwm;
- if ( lwm_ > tmp) not_full_cond_.notify_one();
- }
-
- std::size_t lower_bound()
- { return lwm_; }
-
- void deactivate()
- { deactivate_(); }
-
- bool empty()
- {
- unique_lock< mutex > lk( head_mtx_);
- return empty_();
- }
-
- void put( value_type const& va)
- {
- node::sptr_t new_node( new node);
- {
- unique_lock< mutex > lk( tail_mtx_);
-
- if ( full_() )
- {
- while ( active_() && full_() )
- not_full_cond_.wait( lk);
- }
- if ( ! active_() )
- throw task_rejected("queue is not active");
-
- tail_->va = va;
- tail_->next = new_node;
- tail_ = new_node;
- detail::atomic_fetch_add( & count_, 1);
- }
- not_empty_cond_.notify_one();
- }
-
- template< typename Duration >
- void put(
- value_type const& va,
- Duration const& rel_time)
- {
- node::sptr_t new_node( new node);
- {
- unique_lock< mutex > lk( tail_mtx_);
-
- if ( full_() )
- {
- while ( active_() && full_() )
- if ( ! not_full_cond_.wait( lk, rel_time) )
- throw task_rejected("timed out");
- }
- if ( ! active_() )
- throw task_rejected("queue is not active");
-
- tail_->va = va;
- tail_->next = new_node;
- tail_ = new_node;
- detail::atomic_fetch_add( & count_, 1);
- }
- not_empty_cond_.notify_one();
- }
-
- bool take( value_type & va)
- {
- unique_lock< mutex > lk( head_mtx_);
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- while ( active_() && empty_() )
- not_empty_cond_.wait( lk);
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va.swap( head_->va);
- pop_head_();
- if ( size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // for submiting an action object
- not_full_cond_.notify_all();
- }
- return ! va.empty();
- }
-
- template< typename Duration >
- bool take(
- value_type & va,
- Duration const& rel_time)
- {
- unique_lock< mutex > lk( head_mtx_);
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- while ( active_() && empty_() )
- if ( ! not_empty_cond_.timed_wait( lk, rel_time) )
- return false;
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va.swap( head_->va);
- pop_head_();
- if ( size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // for submiting an action object
- not_full_cond_.notify_all();
- }
- return ! va.empty();
- }
-
- bool try_take( value_type & va)
- {
- unique_lock< mutex > lk( head_mtx_);
- if ( empty_() )
- return false;
- va.swap( head_->va);
- pop_head_();
- bool valid = ! va.empty();
- if ( valid && size_() <= lwm_)
- {
- if ( lwm_ == hwm_)
- not_full_cond_.notify_one();
- else
- // more than one producer could be waiting
- // in order to submit an task
- not_full_cond_.notify_all();
- }
- return valid;
- }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_BOUNDED_TWOLOCK_FIFO_H

Deleted: sandbox/task/boost/task/detail/atomic.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,49 +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)
-
-#ifndef BOOST_TASKS_DETAIL_ATOMIC_H
-#define BOOST_TASKS_DETAIL_ATOMIC_H
-
-// MS compatible compilers support #pragma once
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-#include <boost/config.hpp>
-
-#include <boost/task/detail/has_sync.hpp>
-
-# if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
-#include <boost/task/detail/atomic_interlocked.hpp>
-
-# elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
-#include <boost/task/detail/atomic_gcc_x86.hpp>
-
-# elif defined( __GNUC__ ) && ( defined(__PPC__) || defined(__ppc__) )
-#include <boost/task/detail/atomic_gcc_ppc.hpp>
-
-# elif defined( BOOST_TASKS_HAS_SYNC)
-#include <boost/task/detail/atomic_sync.hpp>
-
-# elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
-#include <boost/task/detail/atomic_gcc.hpp>
-
-# elif defined(__IBMCPP__) || defined(_AIX)
-#include <boost/task/detail/atomic_aix.hpp>
-
-# elif defined(__hpux)
-#include <boost/task/detail/atomic_hpux.hpp>
-
-# elif defined(sun) || defined(__sun)
-#include <boost/task/detail/atomic_solaris.hpp>
-
-# else
-#include <boost/task/detail/atomic_interprocess.hpp>
-
-# endif
-
-#endif // BOOST_TASKS_DETAIL_ATOMIC_H
-

Deleted: sandbox/task/boost/task/detail/atomic_aix.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_aix.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,55 +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)
-
-#ifndef BOOST_TASKS_DETAIL_ATOMIC_AIX_H
-#define BOOST_TASKS_DETAIL_ATOMIC_AIX_H
-
-extern "C"
-{
-#include <sys/atomic_ops.h>
-}
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{ * object = desired; }
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{ return ::compare_and_swap( object, expected, desired); }
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::fetch_and_add( object, 1);
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::fetch_and_add( object, -1);
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_DETAIL_ATOMIC_AIX_H
-

Deleted: sandbox/task/boost/task/detail/atomic_gcc.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_gcc.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,77 +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)
-
-#ifndef BOOST_TASKS_DETAIL_ATOMIC_GCC_H
-#define BOOST_TASKS_DETAIL_ATOMIC_GCC_H
-
-// based on boost/smart_ptr/detail/atomic_count_gcc.hpp
-
-# if __GNUC__ * 100 + __GNUC_MINOR__ >= 402
-#include <ext/atomicity.h>
-# else
-#include <bits/atomicity.h>
-# endif
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/interprocess/detail/atomic.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-#if defined(__GLIBCXX__) // g++ 3.4+
-
-using __gnu_cxx::__atomic_add;
-using __gnu_cxx::__exchange_and_add;
-
-#endif
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{
- // inline asm xchg for i386 || x86_64?
- * object = desired;
-}
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = interprocess::detail::atomic_cas32( object, desired, * expected);
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return __exchange_and_add( ( _Atomic_word volatile *) object, 1) + 1;
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return __exchange_and_add( ( _Atomic_word volatile *) object, -1) - 1;
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_DETAIL_ATOMIC_GCC_H
-

Deleted: sandbox/task/boost/task/detail/atomic_gcc_ppc.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_gcc_ppc.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,114 +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)
-
-#ifndef BOOST_TASKS_DETAIL_ATOMIC_GCC_PPC_H
-#define BOOST_TASKS_DETAIL_ATOMIC_GCC_PPC_H
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{
- uint32_t r;
-
- __asm__ __volatile__
- (
- "0:\n\t"
- "lwarx %0, 0, %2 \n\t"
- "stwcx. %1, 0, %2 \n\t"
- "bne- 1b" :
- "=r" ( r) :
- "r" ( desired), "r" ( object)
- );
-}
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = * expected;
-
- __asm__ __volatile__
- (
- "0:\n\t"
- "lwarx %0,0,%1\n\t"
- "cmpw %0,%3\n\t"
- "bne- 1f\n\t"
- "stwcx. %2,0,%1\n\t"
- "bne- 0b\n\t"
- "1:"
- : "=&r"( * expected)
- : "b" ( object), "r" ( desired), "r" ( * expected)
- : "memory", "cc"
- );
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- int object_ = static_cast< int >( object);
- int operand_ = static_cast< int >( operand);
- int r, t;
-
- __asm__ __volatile__
- (
- "0:\n\t"
- "lwarx %0,0,%2\n\t"
- "add %1,%0,%3\n\t"
- "stwcx. %1,0,%2\n\t"
- "bne- 0b"
- : "=&r" ( r), "=&r" ( t)
- : "b" ( object_), "r" ( operand_)
- : "memory", "cc"
- );
-
- return r;
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- int object_ = static_cast< int >( object);
- int operand_ = static_cast< int >( -1 * operand);
- int r;
-
- __asm__ __volatile__
- (
- "0:\n\t"
- "lwarx %0,0,%2\n\t"
- "add %1,%0,%3\n\t"
- "stwcx. %1,0,%2\n\t"
- "bne- 0b"
- : "=&r" ( r), "=&r" ( t)
- : "b" ( object_), "r" ( operand_)
- : "memory", "cc"
- );
-
- return r;
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_DETAIL_ATOMIC_GCC_PPC_H
-

Deleted: sandbox/task/boost/task/detail/atomic_gcc_x86.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_gcc_x86.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,91 +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)
-
-#ifndef BOOST_TASKS_DETAIL_ATOMIC_GCC_X86_H
-#define BOOST_TASKS_DETAIL_ATOMIC_GCC_X86_H
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{
- __asm__ __volatile__
- (
- "xchg %0, %1" :
- "+r" ( desired), "+m" ( * object)
- );
-}
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = * expected;
-
- __asm__ __volatile__
- (
- "lock\n\t"
- "cmpxchg %3, %1"
- : "=a" ( * expected), "=m" ( * object)
- : "a" ( prev), "r" ( desired)
- : "memory", "cc"
- );
-
- return prev == * expected;
-}
-
-inline
-long atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- int operand_ = static_cast< int >( operand);
- int r;
-
- __asm__ __volatile__
- (
- "lock\n\t"
- "xadd %1, %0" :
- "+m"( * object), "=r"( r):
- "1"( operand_):
- "memory", "cc"
- );
-
- return r;
-}
-
-inline
-long atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- int operand_ = static_cast< int >( -1 * operand);
- int r;
-
- __asm__ __volatile__
- (
- "lock\n\t"
- "xadd %1, %0":
- "+m"( * object), "=r"( r ):
- "1"( operand_):
- "memory", "cc"
- );
-
- return r;
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_DETAIL_ATOMIC_GCC_X86_H
-

Deleted: sandbox/task/boost/task/detail/atomic_hpux.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_hpux.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,62 +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)
-
-#ifndef BOOST_TASKS_DETAIL_ATOMIC_HPUX_H
-#define BOOST_TASKS_DETAIL_ATOMIC_HPUX_H
-
-extern "C"
-{
-#include <atomic.h>
-}
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{ * object = desired; }
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = ::atomic_cas_32( object, * expected, desired);
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::atomic_inc( object);
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::atomic_dec( object);
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_DETAIL_ATOMIC_HPUX_H
-

Deleted: sandbox/task/boost/task/detail/atomic_interlocked.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_interlocked.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,66 +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)
-
-#ifndef BOOST_TASKS_DETAIL_ATOMIC_INTERLOCKED_H
-#define BOOST_TASKS_DETAIL_ATOMIC_INTERLOCKED_H
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/detail/interlocked.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{
- BOOST_INTERLOCKED_EXCHANGE(
- reinterpret_cast< long volatile * >( object),
- static_cast< long >( desired) );
-}
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = BOOST_INTERLOCKED_COMPARE_EXCHANGE(
- reinterpret_cast< long volatile * >( object),
- static_cast< long >( desired),
- static_cast< long >( * expected) );
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return BOOST_INTERLOCKED_INCREMENT( reinterpret_cast< long volatile * >( object) ) - 1;
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return BOOST_INTERLOCKED_DECREMENT( reinterpret_cast< long volatile * >( object) ) + 1;
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_DETAIL_ATOMIC_INTERLOCKED_H
-

Deleted: sandbox/task/boost/task/detail/atomic_interprocess.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_interprocess.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,59 +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)
-
-#ifndef BOOST_TASKS_DETAIL_ATOMIC_INTERPROCESS_H
-#define BOOST_TASKS_DETAIL_ATOMIC_INTERPROCESS_H
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/interprocess/detail/atomic.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{ interprocess::detail::atomic_write32( object, desired); }
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = interprocess::detail::atomic_cas32( object, desired, * expected);
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-unsigned int atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return interprocess::detail::atomic_inc32( object);
-}
-
-inline
-unsigned int atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return interprocess::detail::atomic_dec32( object);
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_DETAIL_ATOMIC_INTERPROCESS_H
-

Deleted: sandbox/task/boost/task/detail/atomic_solaris.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_solaris.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,63 +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)
-
-#ifndef BOOST_TASKS_DETAIL_ATOMIC_SOLARIS_H
-#define BOOST_TASKS_DETAIL_ATOMIC_SOLARIS_H
-
-extern "C"
-{
-#include <atomic.h>
-}
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{ * object = desired; }
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = ::atomic_cas_32( object, * expected, desired);
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::atomic_inc_32( object);
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return ::atomic_dec_32( object);
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_DETAIL_ATOMIC_SOLARIS_H
-

Deleted: sandbox/task/boost/task/detail/atomic_sync.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_sync.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,67 +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)
-
-#ifndef BOOST_TASKS_DETAIL_ATOMIC_SYNC_H
-#define BOOST_TASKS_DETAIL_ATOMIC_SYNC_H
-
-// based on boost/smart_ptr/detail/atomic_count_gc.hpp
-
-# if defined( __ia64__ ) && defined( __INTEL_COMPILER )
-extern "C"
-{
-#include<ia64intrin.h>
-}
-# endif
-
-#include <boost/assert.hpp>
-#include <boost/cstdint.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-namespace detail {
-
-inline
-uint32_t atomic_load( uint32_t const volatile * object)
-{ return * object; }
-
-inline
-void atomic_exchange( uint32_t volatile * object, uint32_t desired)
-{ * object = desired; }
-
-inline
-bool atomic_compare_exchange_strong( uint32_t volatile * object, uint32_t * expected, uint32_t desired)
-{
- uint32_t prev = __sync_val_compare_and_swap( object, * expected, desired);
- if ( prev != * expected)
- {
- * expected = prev;
- return false;
- }
- return true;
-}
-
-inline
-uint32_t atomic_fetch_add( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return __sync_fetch_and_add( object, 1);
-}
-
-inline
-uint32_t atomic_fetch_sub( uint32_t volatile * object, uint32_t operand)
-{
- BOOST_ASSERT( operand == 1);
- return __sync_fetch_and_add( object, -1);
-}
-
-}}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_DETAIL_ATOMIC_SYNC_H
-

Added: sandbox/task/boost/task/detail/future_traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/detail/future_traits.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,82 @@
+// (C) Copyright 2008-9 Anthony Williams
+//
+// 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)
+
+#ifndef BOOST_TASKS_DETAIL_FUTURE_TRAITSHPP
+#define BOOST_TASKS_DETAIL_FUTURE_TRAITSHPP
+
+#include <algorithm>
+#include <list>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/config.hpp>
+#include <boost/move/move.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/next_prior.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/type_traits/is_fundamental.hpp>
+
+namespace boost {
+namespace tasks {
+namespace detail {
+
+template<typename T>
+struct future_traits
+{
+ typedef boost::scoped_ptr<T> storage_type;
+#ifdef BOOST_HAS_RVALUE_REFS
+ typedef T const& source_reference_type;
+ struct dummy;
+ typedef typename boost::mpl::if_<boost::is_fundamental<T>,dummy&,T&&>::type rvalue_source_type;
+ typedef typename boost::mpl::if_<boost::is_fundamental<T>,T,T&&>::type move_dest_type;
+#else
+ typedef T& source_reference_type;
+ typedef typename boost::mpl::if_<boost::is_convertible<T&, BOOST_RV_REF( T) >, BOOST_RV_REF( T),T const&>::type rvalue_source_type;
+ typedef typename boost::mpl::if_<boost::is_convertible<T&,BOOST_RV_REF( T) >,BOOST_RV_REF( T),T>::type move_dest_type;
+#endif
+
+ static void init(storage_type& storage,source_reference_type t)
+ { storage.reset(new T(t)); }
+
+ static void init(storage_type& storage,rvalue_source_type t)
+ { storage.reset(new T(static_cast<rvalue_source_type>(t))); }
+
+ static void cleanup(storage_type& storage)
+ { storage.reset(); }
+};
+
+template<typename T>
+struct future_traits<T&>
+{
+ typedef T* storage_type;
+ typedef T& source_reference_type;
+ struct rvalue_source_type {};
+ typedef T& move_dest_type;
+
+ static void init(storage_type& storage,T& t)
+ { storage=&t; }
+
+ static void cleanup(storage_type& storage)
+ { storage=0; }
+};
+
+template<>
+struct future_traits<void>
+{
+ typedef bool storage_type;
+ typedef void move_dest_type;
+
+ static void init(storage_type& storage)
+ { storage=true; }
+
+ static void cleanup(storage_type& storage)
+ { storage=false; }
+};
+
+}}}
+
+#endif // BOOST_TASKS_DETAIL_FUTURE_TRAITS_H

Deleted: sandbox/task/boost/task/detail/has_sync.hpp
==============================================================================
--- sandbox/task/boost/task/detail/has_sync.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,49 +0,0 @@
-#ifndef BOOST_TASKS_DETAIL_HAS_SYNC_H
-#define BOOST_TASKS_DETAIL_HAS_SYNC_H
-
-// MS compatible compilers support #pragma once
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-//
-// based on boost/smart_ptr/detail/sp_has_sync.hpp
-//
-// Copyright (c) 2008, 2009 Peter Dimov
-//
-// 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)
-//
-// Defines the BOOST_SP_HAS_SYNC macro if the __sync_* intrinsics
-// are available.
-//
-
-#if defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
-
-#define BOOST_TASKS_HAS_SYNC
-
-#if defined( __arm__ ) || defined( __armel__ )
-#undef BOOST_TASKS_HAS_SYNC
-#endif
-
-#if defined( __hppa ) || defined( __hppa__ )
-#undef BOOST_TASKS_HAS_SYNC
-#endif
-
-#if defined( __m68k__ )
-#undef BOOST_TASKS_HAS_SYNC
-#endif
-
-#if defined( __sparc__ )
-#undef BOOST_TASKS_HAS_SYNC
-#endif
-
-#if defined( __INTEL_COMPILER ) && !defined( __ia64__ )
-#undef BOOST_TASKS_HAS_SYNC
-#endif
-
-#endif // __GNUC__ * 100 + __GNUC_MINOR__ >= 401
-
-#endif // BOOST_TASKS_DETAIL_HAS_SYNC_H

Added: sandbox/task/boost/task/unbounded_fifo.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/unbounded_fifo.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,179 @@
+
+// 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)
+
+#ifndef BOOST_TASKS_UNBOUNDED_FIFO_H
+#define BOOST_TASKS_UNBOUNDED_FIFO_H
+
+#include <cstddef>
+
+#include <boost/assert.hpp>
+#include <boost/atomic.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
+#include <boost/task/callable.hpp>
+#include <boost/task/detail/meta.hpp>
+#include <boost/task/exceptions.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace tasks {
+
+class unbounded_fifo
+{
+public:
+ typedef detail::has_no_attribute attribute_tag_type;
+ typedef callable value_type;
+
+private:
+ struct node
+ {
+ typedef shared_ptr< node > sptr_t;
+
+ value_type va;
+ sptr_t next;
+ };
+
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
+ };
+
+ atomic< state > state_;
+ node::sptr_t head_;
+ mutable mutex head_mtx_;
+ node::sptr_t tail_;
+ mutable mutex tail_mtx_;
+ condition not_empty_cond_;
+
+ bool active_() const
+ { return ACTIVE == state_.load(); }
+
+ void deactivate_()
+ { state_.store( DEACTIVE); }
+
+ bool empty_() const
+ { return head_ == get_tail_(); }
+
+ node::sptr_t get_tail_() const
+ {
+ 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:
+ unbounded_fifo() :
+ state_( ACTIVE),
+ head_( new node),
+ head_mtx_(),
+ tail_( head_),
+ tail_mtx_(),
+ not_empty_cond_()
+ {}
+
+ bool active() const
+ { return active_(); }
+
+ void deactivate()
+ { deactivate_(); }
+
+ bool empty() const
+ {
+ unique_lock< mutex > lk( head_mtx_);
+ return empty_();
+ }
+
+ void put( value_type const& va)
+ {
+ node::sptr_t new_node( new node);
+ {
+ unique_lock< mutex > lk( tail_mtx_);
+ tail_->va = va;
+ tail_->next = new_node;
+ tail_ = new_node;
+ }
+ not_empty_cond_.notify_one();
+ }
+
+ bool take( value_type & va)
+ {
+ unique_lock< mutex > lk( head_mtx_);
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ while ( active_() && empty_() )
+ not_empty_cond_.wait( lk);
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ va.swap( head_->va);
+ pop_head_();
+ return ! va.empty();
+ }
+
+ template< typename TimeDuration >
+ bool take(
+ value_type & va,
+ TimeDuration const& rel_time)
+ {
+ unique_lock< mutex > lk( head_mtx_);
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ while ( active_() && empty_() )
+ if ( ! not_empty_cond_.timed_wait( lk, rel_time) )
+ return false;
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ va.swap( head_->va);
+ pop_head_();
+ return ! va.empty();
+ }
+
+ bool try_take( value_type & va)
+ {
+ unique_lock< mutex > lk( head_mtx_);
+ if ( empty_() )
+ return false;
+ va.swap( head_->va);
+ pop_head_();
+ return ! va.empty();
+ }
+};
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_TASKS_UNBOUNDED_FIFO_H

Deleted: sandbox/task/boost/task/unbounded_onelock_fifo.hpp
==============================================================================
--- sandbox/task/boost/task/unbounded_onelock_fifo.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,180 +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)
-
-#ifndef BOOST_TASKS_UNBOUNDED_ONELOCK_FIFO_H
-#define BOOST_TASKS_UNBOUNDED_ONELOCK_FIFO_H
-
-#include <cstddef>
-#include <list>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/shared_mutex.hpp>
-
-#include <boost/task/callable.hpp>
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/detail/meta.hpp>
-#include <boost/task/exceptions.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-
-class unbounded_onelock_fifo
-{
-public:
- typedef detail::has_no_attribute attribute_tag_type;
- typedef callable value_type;
-
-private:
- typedef std::list< value_type > queue_type;
-
- volatile uint32_t state_;
- queue_type queue_;
- shared_mutex mtx_;
- condition not_empty_cond_;
-
- bool active_() const
- { return 0 == state_; }
-
- void deactivate_()
- { detail::atomic_fetch_add( & state_, 1); }
-
- bool empty_() const
- { return queue_.empty(); }
-
- void put_( value_type const& va)
- {
- if ( ! active_() )
- throw task_rejected("queue is not active");
- queue_.push_back( va);
- not_empty_cond_.notify_one();
- }
-
- bool take_(
- value_type & va,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- not_empty_cond_.wait(
- lk,
- bind(
- & unbounded_onelock_fifo::consumers_activate_,
- this) );
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va.swap( queue_.front() );
- queue_.pop_front();
- return ! va.empty();
- }
-
- template< typename Duration >
- bool take_(
- value_type & va,
- Duration const& rel_time,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- if ( ! not_empty_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & unbounded_onelock_fifo::consumers_activate_,
- this) ) )
- return false;
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va.swap( queue_.front() );
- queue_.pop_front();
- return ! va.empty();
- }
-
- bool try_take_( value_type & va)
- {
- if ( empty_() )
- return false;
- va.swap( queue_.front() );
- queue_.pop_front();
- return ! va.empty();
- }
-
- bool consumers_activate_() const
- { return ! active_() || ! empty_(); }
-
-public:
- unbounded_onelock_fifo() :
- state_( 0),
- queue_(),
- mtx_(),
- not_empty_cond_()
- {}
-
- void deactivate()
- { deactivate_(); }
-
- bool empty()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return empty_();
- }
-
- void put( value_type const& va)
- {
- unique_lock< shared_mutex > lk( mtx_);
- put_( va);
- }
-
- bool take( value_type & va)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( va, lk);
- }
-
- template< typename Duration >
- bool take(
- value_type & va,
- Duration const& rel_time)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( va, rel_time, lk);
- }
-
- bool try_take( value_type & va)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return try_take_( va);
- }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_UNBOUNDED_ONELOCK_FIFO_H

Deleted: sandbox/task/boost/task/unbounded_onelock_prio_queue.hpp
==============================================================================
--- sandbox/task/boost/task/unbounded_onelock_prio_queue.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,217 +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)
-
-#ifndef BOOST_TASKS_UNBOUNDED_ONELOCK_PRIO_QUEUE_H
-#define BOOST_TASKS_UNBOUNDED_ONELOCK_PRIO_QUEUE_H
-
-#include <algorithm>
-#include <cstddef>
-#include <functional>
-#include <queue>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/shared_mutex.hpp>
-
-#include <boost/task/callable.hpp>
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/detail/meta.hpp>
-#include <boost/task/exceptions.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-
-template<
- typename Attr,
- typename Comp = std::less< Attr >
->
-class unbounded_onelock_prio_queue
-{
-public:
- typedef detail::has_attribute attribute_tag_type;
- typedef Attr attribute_type;
-
- struct value_type
- {
- callable ca;
- attribute_type attr;
-
- value_type(
- callable const& ca_,
- attribute_type const& attr_) :
- ca( ca_), attr( attr_)
- { BOOST_ASSERT( ! ca.empty() ); }
-
- void swap( value_type & other)
- {
- ca.swap( other.ca);
- std::swap( attr, other.attr);
- }
- };
-
-private:
- struct compare : public std::binary_function< value_type, value_type, bool >
- {
- bool operator()( value_type const& va1, value_type const& va2)
- { return Comp()( va1.attr, va2.attr); }
- };
-
- typedef std::priority_queue<
- value_type,
- std::deque< value_type >,
- compare
- > queue_type;
-
- volatile uint32_t state_;
- queue_type queue_;
- shared_mutex mtx_;
- condition not_empty_cond_;
-
- bool active_() const
- { return 0 == state_; }
-
- void deactivate_()
- { detail::atomic_fetch_add( & state_, 1); }
-
- bool empty_() const
- { return queue_.empty(); }
-
- void put_( value_type const& va)
- {
- if ( ! active_() )
- throw task_rejected("queue is not active");
- queue_.push( va);
- not_empty_cond_.notify_one();
- }
-
- bool take_(
- callable & ca,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- not_empty_cond_.wait(
- lk,
- bind(
- & unbounded_onelock_prio_queue::consumers_activate_,
- this) );
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- callable tmp( queue_.top().ca);
- queue_.pop();
- ca.swap( tmp);
- return ! ca.empty();
- }
-
- template< typename Duration >
- bool take_(
- callable & ca,
- Duration const& rel_time,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- if ( ! not_empty_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & unbounded_onelock_prio_queue::consumers_activate_,
- this) ) )
- return false;
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- callable tmp( queue_.top().ca);
- queue_.pop();
- ca.swap( tmp);
- return ! ca.empty();
- }
-
- bool try_take_( callable & ca)
- {
- if ( empty_() )
- return false;
- callable tmp( queue_.top().ca);
- queue_.pop();
- ca.swap( tmp);
- return ! ca.empty();
- }
-
- bool consumers_activate_() const
- { return ! active_() || ! empty_(); }
-
-public:
- unbounded_onelock_prio_queue() :
- state_( 0),
- queue_(),
- mtx_(),
- not_empty_cond_()
- {}
-
- void deactivate()
- { deactivate_(); }
-
- bool empty()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return empty_();
- }
-
- void put( value_type const& va)
- {
- unique_lock< shared_mutex > lk( mtx_);
- put_( va);
- }
-
- bool take( callable & ca)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( ca, lk);
- }
-
- template< typename Duration >
- bool take(
- callable & ca,
- Duration const& rel_time)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( ca, rel_time, lk);
- }
-
- bool try_take( callable & ca)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return try_take_( ca);
- }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_UNBOUNDED_ONELOCK_PRIO_QUEUE_H

Deleted: sandbox/task/boost/task/unbounded_onelock_smart_queue.hpp
==============================================================================
--- sandbox/task/boost/task/unbounded_onelock_smart_queue.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,224 +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)
-
-#ifndef BOOST_TASKS_UNBOUNDED_ONELOCK_SMART_QUEUE_H
-#define BOOST_TASKS_UNBOUNDED_ONELOCK_SMART_QUEUE_H
-
-#include <algorithm>
-#include <cstddef>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
-#include <boost/multi_index_container.hpp>
-#include <boost/multi_index/member.hpp>
-#include <boost/multi_index/ordered_index.hpp>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/shared_mutex.hpp>
-
-#include <boost/task/callable.hpp>
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/detail/meta.hpp>
-#include <boost/task/detail/smart.hpp>
-#include <boost/task/exceptions.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-
-template<
- typename Attr,
- typename Comp,
- typename Enq = detail::replace_oldest,
- typename Deq = detail::take_oldest
->
-class unbounded_onelock_smart_queue
-{
-public:
- typedef detail::has_attribute attribute_tag_type;
- typedef Attr attribute_type;
-
- struct value_type
- {
- callable ca;
- attribute_type attr;
-
- value_type(
- callable const& ca_,
- attribute_type const& attr_) :
- ca( ca_), attr( attr_)
- { BOOST_ASSERT( ! ca.empty() ); }
-
- void swap( value_type & other)
- {
- ca.swap( other.ca);
- std::swap( attr, other.attr);
- }
- };
-
-private:
- typedef multi_index::multi_index_container<
- value_type,
- multi_index::indexed_by<
- multi_index::ordered_non_unique<
- multi_index::member<
- value_type,
- Attr,
- & value_type::attr
- >,
- Comp
- >
- >
- > queue_type;
- typedef typename queue_type::template nth_index< 0 >::type queue_index;
-
- volatile uint32_t state_;
- queue_type queue_;
- queue_index & idx_;
- shared_mutex mtx_;
- condition not_empty_cond_;
- Enq enq_op_;
- Deq deq_op_;
-
- bool active_() const
- { return 0 == state_; }
-
- void deactivate_()
- { detail::atomic_fetch_add( & state_, 1); }
-
- bool empty_() const
- { return queue_.empty(); }
-
- void put_( value_type const& va)
- {
- if ( ! active_() )
- throw task_rejected("queue is not active");
- enq_op_( idx_, va);
- not_empty_cond_.notify_one();
- }
-
- bool take_(
- callable & ca,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- not_empty_cond_.wait(
- lk,
- bind(
- & unbounded_onelock_smart_queue::consumers_activate_,
- this) );
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- deq_op_( idx_, ca);
- return ! ca.empty();
- }
-
- template< typename Duration >
- bool take_(
- callable & ca,
- Duration const& rel_time,
- unique_lock< shared_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- if ( ! not_empty_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & unbounded_onelock_smart_queue::consumers_activate_,
- this) ) )
- return false;
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- deq_op_( idx_, ca);
- return ! ca.empty();
- }
-
- bool try_take_( callable & ca)
- {
- if ( empty_() )
- return false;
- deq_op_( idx_, ca);
- return ! ca.empty();
- }
-
- bool consumers_activate_() const
- { return ! active_() || ! empty_(); }
-
-public:
- unbounded_onelock_smart_queue() :
- state_( 0),
- queue_(),
- idx_( queue_.get< 0 >() ),
- mtx_(),
- not_empty_cond_(),
- enq_op_(),
- deq_op_()
- {}
-
- void deactivate()
- { detail::atomic_fetch_add( & state_, 1); }
-
- bool empty()
- {
- shared_lock< shared_mutex > lk( mtx_);
- return empty_();
- }
-
- void put( value_type const& va)
- {
- unique_lock< shared_mutex > lk( mtx_);
- put_( va);
- }
-
- bool take( callable & ca)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( ca, lk);
- }
-
- template< typename Duration >
- bool take(
- callable & ca,
- Duration const& rel_time)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return take_( ca, rel_time, lk);
- }
-
- bool try_take( callable & ca)
- {
- unique_lock< shared_mutex > lk( mtx_);
- return try_take_( ca);
- }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_UNBOUNDED_ONELOCK_SMART_QUEUE_H

Added: sandbox/task/boost/task/unbounded_prio_queue.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/unbounded_prio_queue.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,226 @@
+
+// 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)
+
+#ifndef BOOST_TASKS_UNBOUNDED_PRIO_QUEUE_H
+#define BOOST_TASKS_UNBOUNDED_PRIO_QUEUE_H
+
+#include <algorithm>
+#include <cstddef>
+#include <functional>
+#include <queue>
+
+#include <boost/assert.hpp>
+#include <boost/atomic.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
+#include <boost/task/callable.hpp>
+#include <boost/task/detail/meta.hpp>
+#include <boost/task/exceptions.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace tasks {
+
+template<
+ typename Attr,
+ typename Comp = std::less< Attr >
+>
+class unbounded_prio_queue
+{
+public:
+ typedef detail::has_attribute attribute_tag_type;
+ typedef Attr attribute_type;
+
+ struct value_type
+ {
+ callable ca;
+ attribute_type attr;
+
+ value_type(
+ callable const& ca_,
+ attribute_type const& attr_) :
+ ca( ca_), attr( attr_)
+ { BOOST_ASSERT( ! ca.empty() ); }
+
+ void swap( value_type & other)
+ {
+ ca.swap( other.ca);
+ std::swap( attr, other.attr);
+ }
+ };
+
+private:
+ struct compare : public std::binary_function< value_type, value_type, bool >
+ {
+ bool operator()( value_type const& va1, value_type const& va2)
+ { return Comp()( va1.attr, va2.attr); }
+ };
+
+ typedef std::priority_queue<
+ value_type,
+ std::deque< value_type >,
+ compare
+ > queue_type;
+
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
+ };
+
+ atomic< state > state_;
+ queue_type queue_;
+ mutable shared_mutex mtx_;
+ condition not_empty_cond_;
+
+ bool active_() const
+ { return ACTIVE == state_.load(); }
+
+ void deactivate_()
+ { state_.store( DEACTIVE); }
+
+ bool empty_() const
+ { return queue_.empty(); }
+
+ void put_( value_type const& va)
+ {
+ if ( ! active_() )
+ throw task_rejected("queue is not active");
+ queue_.push( va);
+ not_empty_cond_.notify_one();
+ }
+
+ bool take_(
+ callable & ca,
+ unique_lock< shared_mutex > & lk)
+ {
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ not_empty_cond_.wait(
+ lk,
+ bind(
+ & unbounded_prio_queue::consumers_activate_,
+ this) );
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ callable tmp( queue_.top().ca);
+ queue_.pop();
+ ca.swap( tmp);
+ return ! ca.empty();
+ }
+
+ template< typename TimeDuration >
+ bool take_(
+ callable & ca,
+ TimeDuration const& rel_time,
+ unique_lock< shared_mutex > & lk)
+ {
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ if ( ! not_empty_cond_.timed_wait(
+ lk,
+ rel_time,
+ bind(
+ & unbounded_prio_queue::consumers_activate_,
+ this) ) )
+ return false;
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ callable tmp( queue_.top().ca);
+ queue_.pop();
+ ca.swap( tmp);
+ return ! ca.empty();
+ }
+
+ bool try_take_( callable & ca)
+ {
+ if ( empty_() )
+ return false;
+ callable tmp( queue_.top().ca);
+ queue_.pop();
+ ca.swap( tmp);
+ return ! ca.empty();
+ }
+
+ bool consumers_activate_() const
+ { return ! active_() || ! empty_(); }
+
+public:
+ unbounded_prio_queue() :
+ state_( ACTIVE),
+ queue_(),
+ mtx_(),
+ not_empty_cond_()
+ {}
+
+ bool active() const
+ { return active_(); }
+
+ void deactivate()
+ { deactivate_(); }
+
+ bool empty() const
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return empty_();
+ }
+
+ void put( value_type const& va)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ put_( va);
+ }
+
+ bool take( callable & ca)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, lk);
+ }
+
+ template< typename TimeDuration >
+ bool take(
+ callable & ca,
+ TimeDuration const& rel_time)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, rel_time, lk);
+ }
+
+ bool try_take( callable & ca)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return try_take_( ca);
+ }
+};
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_TASKS_UNBOUNDED_PRIO_QUEUE_H

Added: sandbox/task/boost/task/unbounded_smart_queue.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/unbounded_smart_queue.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,233 @@
+
+// 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)
+
+#ifndef BOOST_TASKS_UNBOUNDED_SMART_QUEUE_H
+#define BOOST_TASKS_UNBOUNDED_SMART_QUEUE_H
+
+#include <algorithm>
+#include <cstddef>
+
+#include <boost/assert.hpp>
+#include <boost/atomic.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/member.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
+#include <boost/task/callable.hpp>
+#include <boost/task/detail/meta.hpp>
+#include <boost/task/detail/smart.hpp>
+#include <boost/task/exceptions.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace tasks {
+
+template<
+ typename Attr,
+ typename Comp,
+ typename Enq = detail::replace_oldest,
+ typename Deq = detail::take_oldest
+>
+class unbounded_smart_queue
+{
+public:
+ typedef detail::has_attribute attribute_tag_type;
+ typedef Attr attribute_type;
+
+ struct value_type
+ {
+ callable ca;
+ attribute_type attr;
+
+ value_type(
+ callable const& ca_,
+ attribute_type const& attr_) :
+ ca( ca_), attr( attr_)
+ { BOOST_ASSERT( ! ca.empty() ); }
+
+ void swap( value_type & other)
+ {
+ ca.swap( other.ca);
+ std::swap( attr, other.attr);
+ }
+ };
+
+private:
+ typedef multi_index::multi_index_container<
+ value_type,
+ multi_index::indexed_by<
+ multi_index::ordered_non_unique<
+ multi_index::member<
+ value_type,
+ Attr,
+ & value_type::attr
+ >,
+ Comp
+ >
+ >
+ > queue_type;
+ typedef typename queue_type::template nth_index< 0 >::type queue_index;
+
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
+ };
+
+ atomic< state > state_;
+ queue_type queue_;
+ queue_index & idx_;
+ mutable shared_mutex mtx_;
+ condition not_empty_cond_;
+ Enq enq_op_;
+ Deq deq_op_;
+
+ bool active_() const
+ { return ACTIVE == state_.load(); }
+
+ void deactivate_()
+ { state_.store( DEACTIVE); }
+
+ bool empty_() const
+ { return queue_.empty(); }
+
+ void put_( value_type const& va)
+ {
+ if ( ! active_() )
+ throw task_rejected("queue is not active");
+ enq_op_( idx_, va);
+ not_empty_cond_.notify_one();
+ }
+
+ bool take_(
+ callable & ca,
+ unique_lock< shared_mutex > & lk)
+ {
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ not_empty_cond_.wait(
+ lk,
+ bind(
+ & unbounded_smart_queue::consumers_activate_,
+ this) );
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ deq_op_( idx_, ca);
+ return ! ca.empty();
+ }
+
+ template< typename TimeDuration >
+ bool take_(
+ callable & ca,
+ TimeDuration const& rel_time,
+ unique_lock< shared_mutex > & lk)
+ {
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ if ( ! not_empty_cond_.timed_wait(
+ lk,
+ rel_time,
+ bind(
+ & unbounded_smart_queue::consumers_activate_,
+ this) ) )
+ return false;
+ }
+ catch ( thread_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ deq_op_( idx_, ca);
+ return ! ca.empty();
+ }
+
+ bool try_take_( callable & ca)
+ {
+ if ( empty_() )
+ return false;
+ deq_op_( idx_, ca);
+ return ! ca.empty();
+ }
+
+ bool consumers_activate_() const
+ { return ! active_() || ! empty_(); }
+
+public:
+ unbounded_smart_queue() :
+ state_( ACTIVE),
+ queue_(),
+ idx_( queue_.get< 0 >() ),
+ mtx_(),
+ not_empty_cond_(),
+ enq_op_(),
+ deq_op_()
+ {}
+
+ bool active() const
+ { return active_(); }
+
+ void deactivate()
+ { deactivate_(); }
+
+ bool empty() const
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return empty_();
+ }
+
+ void put( value_type const& va)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ put_( va);
+ }
+
+ bool take( callable & ca)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, lk);
+ }
+
+ template< typename TimeDuration >
+ bool take(
+ callable & ca,
+ TimeDuration const& rel_time)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, rel_time, lk);
+ }
+
+ bool try_take( callable & ca)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return try_take_( ca);
+ }
+};
+
+}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_TASKS_UNBOUNDED_SMART_QUEUE_H

Deleted: sandbox/task/boost/task/unbounded_twolock_fifo.hpp
==============================================================================
--- sandbox/task/boost/task/unbounded_twolock_fifo.hpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,171 +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)
-
-#ifndef BOOST_TASKS_UNBOUNDED_TWOLOCK_FIFO_H
-#define BOOST_TASKS_UNBOUNDED_TWOLOCK_FIFO_H
-
-#include <cstddef>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/foreach.hpp>
-#include <boost/thread/condition.hpp>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/shared_mutex.hpp>
-
-#include <boost/task/callable.hpp>
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/detail/meta.hpp>
-#include <boost/task/exceptions.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace tasks {
-
-class unbounded_twolock_fifo
-{
-public:
- typedef detail::has_no_attribute attribute_tag_type;
- typedef callable value_type;
-
-private:
- struct node
- {
- typedef shared_ptr< node > sptr_t;
-
- value_type va;
- sptr_t next;
- };
-
- volatile uint32_t state_;
- node::sptr_t head_;
- mutex head_mtx_;
- node::sptr_t tail_;
- mutex tail_mtx_;
- condition not_empty_cond_;
-
- bool active_() const
- { return 0 == state_; }
-
- void deactivate_()
- { detail::atomic_fetch_add( & state_, 1); }
-
- 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:
- unbounded_twolock_fifo() :
- state_( 0),
- head_( new node),
- head_mtx_(),
- tail_( head_),
- tail_mtx_(),
- not_empty_cond_()
- {}
-
- void deactivate()
- { deactivate_(); }
-
- bool empty()
- {
- unique_lock< mutex > lk( head_mtx_);
- return empty_();
- }
-
- void put( value_type const& va)
- {
- node::sptr_t new_node( new node);
- {
- unique_lock< mutex > lk( tail_mtx_);
- tail_->va = va;
- tail_->next = new_node;
- tail_ = new_node;
- }
- not_empty_cond_.notify_one();
- }
-
- bool take( value_type & va)
- {
- unique_lock< mutex > lk( head_mtx_);
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- while ( active_() && empty_() )
- not_empty_cond_.wait( lk);
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va.swap( head_->va);
- pop_head_();
- return ! va.empty();
- }
-
- template< typename Duration >
- bool take(
- value_type & va,
- Duration const& rel_time)
- {
- unique_lock< mutex > lk( head_mtx_);
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- while ( active_() && empty_() )
- if ( ! not_empty_cond_.timed_wait( lk, rel_time) )
- return false;
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va.swap( head_->va);
- pop_head_();
- return ! va.empty();
- }
-
- bool try_take( value_type & va)
- {
- unique_lock< mutex > lk( head_mtx_);
- if ( empty_() )
- return false;
- va.swap( head_->va);
- pop_head_();
- return ! va.empty();
- }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASKS_UNBOUNDED_TWOLOCK_FIFO_H

Deleted: sandbox/task/libs/task/test/test_bounded_buffer.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_bounded_buffer.cpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,171 +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 <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/optional.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::tasks;
-
-struct send_data
-{
- tsk::bounded_buffer< int > & buf;
-
- send_data( tsk::bounded_buffer< int > & buf_) :
- buf( buf_)
- {}
-
- void operator()( int value)
- { buf.put( value); }
-};
-
-struct recv_data
-{
- tsk::bounded_buffer< int > & buf;
- int value;
-
- recv_data( tsk::bounded_buffer< int > & buf_) :
- buf( buf_), value( 0)
- {}
-
- void operator()( )
- {
- boost::optional< int > res;
- if ( buf.take( res) )
- value = * res;
- }
-};
-
-void test_case_1()
-{
- tsk::bounded_buffer< int > buf( tsk::high_watermark( 10), tsk::low_watermark( 10) );
- BOOST_CHECK_EQUAL( true, buf.empty() );
- BOOST_CHECK_EQUAL( true, buf.active() );
- int n = 1;
- buf.put( n);
- BOOST_CHECK_EQUAL( false, buf.empty() );
- boost::optional< int > res;
- BOOST_CHECK_EQUAL( true, buf.take( res) );
- BOOST_CHECK( res);
- BOOST_CHECK_EQUAL( n, res.get() );
- buf.deactivate();
- BOOST_CHECK_EQUAL( false, buf.active() );
- BOOST_CHECK_THROW( buf.put( 1), tsk::task_rejected);
-}
-
-void test_case_2()
-{
- tsk::bounded_buffer< int > buf( tsk::high_watermark( 10), tsk::low_watermark( 10) );
- BOOST_CHECK_EQUAL( true, buf.empty() );
- BOOST_CHECK_EQUAL( true, buf.active() );
- int n = 1;
- buf.put( n);
- BOOST_CHECK_EQUAL( false, buf.empty() );
- boost::optional< int > res;
- BOOST_CHECK_EQUAL( true, buf.try_take( res) );
- BOOST_CHECK( res);
- BOOST_CHECK_EQUAL( n, res.get() );
- BOOST_CHECK_EQUAL( false, buf.try_take( res) );
- BOOST_CHECK_EQUAL( false, buf.take( res, pt::milliseconds( 10) ) );
-}
-
-void test_case_3()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 2) );
-
- tsk::bounded_buffer< int > buf( tsk::high_watermark( 10), tsk::low_watermark( 10) );
-
- int n = 37;
-
- recv_data receiver( buf);
- BOOST_CHECK_EQUAL( 0, receiver.value);
- tsk::handle< void > h =
- tsk::async(
- tsk::make_task(
- & recv_data::operator(),
- boost::ref( receiver) ),
- pool);
-
- boost::this_thread::sleep(
- pt::milliseconds( 250) );
-
- BOOST_CHECK_EQUAL( false, h.is_ready() );
- buf.put( n);
-
- h.wait();
-
- BOOST_CHECK_EQUAL( n, receiver.value);
-}
-
-void test_case_4()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 2) );
-
- tsk::bounded_buffer< int > buf( tsk::high_watermark( 10), tsk::low_watermark( 10) );
-
- int n = 37;
-
- send_data sender( buf);
- recv_data receiver( buf);
- BOOST_CHECK_EQUAL( 0, receiver.value);
-
- tsk::handle< void > h1 =
- tsk::async(
- tsk::make_task(
- & recv_data::operator(),
- boost::ref( receiver) ),
- pool);
-
- boost::this_thread::sleep(
- pt::milliseconds( 250) );
- BOOST_CHECK_EQUAL( false, h1.is_ready() );
-
- tsk::handle< void > h2 =
- tsk::async(
- tsk::make_task(
- & send_data::operator(),
- boost::ref( sender),
- n),
- pool);
-
- h2.wait();
- BOOST_CHECK_EQUAL( true, h2.is_ready() );
- h1.wait();
- BOOST_CHECK_EQUAL( true, h1.is_ready() );
-
- BOOST_CHECK_EQUAL( n, receiver.value);
-}
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test =
- BOOST_TEST_SUITE("Boost.Task: bounded-buffer test suite");
-
- test->add( BOOST_TEST_CASE( & test_case_1) );
- test->add( BOOST_TEST_CASE( & test_case_2) );
- test->add( BOOST_TEST_CASE( & test_case_3) );
- test->add( BOOST_TEST_CASE( & test_case_4) );
-
- return test;
-}

Deleted: sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,588 +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 <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::tasks;
-
-// check size and move op
-void test_case_1()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool1(
- tsk::poolsize( 3),
- tsk::high_watermark( 10),
- tsk::low_watermark( 5) );
- BOOST_CHECK( pool1);
- BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool1.upper_bound(), std::size_t( 10) );
- BOOST_CHECK_EQUAL( pool1.lower_bound(), std::size_t( 5) );
-
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool2;
- BOOST_CHECK( ! pool2);
- BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool2.upper_bound(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool2.lower_bound(), tsk::pool_moved);
-
- pool2 = boost::move( pool1);
-
- BOOST_CHECK( ! pool1);
- BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool1.upper_bound(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool1.lower_bound(), tsk::pool_moved);
-
- BOOST_CHECK( pool2);
- BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool2.upper_bound(), std::size_t( 10) );
- BOOST_CHECK_EQUAL( pool2.lower_bound(), std::size_t( 5) );
-
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool2) );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check submit
-void test_case_2()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check assignment
-void test_case_3()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h1;
- tsk::handle< int > h2(
- tsk::async( boost::move( t), pool) );
- h1 = h2;
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 55);
-}
-
-// check swap
-void test_case_4()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t1( fibonacci_fn, 5);
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< int > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), pool) );
- BOOST_CHECK_EQUAL( h1.get(), 5);
- BOOST_CHECK_EQUAL( h2.get(), 55);
- BOOST_CHECK_NO_THROW( h1.swap( h2) );
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 5);
-}
-
-// check runs in pool
-void test_case_5()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), true);
-}
-
-// check shutdown
-void test_case_6()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check runtime_error throw inside task
-void test_case_7()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( throwing_fn);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK_THROW( h.get(), std::runtime_error);
-}
-
-// check shutdown with task_rejected exception
-void test_case_8()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_THROW(
- tsk::async( boost::move( t), pool),
- tsk::task_rejected);
-}
-
-// check shutdown_now with thread_interrupted exception
-void test_case_9()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::millisec( 500) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- pool.shutdown_now();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 0) );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check wait
-void test_case_10()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- h.wait();
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check wait_for
-void test_case_11()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.wait_for( pt::seconds( 3) ) );
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_for
-void test_case_12()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.wait_for( pt::seconds( 1) ) );
- BOOST_CHECK( ! h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_for
-void test_case_13()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 3) ) );
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_for
-void test_case_14()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.wait_until( boost::get_system_time() + pt::seconds( 1) ) );
- BOOST_CHECK( ! h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check interrupt
-void test_case_15()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_all_worker
-void test_case_16()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t1( delay_fn, pt::seconds( 3) );
- tsk::task< void > t2( delay_fn, pt::seconds( 3) );
- tsk::task< void > t3( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< void > h2(
- tsk::async( boost::move( t2), pool) );
- tsk::handle< void > h3(
- tsk::async( boost::move( t3), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- pool.interrupt_all_worker();
- BOOST_CHECK( ! h1.interruption_requested() );
- BOOST_CHECK( ! h2.interruption_requested() );
- BOOST_CHECK( ! h3.interruption_requested() );
- BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
-}
-
-// check interrupt_and_wait
-void test_case_17()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt_and_wait();
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_for
-void test_case_18()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 3) ) );
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_for
-void test_case_19()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
-}
-
-// check interrupt_and_wait_until
-void test_case_20()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 3) ) );
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_until
-void test_case_21()
-{
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
-}
-
-// check fifo scheduling
-void test_case_22()
-{
- typedef tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool_type;
- BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), pool);
- tsk::async( boost::move( t3), pool);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 55);
- BOOST_CHECK_EQUAL( buffer[1], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
-}
-
-// check priority scheduling
-void test_case_23()
-{
- typedef tsk::static_pool<
- tsk::bounded_onelock_prio_queue< int >
- > pool_type;
- BOOST_CHECK( tsk::has_attribute< pool_type >::value);
- typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
- BOOST_CHECK( type::value);
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), 0, pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), 1, pool);
- tsk::async( boost::move( t3), 0, pool);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 55);
- BOOST_CHECK_EQUAL( buffer[1], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
-}
-
-// check smart scheduling
-void test_case_24()
-{
- typedef tsk::static_pool<
- tsk::bounded_onelock_smart_queue< int, std::less< int > >
- > pool_type;
- BOOST_CHECK( tsk::has_attribute< pool_type >::value);
- typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
- BOOST_CHECK( type::value);
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1(
- barrier_fn,
- boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::task< void > t4(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 1);
- pool.submit( boost::move( t1), 0);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), 2, pool);
- tsk::async( boost::move( t3), 1, pool);
- tsk::async( boost::move( t4), 2, pool);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 1);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
-}
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test =
- BOOST_TEST_SUITE("Boost.Task: bounded-onelock-pool test suite");
-
- test->add( BOOST_TEST_CASE( & test_case_1) );
- test->add( BOOST_TEST_CASE( & test_case_2) );
- test->add( BOOST_TEST_CASE( & test_case_3) );
- test->add( BOOST_TEST_CASE( & test_case_4) );
- test->add( BOOST_TEST_CASE( & test_case_5) );
- test->add( BOOST_TEST_CASE( & test_case_6) );
- test->add( BOOST_TEST_CASE( & test_case_7) );
- test->add( BOOST_TEST_CASE( & test_case_8) );
- test->add( BOOST_TEST_CASE( & test_case_9) );
- test->add( BOOST_TEST_CASE( & test_case_10) );
- test->add( BOOST_TEST_CASE( & test_case_11) );
- test->add( BOOST_TEST_CASE( & test_case_12) );
- test->add( BOOST_TEST_CASE( & test_case_13) );
- test->add( BOOST_TEST_CASE( & test_case_14) );
- test->add( BOOST_TEST_CASE( & test_case_15) );
- test->add( BOOST_TEST_CASE( & test_case_16) );
- test->add( BOOST_TEST_CASE( & test_case_17) );
- test->add( BOOST_TEST_CASE( & test_case_18) );
- test->add( BOOST_TEST_CASE( & test_case_19) );
- test->add( BOOST_TEST_CASE( & test_case_20) );
- test->add( BOOST_TEST_CASE( & test_case_21) );
- test->add( BOOST_TEST_CASE( & test_case_22) );
- test->add( BOOST_TEST_CASE( & test_case_23) );
- test->add( BOOST_TEST_CASE( & test_case_24) );
-
- return test;
-}
-

Added: sandbox/task/libs/task/test/test_bounded_pool.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_bounded_pool.cpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,509 @@
+
+// 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 <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::tasks;
+
+// check size and move op
+void test_case_1()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool1(
+ tsk::poolsize( 3),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 5) );
+ BOOST_CHECK( pool1);
+ BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool1.upper_bound(), std::size_t( 10) );
+ BOOST_CHECK_EQUAL( pool1.lower_bound(), std::size_t( 5) );
+
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool2;
+ BOOST_CHECK( ! pool2);
+ BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool2.upper_bound(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool2.lower_bound(), tsk::pool_moved);
+
+ pool2 = boost::move( pool1);
+
+ BOOST_CHECK( ! pool1);
+ BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool1.upper_bound(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool1.lower_bound(), tsk::pool_moved);
+
+ BOOST_CHECK( pool2);
+ BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool2.upper_bound(), std::size_t( 10) );
+ BOOST_CHECK_EQUAL( pool2.lower_bound(), std::size_t( 5) );
+
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool2) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check submit
+void test_case_2()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check assignment
+void test_case_3()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t), pool) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+}
+
+// check swap
+void test_case_4()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t1( fibonacci_fn, 5);
+ tsk::task< int > t2( fibonacci_fn, 10);
+ tsk::handle< int > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t2), pool) );
+ BOOST_CHECK_EQUAL( h1.get(), 5);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ BOOST_CHECK_NO_THROW( h1.swap( h2) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 5);
+}
+
+// check runs in pool
+void test_case_5()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< bool > t( runs_in_pool_fn);
+ tsk::handle< bool > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), true);
+}
+
+// check shutdown
+void test_case_6()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check runtime_error throw inside task
+void test_case_7()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( throwing_fn);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK_THROW( h.get(), std::runtime_error);
+}
+
+// check shutdown with task_rejected exception
+void test_case_8()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_THROW(
+ tsk::async( boost::move( t), pool),
+ tsk::task_rejected);
+}
+
+// check shutdown_now with thread_interrupted exception
+void test_case_9()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::millisec( 500) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 0) );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check wait
+void test_case_10()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ h.wait();
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check wait_for
+void test_case_11()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( h.wait_for( pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+}
+
+// check wait_for
+void test_case_12()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.wait_for( pt::seconds( 1) ) );
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+}
+
+// check wait_for
+void test_case_13()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+}
+
+// check wait_for
+void test_case_14()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+}
+
+// check interrupt
+void test_case_15()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_all_worker
+void test_case_16()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t1( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t2( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t3( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< void > h2(
+ tsk::async( boost::move( t2), pool) );
+ tsk::handle< void > h3(
+ tsk::async( boost::move( t3), pool) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ pool.interrupt_all_worker();
+ BOOST_CHECK( ! h1.interruption_requested() );
+ BOOST_CHECK( ! h2.interruption_requested() );
+ BOOST_CHECK( ! h3.interruption_requested() );
+ BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
+}
+
+// check interrupt_and_wait
+void test_case_17()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ h.interrupt_and_wait();
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_and_wait_for
+void test_case_18()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 3) ) );
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_and_wait_for
+void test_case_19()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
+}
+
+// check interrupt_and_wait_until
+void test_case_20()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_and_wait_until
+void test_case_21()
+{
+ tsk::static_pool<
+ tsk::bounded_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+}
+
+// check fifo scheduling
+void test_case_22()
+{
+ typedef tsk::static_pool<
+ tsk::bounded_fifo
+ > pool_type;
+ BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ std::vector< int > buffer;
+ tsk::task< void > t1( barrier_fn, boost::ref( b) );
+ tsk::task< void > t2(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10);
+ tsk::task< void > t3(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0);
+ tsk::async( boost::move( t1), pool);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ tsk::async( boost::move( t2), pool);
+ tsk::async( boost::move( t3), pool);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 55);
+ BOOST_CHECK_EQUAL( buffer[1], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+}
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: bounded-pool test suite");
+
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+ test->add( BOOST_TEST_CASE( & test_case_5) );
+ test->add( BOOST_TEST_CASE( & test_case_6) );
+ test->add( BOOST_TEST_CASE( & test_case_7) );
+ test->add( BOOST_TEST_CASE( & test_case_8) );
+ test->add( BOOST_TEST_CASE( & test_case_9) );
+ test->add( BOOST_TEST_CASE( & test_case_10) );
+ test->add( BOOST_TEST_CASE( & test_case_11) );
+ test->add( BOOST_TEST_CASE( & test_case_12) );
+ test->add( BOOST_TEST_CASE( & test_case_13) );
+ test->add( BOOST_TEST_CASE( & test_case_14) );
+ test->add( BOOST_TEST_CASE( & test_case_15) );
+ test->add( BOOST_TEST_CASE( & test_case_16) );
+ test->add( BOOST_TEST_CASE( & test_case_17) );
+ test->add( BOOST_TEST_CASE( & test_case_18) );
+ test->add( BOOST_TEST_CASE( & test_case_19) );
+ test->add( BOOST_TEST_CASE( & test_case_20) );
+ test->add( BOOST_TEST_CASE( & test_case_21) );
+ test->add( BOOST_TEST_CASE( & test_case_22) );
+
+ return test;
+}
+

Deleted: sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,509 +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 <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::tasks;
-
-// check size and move op
-void test_case_1()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool1(
- tsk::poolsize( 3),
- tsk::high_watermark( 10),
- tsk::low_watermark( 5) );
- BOOST_CHECK( pool1);
- BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool1.upper_bound(), std::size_t( 10) );
- BOOST_CHECK_EQUAL( pool1.lower_bound(), std::size_t( 5) );
-
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool2;
- BOOST_CHECK( ! pool2);
- BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool2.upper_bound(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool2.lower_bound(), tsk::pool_moved);
-
- pool2 = boost::move( pool1);
-
- BOOST_CHECK( ! pool1);
- BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool1.upper_bound(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool1.lower_bound(), tsk::pool_moved);
-
- BOOST_CHECK( pool2);
- BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool2.upper_bound(), std::size_t( 10) );
- BOOST_CHECK_EQUAL( pool2.lower_bound(), std::size_t( 5) );
-
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool2) );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check submit
-void test_case_2()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check assignment
-void test_case_3()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h1;
- tsk::handle< int > h2(
- tsk::async( boost::move( t), pool) );
- h1 = h2;
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 55);
-}
-
-// check swap
-void test_case_4()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t1( fibonacci_fn, 5);
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< int > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), pool) );
- BOOST_CHECK_EQUAL( h1.get(), 5);
- BOOST_CHECK_EQUAL( h2.get(), 55);
- BOOST_CHECK_NO_THROW( h1.swap( h2) );
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 5);
-}
-
-// check runs in pool
-void test_case_5()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), true);
-}
-
-// check shutdown
-void test_case_6()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check runtime_error throw inside task
-void test_case_7()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( throwing_fn);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK_THROW( h.get(), std::runtime_error);
-}
-
-// check shutdown with task_rejected exception
-void test_case_8()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_THROW(
- tsk::async( boost::move( t), pool),
- tsk::task_rejected);
-}
-
-// check shutdown_now with thread_interrupted exception
-void test_case_9()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::millisec( 500) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- pool.shutdown_now();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 0) );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check wait
-void test_case_10()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- h.wait();
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check wait_for
-void test_case_11()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.wait_for( pt::seconds( 3) ) );
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_for
-void test_case_12()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.wait_for( pt::seconds( 1) ) );
- BOOST_CHECK( ! h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_for
-void test_case_13()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 3) ) );
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_for
-void test_case_14()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.wait_until( boost::get_system_time() + pt::seconds( 1) ) );
- BOOST_CHECK( ! h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check interrupt
-void test_case_15()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_all_worker
-void test_case_16()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t1( delay_fn, pt::seconds( 3) );
- tsk::task< void > t2( delay_fn, pt::seconds( 3) );
- tsk::task< void > t3( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< void > h2(
- tsk::async( boost::move( t2), pool) );
- tsk::handle< void > h3(
- tsk::async( boost::move( t3), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- pool.interrupt_all_worker();
- BOOST_CHECK( ! h1.interruption_requested() );
- BOOST_CHECK( ! h2.interruption_requested() );
- BOOST_CHECK( ! h3.interruption_requested() );
- BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
-}
-
-// check interrupt_and_wait
-void test_case_17()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt_and_wait();
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_for
-void test_case_18()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 3) ) );
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_for
-void test_case_19()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
-}
-
-// check interrupt_and_wait_until
-void test_case_20()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 3) ) );
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_until
-void test_case_21()
-{
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
-}
-
-// check fifo scheduling
-void test_case_22()
-{
- typedef tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool_type;
- BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), pool);
- tsk::async( boost::move( t3), pool);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 55);
- BOOST_CHECK_EQUAL( buffer[1], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
-}
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test =
- BOOST_TEST_SUITE("Boost.Task: bounded-twolock-pool test suite");
-
- test->add( BOOST_TEST_CASE( & test_case_1) );
- test->add( BOOST_TEST_CASE( & test_case_2) );
- test->add( BOOST_TEST_CASE( & test_case_3) );
- test->add( BOOST_TEST_CASE( & test_case_4) );
- test->add( BOOST_TEST_CASE( & test_case_5) );
- test->add( BOOST_TEST_CASE( & test_case_6) );
- test->add( BOOST_TEST_CASE( & test_case_7) );
- test->add( BOOST_TEST_CASE( & test_case_8) );
- test->add( BOOST_TEST_CASE( & test_case_9) );
- test->add( BOOST_TEST_CASE( & test_case_10) );
- test->add( BOOST_TEST_CASE( & test_case_11) );
- test->add( BOOST_TEST_CASE( & test_case_12) );
- test->add( BOOST_TEST_CASE( & test_case_13) );
- test->add( BOOST_TEST_CASE( & test_case_14) );
- test->add( BOOST_TEST_CASE( & test_case_15) );
- test->add( BOOST_TEST_CASE( & test_case_16) );
- test->add( BOOST_TEST_CASE( & test_case_17) );
- test->add( BOOST_TEST_CASE( & test_case_18) );
- test->add( BOOST_TEST_CASE( & test_case_19) );
- test->add( BOOST_TEST_CASE( & test_case_20) );
- test->add( BOOST_TEST_CASE( & test_case_21) );
- test->add( BOOST_TEST_CASE( & test_case_22) );
-
- return test;
-}
-

Added: sandbox/task/libs/task/test/test_spin_bounded_channel.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_spin_bounded_channel.cpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,171 @@
+
+// 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 <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/optional.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::tasks;
+
+struct send_data
+{
+ tsk::spin::bounded_channel< int > & buf;
+
+ send_data( tsk::spin::bounded_channel< int > & buf_) :
+ buf( buf_)
+ {}
+
+ void operator()( int value)
+ { buf.put( value); }
+};
+
+struct recv_data
+{
+ tsk::spin::bounded_channel< int > & buf;
+ int value;
+
+ recv_data( tsk::spin::bounded_channel< int > & buf_) :
+ buf( buf_), value( 0)
+ {}
+
+ void operator()( )
+ {
+ boost::optional< int > res;
+ if ( buf.take( res) )
+ value = * res;
+ }
+};
+
+void test_case_1()
+{
+ tsk::spin::bounded_channel< int > buf( tsk::high_watermark( 10), tsk::low_watermark( 10) );
+ BOOST_CHECK_EQUAL( true, buf.empty() );
+ BOOST_CHECK_EQUAL( true, buf.active() );
+ int n = 1;
+ buf.put( n);
+ BOOST_CHECK_EQUAL( false, buf.empty() );
+ boost::optional< int > res;
+ BOOST_CHECK_EQUAL( true, buf.take( res) );
+ BOOST_CHECK( res);
+ BOOST_CHECK_EQUAL( n, res.get() );
+ buf.deactivate();
+ BOOST_CHECK_EQUAL( false, buf.active() );
+ BOOST_CHECK_THROW( buf.put( 1), std::runtime_error);
+}
+
+void test_case_2()
+{
+ tsk::spin::bounded_channel< int > buf( tsk::high_watermark( 10), tsk::low_watermark( 10) );
+ BOOST_CHECK_EQUAL( true, buf.empty() );
+ BOOST_CHECK_EQUAL( true, buf.active() );
+ int n = 1;
+ buf.put( n);
+ BOOST_CHECK_EQUAL( false, buf.empty() );
+ boost::optional< int > res;
+ BOOST_CHECK_EQUAL( true, buf.try_take( res) );
+ BOOST_CHECK( res);
+ BOOST_CHECK_EQUAL( n, res.get() );
+ BOOST_CHECK_EQUAL( false, buf.try_take( res) );
+ BOOST_CHECK_EQUAL( false, buf.take( res, pt::milliseconds( 10) ) );
+}
+
+void test_case_3()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 2) );
+
+ tsk::spin::bounded_channel< int > buf( tsk::high_watermark( 10), tsk::low_watermark( 10) );
+
+ int n = 37;
+
+ recv_data receiver( buf);
+ BOOST_CHECK_EQUAL( 0, receiver.value);
+ tsk::handle< void > h =
+ tsk::async(
+ tsk::make_task(
+ & recv_data::operator(),
+ boost::ref( receiver) ),
+ pool);
+
+ boost::this_thread::sleep(
+ pt::milliseconds( 250) );
+
+ BOOST_CHECK_EQUAL( false, h.is_ready() );
+ buf.put( n);
+
+ h.wait();
+
+ BOOST_CHECK_EQUAL( n, receiver.value);
+}
+
+void test_case_4()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 2) );
+
+ tsk::spin::bounded_channel< int > buf( tsk::high_watermark( 10), tsk::low_watermark( 10) );
+
+ int n = 37;
+
+ send_data sender( buf);
+ recv_data receiver( buf);
+ BOOST_CHECK_EQUAL( 0, receiver.value);
+
+ tsk::handle< void > h1 =
+ tsk::async(
+ tsk::make_task(
+ & recv_data::operator(),
+ boost::ref( receiver) ),
+ pool);
+
+ boost::this_thread::sleep(
+ pt::milliseconds( 250) );
+ BOOST_CHECK_EQUAL( false, h1.is_ready() );
+
+ tsk::handle< void > h2 =
+ tsk::async(
+ tsk::make_task(
+ & send_data::operator(),
+ boost::ref( sender),
+ n),
+ pool);
+
+ h2.wait();
+ BOOST_CHECK_EQUAL( true, h2.is_ready() );
+ h1.wait();
+ BOOST_CHECK_EQUAL( true, h1.is_ready() );
+
+ BOOST_CHECK_EQUAL( n, receiver.value);
+}
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: bounded-buffer test suite");
+
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+
+ return test;
+}

Added: sandbox/task/libs/task/test/test_spin_unbounded_channel.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_spin_unbounded_channel.cpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,171 @@
+
+// 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 <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/optional.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::tasks;
+
+struct send_data
+{
+ tsk::spin::unbounded_channel< int > & buf;
+
+ send_data( tsk::spin::unbounded_channel< int > & buf_) :
+ buf( buf_)
+ {}
+
+ void operator()( int value)
+ { buf.put( value); }
+};
+
+struct recv_data
+{
+ tsk::spin::unbounded_channel< int > & buf;
+ int value;
+
+ recv_data( tsk::spin::unbounded_channel< int > & buf_) :
+ buf( buf_), value( 0)
+ {}
+
+ void operator()( )
+ {
+ boost::optional< int > res;
+ if ( buf.take( res) )
+ value = * res;
+ }
+};
+
+void test_case_1()
+{
+ tsk::spin::unbounded_channel< int > buf;
+ BOOST_CHECK_EQUAL( true, buf.empty() );
+ BOOST_CHECK_EQUAL( true, buf.active() );
+ int n = 1;
+ buf.put( n);
+ BOOST_CHECK_EQUAL( false, buf.empty() );
+ boost::optional< int > res;
+ BOOST_CHECK_EQUAL( true, buf.take( res) );
+ BOOST_CHECK( res);
+ BOOST_CHECK_EQUAL( n, res.get() );
+ buf.deactivate();
+ BOOST_CHECK_EQUAL( false, buf.active() );
+ BOOST_CHECK_THROW( buf.put( 1), std::runtime_error);
+}
+
+void test_case_2()
+{
+ tsk::spin::unbounded_channel< int > buf;
+ BOOST_CHECK_EQUAL( true, buf.empty() );
+ BOOST_CHECK_EQUAL( true, buf.active() );
+ int n = 1;
+ buf.put( n);
+ BOOST_CHECK_EQUAL( false, buf.empty() );
+ boost::optional< int > res;
+ BOOST_CHECK_EQUAL( true, buf.try_take( res) );
+ BOOST_CHECK( res);
+ BOOST_CHECK_EQUAL( n, res.get() );
+ BOOST_CHECK_EQUAL( false, buf.try_take( res) );
+ BOOST_CHECK_EQUAL( false, buf.take( res, pt::milliseconds( 10) ) );
+}
+
+void test_case_3()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 2) );
+
+ tsk::spin::unbounded_channel< int > buf;
+
+ int n = 37;
+
+ recv_data receiver( buf);
+ BOOST_CHECK_EQUAL( 0, receiver.value);
+ tsk::handle< void > h =
+ tsk::async(
+ tsk::make_task(
+ & recv_data::operator(),
+ boost::ref( receiver) ),
+ pool);
+
+ boost::this_thread::sleep(
+ pt::milliseconds( 250) );
+
+ BOOST_CHECK_EQUAL( false, h.is_ready() );
+ buf.put( n);
+
+ h.wait();
+
+ BOOST_CHECK_EQUAL( n, receiver.value);
+}
+
+void test_case_4()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 2) );
+
+ tsk::spin::unbounded_channel< int > buf;
+
+ int n = 37;
+
+ send_data sender( buf);
+ recv_data receiver( buf);
+ BOOST_CHECK_EQUAL( 0, receiver.value);
+
+ tsk::handle< void > h1 =
+ tsk::async(
+ tsk::make_task(
+ & recv_data::operator(),
+ boost::ref( receiver) ),
+ pool);
+
+ boost::this_thread::sleep(
+ pt::milliseconds( 250) );
+ BOOST_CHECK_EQUAL( false, h1.is_ready() );
+
+ tsk::handle< void > h2 =
+ tsk::async(
+ tsk::make_task(
+ & send_data::operator(),
+ boost::ref( sender),
+ n),
+ pool);
+
+ h2.wait();
+ BOOST_CHECK_EQUAL( true, h2.is_ready() );
+ h1.wait();
+ BOOST_CHECK_EQUAL( true, h1.is_ready() );
+
+ BOOST_CHECK_EQUAL( n, receiver.value);
+}
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: unbounded-buffer test suite");
+
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+
+ return test;
+}

Deleted: sandbox/task/libs/task/test/test_unbounded_buffer.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_unbounded_buffer.cpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,171 +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 <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/optional.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::tasks;
-
-struct send_data
-{
- tsk::unbounded_buffer< int > & buf;
-
- send_data( tsk::unbounded_buffer< int > & buf_) :
- buf( buf_)
- {}
-
- void operator()( int value)
- { buf.put( value); }
-};
-
-struct recv_data
-{
- tsk::unbounded_buffer< int > & buf;
- int value;
-
- recv_data( tsk::unbounded_buffer< int > & buf_) :
- buf( buf_), value( 0)
- {}
-
- void operator()( )
- {
- boost::optional< int > res;
- if ( buf.take( res) )
- value = * res;
- }
-};
-
-void test_case_1()
-{
- tsk::unbounded_buffer< int > buf;
- BOOST_CHECK_EQUAL( true, buf.empty() );
- BOOST_CHECK_EQUAL( true, buf.active() );
- int n = 1;
- buf.put( n);
- BOOST_CHECK_EQUAL( false, buf.empty() );
- boost::optional< int > res;
- BOOST_CHECK_EQUAL( true, buf.take( res) );
- BOOST_CHECK( res);
- BOOST_CHECK_EQUAL( n, res.get() );
- buf.deactivate();
- BOOST_CHECK_EQUAL( false, buf.active() );
- BOOST_CHECK_THROW( buf.put( 1), tsk::task_rejected);
-}
-
-void test_case_2()
-{
- tsk::unbounded_buffer< int > buf;
- BOOST_CHECK_EQUAL( true, buf.empty() );
- BOOST_CHECK_EQUAL( true, buf.active() );
- int n = 1;
- buf.put( n);
- BOOST_CHECK_EQUAL( false, buf.empty() );
- boost::optional< int > res;
- BOOST_CHECK_EQUAL( true, buf.try_take( res) );
- BOOST_CHECK( res);
- BOOST_CHECK_EQUAL( n, res.get() );
- BOOST_CHECK_EQUAL( false, buf.try_take( res) );
- BOOST_CHECK_EQUAL( false, buf.take( res, pt::milliseconds( 10) ) );
-}
-
-void test_case_3()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 2) );
-
- tsk::unbounded_buffer< int > buf;
-
- int n = 37;
-
- recv_data receiver( buf);
- BOOST_CHECK_EQUAL( 0, receiver.value);
- tsk::handle< void > h =
- tsk::async(
- tsk::make_task(
- & recv_data::operator(),
- boost::ref( receiver) ),
- pool);
-
- boost::this_thread::sleep(
- pt::milliseconds( 250) );
-
- BOOST_CHECK_EQUAL( false, h.is_ready() );
- buf.put( n);
-
- h.wait();
-
- BOOST_CHECK_EQUAL( n, receiver.value);
-}
-
-void test_case_4()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 2) );
-
- tsk::unbounded_buffer< int > buf;
-
- int n = 37;
-
- send_data sender( buf);
- recv_data receiver( buf);
- BOOST_CHECK_EQUAL( 0, receiver.value);
-
- tsk::handle< void > h1 =
- tsk::async(
- tsk::make_task(
- & recv_data::operator(),
- boost::ref( receiver) ),
- pool);
-
- boost::this_thread::sleep(
- pt::milliseconds( 250) );
- BOOST_CHECK_EQUAL( false, h1.is_ready() );
-
- tsk::handle< void > h2 =
- tsk::async(
- tsk::make_task(
- & send_data::operator(),
- boost::ref( sender),
- n),
- pool);
-
- h2.wait();
- BOOST_CHECK_EQUAL( true, h2.is_ready() );
- h1.wait();
- BOOST_CHECK_EQUAL( true, h1.is_ready() );
-
- BOOST_CHECK_EQUAL( n, receiver.value);
-}
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test =
- BOOST_TEST_SUITE("Boost.Task: unbounded-buffer test suite");
-
- test->add( BOOST_TEST_CASE( & test_case_1) );
- test->add( BOOST_TEST_CASE( & test_case_2) );
- test->add( BOOST_TEST_CASE( & test_case_3) );
- test->add( BOOST_TEST_CASE( & test_case_4) );
-
- return test;
-}

Deleted: sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,511 +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 <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::tasks;
-
-// check size and move op
-void test_case_1()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool1( tsk::poolsize( 3) );
- BOOST_CHECK( pool1);
- BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
-
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool2;
- BOOST_CHECK( ! pool2);
- BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
-
- pool2 = boost::move( pool1);
-
- BOOST_CHECK( ! pool1);
- BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
-
- BOOST_CHECK( pool2);
- BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
-
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool2) );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check submit
-void test_case_2()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check assignment
-void test_case_3()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h1;
- tsk::handle< int > h2(
- tsk::async( boost::move( t), pool) );
- h1 = h2;
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 55);
-}
-
-// check swap
-void test_case_4()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t1( fibonacci_fn, 5);
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< int > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), pool) );
- BOOST_CHECK_EQUAL( h1.get(), 5);
- BOOST_CHECK_EQUAL( h2.get(), 55);
- BOOST_CHECK_NO_THROW( h1.swap( h2) );
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 5);
-}
-
-// check runs in pool
-void test_case_5()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), true);
-}
-
-// check shutdown
-void test_case_6()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check runtime_error throw inside task
-void test_case_7()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< void > t( throwing_fn);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK_THROW( h.get(), std::runtime_error);
-}
-
-// check shutdown with task_rejected exception
-void test_case_8()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_THROW(
- tsk::async( boost::move( t), pool),
- tsk::task_rejected);
-}
-
-// check shutdown_now with thread_interrupted exception
-void test_case_9()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< void > t( delay_fn, pt::millisec( 500) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- pool.shutdown_now();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 0) );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check wait
-void test_case_10()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- h.wait();
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check wait_for
-void test_case_11()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.wait_for( pt::seconds( 3) ) );
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_for
-void test_case_12()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.wait_for( pt::seconds( 1) ) );
- BOOST_CHECK( ! h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_until
-void test_case_13()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 3) ) );
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_until
-void test_case_14()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.wait_until( boost::get_system_time() + pt::seconds( 1) ) );
- BOOST_CHECK( ! h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check interrupt
-void test_case_15()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_all_worker
-void test_case_16()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 5) );
- tsk::task< void > t1( delay_fn, pt::seconds( 3) );
- tsk::task< void > t2( delay_fn, pt::seconds( 3) );
- tsk::task< void > t3( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< void > h2(
- tsk::async( boost::move( t2), pool) );
- tsk::handle< void > h3(
- tsk::async( boost::move( t3), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- pool.interrupt_all_worker();
- BOOST_CHECK( ! h1.interruption_requested() );
- BOOST_CHECK( ! h2.interruption_requested() );
- BOOST_CHECK( ! h3.interruption_requested() );
- BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
-}
-
-// check interrupt_and_wait
-void test_case_17()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt_and_wait();
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_for
-void test_case_18()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 3) ) );
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_for
-void test_case_19()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
-}
-
-// check interrupt_and_wait_until
-void test_case_20()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 3) ) );
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_until
-void test_case_21()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
-}
-
-// check fifo scheduling
-void test_case_22()
-{
- typedef tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool_type;
- BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), pool);
- tsk::async( boost::move( t3), pool);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 55);
- BOOST_CHECK_EQUAL( buffer[1], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
-}
-
-// check priority scheduling
-void test_case_23()
-{
- typedef tsk::static_pool<
- tsk::unbounded_onelock_prio_queue< int >
- > pool_type;
- BOOST_CHECK( tsk::has_attribute< pool_type >::value);
- typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
- BOOST_CHECK( type::value);
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) ;
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), 0, pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), 1, pool);
- tsk::async( boost::move( t3), 0, pool);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 55);
- BOOST_CHECK_EQUAL( buffer[1], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
-}
-
-// check smart scheduling
-void test_case_24()
-{
- typedef tsk::static_pool<
- tsk::unbounded_onelock_smart_queue< int, std::less< int > >
- > pool_type;
- BOOST_CHECK( tsk::has_attribute< pool_type >::value);
- typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
- BOOST_CHECK( type::value);
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::task< void > t4(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 1);
- pool.submit( boost::move( t1), 0);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), 2, pool);
- tsk::async( boost::move( t3), 1, pool);
- tsk::async( boost::move( t4), 2, pool);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 1);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
-}
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test =
- BOOST_TEST_SUITE("Boost.Task: unbounded-onelock-pool test suite");
-
- test->add( BOOST_TEST_CASE( & test_case_1) );
- test->add( BOOST_TEST_CASE( & test_case_2) );
- test->add( BOOST_TEST_CASE( & test_case_3) );
- test->add( BOOST_TEST_CASE( & test_case_4) );
- test->add( BOOST_TEST_CASE( & test_case_5) );
- test->add( BOOST_TEST_CASE( & test_case_6) );
- test->add( BOOST_TEST_CASE( & test_case_7) );
- test->add( BOOST_TEST_CASE( & test_case_8) );
- test->add( BOOST_TEST_CASE( & test_case_9) );
- test->add( BOOST_TEST_CASE( & test_case_10) );
- test->add( BOOST_TEST_CASE( & test_case_11) );
- test->add( BOOST_TEST_CASE( & test_case_12) );
- test->add( BOOST_TEST_CASE( & test_case_13) );
- test->add( BOOST_TEST_CASE( & test_case_14) );
- test->add( BOOST_TEST_CASE( & test_case_15) );
- test->add( BOOST_TEST_CASE( & test_case_16) );
- test->add( BOOST_TEST_CASE( & test_case_17) );
- test->add( BOOST_TEST_CASE( & test_case_18) );
- test->add( BOOST_TEST_CASE( & test_case_19) );
- test->add( BOOST_TEST_CASE( & test_case_20) );
- test->add( BOOST_TEST_CASE( & test_case_21) );
- test->add( BOOST_TEST_CASE( & test_case_22) );
- test->add( BOOST_TEST_CASE( & test_case_23) );
- test->add( BOOST_TEST_CASE( & test_case_24) );
-
- return test;
-}

Added: sandbox/task/libs/task/test/test_unbounded_pool.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_unbounded_pool.cpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
@@ -0,0 +1,440 @@
+
+// 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 <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::tasks;
+
+// check size and move op
+void test_case_1()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool1( tsk::poolsize( 3) );
+ BOOST_CHECK( pool1);
+ BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
+
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool2;
+ BOOST_CHECK( ! pool2);
+ BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
+
+ pool2 = boost::move( pool1);
+
+ BOOST_CHECK( ! pool1);
+ BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
+
+ BOOST_CHECK( pool2);
+ BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
+
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool2) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check submit
+void test_case_2()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check assignment
+void test_case_3()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t), pool) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+}
+
+// check swap
+void test_case_4()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t1( fibonacci_fn, 5);
+ tsk::task< int > t2( fibonacci_fn, 10);
+ tsk::handle< int > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t2), pool) );
+ BOOST_CHECK_EQUAL( h1.get(), 5);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ BOOST_CHECK_NO_THROW( h1.swap( h2) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 5);
+}
+
+// check runs in pool
+void test_case_5()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< bool > t( runs_in_pool_fn);
+ tsk::handle< bool > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), true);
+}
+
+// check shutdown
+void test_case_6()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check runtime_error throw inside task
+void test_case_7()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< void > t( throwing_fn);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK_THROW( h.get(), std::runtime_error);
+}
+
+// check shutdown with task_rejected exception
+void test_case_8()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_THROW(
+ tsk::async( boost::move( t), pool),
+ tsk::task_rejected);
+}
+
+// check shutdown_now with thread_interrupted exception
+void test_case_9()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< void > t( delay_fn, pt::millisec( 500) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 0) );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check wait
+void test_case_10()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ h.wait();
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check wait_for
+void test_case_11()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( h.wait_for( pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+}
+
+// check wait_for
+void test_case_12()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.wait_for( pt::seconds( 1) ) );
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+}
+
+// check wait_until
+void test_case_13()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+}
+
+// check wait_until
+void test_case_14()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+}
+
+// check interrupt
+void test_case_15()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_all_worker
+void test_case_16()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 5) );
+ tsk::task< void > t1( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t2( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t3( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< void > h2(
+ tsk::async( boost::move( t2), pool) );
+ tsk::handle< void > h3(
+ tsk::async( boost::move( t3), pool) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ pool.interrupt_all_worker();
+ BOOST_CHECK( ! h1.interruption_requested() );
+ BOOST_CHECK( ! h2.interruption_requested() );
+ BOOST_CHECK( ! h3.interruption_requested() );
+ BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
+}
+
+// check interrupt_and_wait
+void test_case_17()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ h.interrupt_and_wait();
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_and_wait_for
+void test_case_18()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 3) ) );
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_and_wait_for
+void test_case_19()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
+}
+
+// check interrupt_and_wait_until
+void test_case_20()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_and_wait_until
+void test_case_21()
+{
+ tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+}
+
+// check fifo scheduling
+void test_case_22()
+{
+ typedef tsk::static_pool<
+ tsk::unbounded_fifo
+ > pool_type;
+ BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ std::vector< int > buffer;
+ tsk::task< void > t1( barrier_fn, boost::ref( b) );
+ tsk::task< void > t2(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10);
+ tsk::task< void > t3(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0);
+ tsk::async( boost::move( t1), pool);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ tsk::async( boost::move( t2), pool);
+ tsk::async( boost::move( t3), pool);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 55);
+ BOOST_CHECK_EQUAL( buffer[1], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+}
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: unbounded-pool test suite");
+
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+ test->add( BOOST_TEST_CASE( & test_case_5) );
+ test->add( BOOST_TEST_CASE( & test_case_6) );
+ test->add( BOOST_TEST_CASE( & test_case_7) );
+ test->add( BOOST_TEST_CASE( & test_case_8) );
+ test->add( BOOST_TEST_CASE( & test_case_9) );
+ test->add( BOOST_TEST_CASE( & test_case_10) );
+ test->add( BOOST_TEST_CASE( & test_case_11) );
+ test->add( BOOST_TEST_CASE( & test_case_12) );
+ test->add( BOOST_TEST_CASE( & test_case_13) );
+ test->add( BOOST_TEST_CASE( & test_case_14) );
+ test->add( BOOST_TEST_CASE( & test_case_15) );
+ test->add( BOOST_TEST_CASE( & test_case_16) );
+ test->add( BOOST_TEST_CASE( & test_case_17) );
+ test->add( BOOST_TEST_CASE( & test_case_18) );
+ test->add( BOOST_TEST_CASE( & test_case_19) );
+ test->add( BOOST_TEST_CASE( & test_case_20) );
+ test->add( BOOST_TEST_CASE( & test_case_21) );
+ test->add( BOOST_TEST_CASE( & test_case_22) );
+
+ return test;
+}

Deleted: sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp 2009-12-27 18:10:26 EST (Sun, 27 Dec 2009)
+++ (empty file)
@@ -1,440 +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 <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::tasks;
-
-// check size and move op
-void test_case_1()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool1( tsk::poolsize( 3) );
- BOOST_CHECK( pool1);
- BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
-
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool2;
- BOOST_CHECK( ! pool2);
- BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
-
- pool2 = boost::move( pool1);
-
- BOOST_CHECK( ! pool1);
- BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
-
- BOOST_CHECK( pool2);
- BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
-
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool2) );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check submit
-void test_case_2()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check assignment
-void test_case_3()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h1;
- tsk::handle< int > h2(
- tsk::async( boost::move( t), pool) );
- h1 = h2;
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 55);
-}
-
-// check swap
-void test_case_4()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t1( fibonacci_fn, 5);
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< int > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), pool) );
- BOOST_CHECK_EQUAL( h1.get(), 5);
- BOOST_CHECK_EQUAL( h2.get(), 55);
- BOOST_CHECK_NO_THROW( h1.swap( h2) );
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 5);
-}
-
-// check runs in pool
-void test_case_5()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), true);
-}
-
-// check shutdown
-void test_case_6()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check runtime_error throw inside task
-void test_case_7()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< void > t( throwing_fn);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK_THROW( h.get(), std::runtime_error);
-}
-
-// check shutdown with task_rejected exception
-void test_case_8()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_THROW(
- tsk::async( boost::move( t), pool),
- tsk::task_rejected);
-}
-
-// check shutdown_now with thread_interrupted exception
-void test_case_9()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< void > t( delay_fn, pt::millisec( 500) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- pool.shutdown_now();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 0) );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check wait
-void test_case_10()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- h.wait();
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
- BOOST_CHECK_EQUAL( h.get(), 55);
-}
-
-// check wait_for
-void test_case_11()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.wait_for( pt::seconds( 3) ) );
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_for
-void test_case_12()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.wait_for( pt::seconds( 1) ) );
- BOOST_CHECK( ! h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_until
-void test_case_13()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 3) ) );
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check wait_until
-void test_case_14()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.wait_until( boost::get_system_time() + pt::seconds( 1) ) );
- BOOST_CHECK( ! h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
-}
-
-// check interrupt
-void test_case_15()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_all_worker
-void test_case_16()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 5) );
- tsk::task< void > t1( delay_fn, pt::seconds( 3) );
- tsk::task< void > t2( delay_fn, pt::seconds( 3) );
- tsk::task< void > t3( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< void > h2(
- tsk::async( boost::move( t2), pool) );
- tsk::handle< void > h3(
- tsk::async( boost::move( t3), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- pool.interrupt_all_worker();
- BOOST_CHECK( ! h1.interruption_requested() );
- BOOST_CHECK( ! h2.interruption_requested() );
- BOOST_CHECK( ! h3.interruption_requested() );
- BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
-}
-
-// check interrupt_and_wait
-void test_case_17()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt_and_wait();
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_for
-void test_case_18()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 3) ) );
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_for
-void test_case_19()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
-}
-
-// check interrupt_and_wait_until
-void test_case_20()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 3) ) );
- BOOST_CHECK( finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( h.has_exception() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
-}
-
-// check interrupt_and_wait_until
-void test_case_21()
-{
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
-}
-
-// check fifo scheduling
-void test_case_22()
-{
- typedef tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool_type;
- BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), pool);
- tsk::async( boost::move( t3), pool);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 55);
- BOOST_CHECK_EQUAL( buffer[1], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
-}
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test =
- BOOST_TEST_SUITE("Boost.Task: unbounded-twolock-pool test suite");
-
- test->add( BOOST_TEST_CASE( & test_case_1) );
- test->add( BOOST_TEST_CASE( & test_case_2) );
- test->add( BOOST_TEST_CASE( & test_case_3) );
- test->add( BOOST_TEST_CASE( & test_case_4) );
- test->add( BOOST_TEST_CASE( & test_case_5) );
- test->add( BOOST_TEST_CASE( & test_case_6) );
- test->add( BOOST_TEST_CASE( & test_case_7) );
- test->add( BOOST_TEST_CASE( & test_case_8) );
- test->add( BOOST_TEST_CASE( & test_case_9) );
- test->add( BOOST_TEST_CASE( & test_case_10) );
- test->add( BOOST_TEST_CASE( & test_case_11) );
- test->add( BOOST_TEST_CASE( & test_case_12) );
- test->add( BOOST_TEST_CASE( & test_case_13) );
- test->add( BOOST_TEST_CASE( & test_case_14) );
- test->add( BOOST_TEST_CASE( & test_case_15) );
- test->add( BOOST_TEST_CASE( & test_case_16) );
- test->add( BOOST_TEST_CASE( & test_case_17) );
- test->add( BOOST_TEST_CASE( & test_case_18) );
- test->add( BOOST_TEST_CASE( & test_case_19) );
- test->add( BOOST_TEST_CASE( & test_case_20) );
- test->add( BOOST_TEST_CASE( & test_case_21) );
- test->add( BOOST_TEST_CASE( & test_case_22) );
-
- return test;
-}


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