|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58532 - in sandbox/task: boost boost/task boost/task/detail boost/task/spin libs/task/build libs/task/examples libs/task/examples/sync libs/task/src libs/task/src/spin libs/task/test
From: oliver.kowalke_at_[hidden]
Date: 2009-12-26 17:01:03
Author: olli
Date: 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
New Revision: 58532
URL: http://svn.boost.org/trac/boost/changeset/58532
Log:
- boost.fiber integrated
Added:
sandbox/task/boost/task/spin/
sandbox/task/boost/task/spin/auto_reset_event.hpp (contents, props changed)
sandbox/task/boost/task/spin/barrier.hpp (contents, props changed)
sandbox/task/boost/task/spin/bounded_channel.hpp (contents, props changed)
sandbox/task/boost/task/spin/condition.hpp (contents, props changed)
sandbox/task/boost/task/spin/count_down_event.hpp (contents, props changed)
sandbox/task/boost/task/spin/future.hpp (contents, props changed)
sandbox/task/boost/task/spin/manual_reset_event.hpp (contents, props changed)
sandbox/task/boost/task/spin/mutex.hpp (contents, props changed)
sandbox/task/boost/task/spin/unbounded_channel.hpp (contents, props changed)
sandbox/task/libs/task/examples/sync/ping_pong.cpp (contents, props changed)
sandbox/task/libs/task/src/spin/
sandbox/task/libs/task/src/spin/auto_reset_event.cpp (contents, props changed)
sandbox/task/libs/task/src/spin/barrier.cpp (contents, props changed)
sandbox/task/libs/task/src/spin/condition.cpp (contents, props changed)
sandbox/task/libs/task/src/spin/count_down_event.cpp (contents, props changed)
sandbox/task/libs/task/src/spin/manual_reset_event.cpp (contents, props changed)
sandbox/task/libs/task/src/spin/mutex.cpp (contents, props changed)
Removed:
sandbox/task/boost/task/bounded_buffer.hpp
sandbox/task/boost/task/detail/fiber.hpp
sandbox/task/boost/task/detail/fiber_posix.hpp
sandbox/task/boost/task/detail/fiber_windows.hpp
sandbox/task/boost/task/future.hpp
sandbox/task/boost/task/local_rr_ums.hpp
sandbox/task/boost/task/semaphore.hpp
sandbox/task/boost/task/spin_auto_reset_event.hpp
sandbox/task/boost/task/spin_condition.hpp
sandbox/task/boost/task/spin_count_down_event.hpp
sandbox/task/boost/task/spin_manual_reset_event.hpp
sandbox/task/boost/task/spin_mutex.hpp
sandbox/task/boost/task/spin_unique_lock.hpp
sandbox/task/boost/task/unbounded_buffer.hpp
sandbox/task/libs/task/examples/sync/buffer_ping_pong.cpp
sandbox/task/libs/task/examples/sync/semaphore_ping_pong.cpp
sandbox/task/libs/task/src/semaphore_posix.cpp
sandbox/task/libs/task/src/semaphore_windows.cpp
sandbox/task/libs/task/src/spin_auto_reset_event.cpp
sandbox/task/libs/task/src/spin_condition.cpp
sandbox/task/libs/task/src/spin_count_down_event.cpp
sandbox/task/libs/task/src/spin_manual_reset_event.cpp
sandbox/task/libs/task/src/spin_mutex.cpp
sandbox/task/libs/task/test/test_futures.cpp
sandbox/task/libs/task/test/test_generic_locks.cpp
sandbox/task/libs/task/test/test_semaphore.cpp
sandbox/task/libs/task/test/test_spin_unique_lock.cpp
Text files modified:
sandbox/task/boost/task.hpp | 25 +++---
sandbox/task/boost/task/as_sub_task.hpp | 17 +++-
sandbox/task/boost/task/async.hpp | 8 +-
sandbox/task/boost/task/bounded_onelock_fifo.hpp | 8 +-
sandbox/task/boost/task/bounded_onelock_prio_queue.hpp | 8 +-
sandbox/task/boost/task/bounded_onelock_smart_queue.hpp | 8 +-
sandbox/task/boost/task/bounded_twolock_fifo.hpp | 8 +-
sandbox/task/boost/task/callable.hpp | 10 +-
sandbox/task/boost/task/context.hpp | 10 +-
sandbox/task/boost/task/detail/atomic.hpp | 8 +-
sandbox/task/boost/task/detail/atomic_aix.hpp | 8 +-
sandbox/task/boost/task/detail/atomic_gcc.hpp | 8 +-
sandbox/task/boost/task/detail/atomic_gcc_ppc.hpp | 8 +-
sandbox/task/boost/task/detail/atomic_gcc_x86.hpp | 8 +-
sandbox/task/boost/task/detail/atomic_hpux.hpp | 8 +-
sandbox/task/boost/task/detail/atomic_interlocked.hpp | 8 +-
sandbox/task/boost/task/detail/atomic_interprocess.hpp | 8 +-
sandbox/task/boost/task/detail/atomic_solaris.hpp | 8 +-
sandbox/task/boost/task/detail/atomic_sync.hpp | 8 +-
sandbox/task/boost/task/detail/bind_processor.hpp | 6
sandbox/task/boost/task/detail/bind_processor_aix.hpp | 6
sandbox/task/boost/task/detail/bind_processor_freebsd.hpp | 6
sandbox/task/boost/task/detail/bind_processor_hpux.hpp | 6
sandbox/task/boost/task/detail/bind_processor_linux.hpp | 6
sandbox/task/boost/task/detail/bind_processor_solaris.hpp | 6
sandbox/task/boost/task/detail/bind_processor_windows.hpp | 6
sandbox/task/boost/task/detail/config.hpp | 48 ++++++------
sandbox/task/boost/task/detail/guard.hpp | 10 +-
sandbox/task/boost/task/detail/has_sync.hpp | 18 ++--
sandbox/task/boost/task/detail/meta.hpp | 8 +-
sandbox/task/boost/task/detail/pool_base.hpp | 48 ++++++------
sandbox/task/boost/task/detail/smart.hpp | 4
sandbox/task/boost/task/detail/worker.hpp | 143 ++++++++++++++++++++-------------------
sandbox/task/boost/task/detail/worker_group.hpp | 11 +-
sandbox/task/boost/task/detail/wsq.hpp | 10 +-
sandbox/task/boost/task/exceptions.hpp | 8 +-
sandbox/task/boost/task/handle.hpp | 10 +-
sandbox/task/boost/task/meta.hpp | 8 +-
sandbox/task/boost/task/new_thread.hpp | 10 +-
sandbox/task/boost/task/own_thread.hpp | 10 +-
sandbox/task/boost/task/poolsize.hpp | 10 +-
sandbox/task/boost/task/scanns.hpp | 10 +-
sandbox/task/boost/task/stacksize.hpp | 10 +-
sandbox/task/boost/task/static_pool.hpp | 61 +++-------------
sandbox/task/boost/task/task.hpp | 104 +++++++---------------------
sandbox/task/boost/task/unbounded_onelock_fifo.hpp | 8 +-
sandbox/task/boost/task/unbounded_onelock_prio_queue.hpp | 8 +-
sandbox/task/boost/task/unbounded_onelock_smart_queue.hpp | 8 +-
sandbox/task/boost/task/unbounded_twolock_fifo.hpp | 8 +-
sandbox/task/boost/task/utility.hpp | 12 +-
sandbox/task/boost/task/watermark.hpp | 12 +-
sandbox/task/libs/task/build/Jamfile.v2 | 35 +++++----
sandbox/task/libs/task/examples/Jamfile.v2 | 6
sandbox/task/libs/task/examples/bind_to_processors.cpp | 2
sandbox/task/libs/task/examples/interrupt.cpp | 2
sandbox/task/libs/task/examples/priority.cpp | 2
sandbox/task/libs/task/examples/shutdown_now.cpp | 2
sandbox/task/libs/task/examples/smart.cpp | 2
sandbox/task/libs/task/examples/sub_tasks.cpp | 2
sandbox/task/libs/task/examples/submit.cpp | 2
sandbox/task/libs/task/examples/sync/fork_join_event.cpp | 10 +-
sandbox/task/libs/task/examples/sync/message_passing.cpp | 14 +-
sandbox/task/libs/task/src/callable.cpp | 2
sandbox/task/libs/task/src/context.cpp | 2
sandbox/task/libs/task/src/guard.cpp | 2
sandbox/task/libs/task/src/poolsize.cpp | 2
sandbox/task/libs/task/src/scanns.cpp | 2
sandbox/task/libs/task/src/stacksize.cpp | 2
sandbox/task/libs/task/src/watermark.cpp | 2
sandbox/task/libs/task/src/worker.cpp | 2
sandbox/task/libs/task/src/worker_group.cpp | 2
sandbox/task/libs/task/src/wsq.cpp | 2
sandbox/task/libs/task/test/Jamfile.v2 | 15 +--
sandbox/task/libs/task/test/condition_test_common.hpp | 16 ++--
sandbox/task/libs/task/test/test_as_sub_task.cpp | 2
sandbox/task/libs/task/test/test_bounded_buffer.cpp | 2
sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp | 2
sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp | 2
sandbox/task/libs/task/test/test_functions.hpp | 2
sandbox/task/libs/task/test/test_new_thread.cpp | 2
sandbox/task/libs/task/test/test_own_thread.cpp | 2
sandbox/task/libs/task/test/test_spin_auto_reset_event.cpp | 2
sandbox/task/libs/task/test/test_spin_condition.cpp | 12 +-
sandbox/task/libs/task/test/test_spin_condition_notify_all.cpp | 20 ++--
sandbox/task/libs/task/test/test_spin_condition_notify_one.cpp | 20 ++--
sandbox/task/libs/task/test/test_spin_condition_timed_wait_times_out.cpp | 50 ++++++------
sandbox/task/libs/task/test/test_spin_count_down_event.cpp | 2
sandbox/task/libs/task/test/test_spin_manual_reset_event.cpp | 2
sandbox/task/libs/task/test/test_spin_mutex.cpp | 6
sandbox/task/libs/task/test/test_task.cpp | 2
sandbox/task/libs/task/test/test_unbounded_buffer.cpp | 2
sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp | 2
sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp | 2
93 files changed, 501 insertions(+), 586 deletions(-)
Modified: sandbox/task/boost/task.hpp
==============================================================================
--- sandbox/task/boost/task.hpp (original)
+++ sandbox/task/boost/task.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,12 +4,11 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_H
-#define BOOST_TASK_H
+#ifndef BOOST_TASKS_H
+#define BOOST_TASKS_H
#include <boost/task/as_sub_task.hpp>
#include <boost/task/async.hpp>
-#include <boost/task/bounded_buffer.hpp>
#include <boost/task/bounded_onelock_fifo.hpp>
#include <boost/task/bounded_onelock_prio_queue.hpp>
#include <boost/task/bounded_onelock_smart_queue.hpp>
@@ -17,25 +16,23 @@
#include <boost/task/callable.hpp>
#include <boost/task/context.hpp>
#include <boost/task/exceptions.hpp>
-#include <boost/task/future.hpp>
#include <boost/task/handle.hpp>
-#include <boost/task/local_rr_ums.hpp>
#include <boost/task/meta.hpp>
#include <boost/task/new_thread.hpp>
#include <boost/task/own_thread.hpp>
#include <boost/task/poolsize.hpp>
#include <boost/task/scanns.hpp>
-#include <boost/task/semaphore.hpp>
-#include <boost/task/spin_auto_reset_event.hpp>
-#include <boost/task/spin_condition.hpp>
-#include <boost/task/spin_count_down_event.hpp>
-#include <boost/task/spin_manual_reset_event.hpp>
-#include <boost/task/spin_mutex.hpp>
-#include <boost/task/spin_unique_lock.hpp>
+#include <boost/task/spin/auto_reset_event.hpp>
+#include <boost/task/spin/barrier.hpp>
+#include <boost/task/spin/bounded_channel.hpp>
+#include <boost/task/spin/condition.hpp>
+#include <boost/task/spin/count_down_event.hpp>
+#include <boost/task/spin/manual_reset_event.hpp>
+#include <boost/task/spin/mutex.hpp>
+#include <boost/task/spin/unbounded_channel.hpp>
#include <boost/task/stacksize.hpp>
#include <boost/task/static_pool.hpp>
#include <boost/task/task.hpp>
-#include <boost/task/unbounded_buffer.hpp>
#include <boost/task/unbounded_onelock_fifo.hpp>
#include <boost/task/unbounded_onelock_prio_queue.hpp>
#include <boost/task/unbounded_onelock_smart_queue.hpp>
@@ -43,5 +40,5 @@
#include <boost/task/utility.hpp>
#include <boost/task/watermark.hpp>
-#endif // BOOST_TASK_H
+#endif // BOOST_TASKS_H
Modified: sandbox/task/boost/task/as_sub_task.hpp
==============================================================================
--- sandbox/task/boost/task/as_sub_task.hpp (original)
+++ sandbox/task/boost/task/as_sub_task.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_AS_SUB_TASK_H
-#define BOOST_TASK_AS_SUB_TASK_H
+#ifndef BOOST_TASKS_AS_SUB_TASK_H
+#define BOOST_TASKS_AS_SUB_TASK_H
#include <boost/bind.hpp>
#include <boost/config.hpp>
@@ -17,7 +17,7 @@
#include <boost/task/callable.hpp>
#include <boost/task/context.hpp>
#include <boost/task/detail/worker.hpp>
-#include <boost/task/future.hpp>
+#include <boost/thread/future.hpp>
#include <boost/task/handle.hpp>
#include <boost/task/new_thread.hpp>
#include <boost/task/task.hpp>
@@ -25,7 +25,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace {
template< typename R >
@@ -33,7 +33,12 @@
{
shared_ptr< shared_future< R > > sptr = wptr.lock();
BOOST_ASSERT( sptr);
- return sptr->is_ready();
+ bool res = sptr->is_ready();
+ if ( res)
+ fprintf(stdout,"future is ready\n");
+ else
+ fprintf(stdout,"future is not ready\n");
+ return res;
}
}
@@ -72,4 +77,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_AS_SUB_TASK_H
+#endif // BOOST_TASKS_AS_SUB_TASK_H
Modified: sandbox/task/boost/task/async.hpp
==============================================================================
--- sandbox/task/boost/task/async.hpp (original)
+++ sandbox/task/boost/task/async.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_ASYNC_H
-#define BOOST_TASK_ASYNC_H
+#ifndef BOOST_TASKS_ASYNC_H
+#define BOOST_TASKS_ASYNC_H
#include <boost/config.hpp>
#include <boost/thread/detail/move.hpp>
@@ -18,7 +18,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
template< typename R >
handle< R > async( task< R > t)
@@ -40,4 +40,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_ASYNC_H
+#endif // BOOST_TASKS_ASYNC_H
Deleted: sandbox/task/boost/task/bounded_buffer.hpp
==============================================================================
--- sandbox/task/boost/task/bounded_buffer.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,369 +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_TASK_BOUNDED_BUFFER_H
-#define BOOST_TASK_BOUNDED_BUFFER_H
-
-#include <cstddef>
-#include <deque>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/optional.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/exceptions.hpp>
-#include <boost/task/semaphore.hpp>
-#include <boost/task/spin_condition.hpp>
-#include <boost/task/spin_unique_lock.hpp>
-#include <boost/task/spin_mutex.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace task {
-
-template< typename T >
-class bounded_buffer
-{
-private:
- typedef T value_type;
-
- class base
- {
- private:
- volatile uint32_t state_;
- std::deque< value_type > queue_;
- spin_mutex mtx_;
- spin_condition not_empty_cond_;
- spin_condition not_full_cond_;
- std::size_t hwm_;
- std::size_t lwm_;
-
- base( base &);
-
- base & operator=( base const&);
-
- 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,
- spin_unique_lock< spin_mutex > & lk)
- {
- if ( full_() )
- {
- not_full_cond_.wait(
- lk,
- bind(
- & base::producers_activate_,
- this) );
- }
- if ( ! active_() )
- throw task_rejected("queue is not active");
- queue_.push_back( va);
- not_empty_cond_.notify_one();
- }
-
- template< typename TimeDuration >
- void put_(
- value_type const& va,
- TimeDuration const& rel_time,
- spin_unique_lock< spin_mutex > & lk)
- {
- if ( full_() )
- {
- if ( ! not_full_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & base::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_(
- optional< value_type > & va,
- spin_unique_lock< spin_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- not_empty_cond_.wait(
- lk,
- bind(
- & base::consumers_activate_,
- this) );
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va = 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;
- }
-
- template< typename TimeDuration >
- bool take_(
- optional< value_type > & va,
- TimeDuration const& rel_time,
- spin_unique_lock< spin_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- if ( ! not_empty_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & base::consumers_activate_,
- this) ) )
- return false;
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va = 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;
- }
-
- bool try_take_( optional< value_type > & va)
- {
- if ( empty_() )
- return false;
- va = queue_.front();
- queue_.pop_front();
- bool valid = va;
- 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:
- base(
- high_watermark const& hwm,
- low_watermark const& lwm) :
- state_( 0),
- queue_(),
- mtx_(),
- not_empty_cond_(),
- not_full_cond_(),
- hwm_( hwm),
- lwm_( lwm)
- {}
-
- bool active()
- { return active_(); }
-
- void deactivate()
- { deactivate_(); }
-
- bool empty()
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- return empty_();
- }
-
- std::size_t upper_bound()
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- return hwm_;
- }
-
- void upper_bound( std::size_t hwm)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- upper_bound_( hwm);
- }
-
- std::size_t lower_bound()
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- return lwm_;
- }
-
- void lower_bound( std::size_t lwm)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- lower_bound_( lwm);
- }
-
- void put( value_type const& va)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- put_( va, lk);
- }
-
- template< typename TimeDuration >
- void put(
- value_type const& va,
- TimeDuration const& rel_time)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- put_( va, rel_time, lk);
- }
-
- bool take( optional< value_type > & va)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- return take_( va, lk);
- }
-
- template< typename TimeDuration >
- bool take(
- optional< value_type > & va,
- TimeDuration const& rel_time)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- return take_( va, rel_time, lk);
- }
-
- bool try_take( optional< value_type > & va)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- return try_take_( va);
- }
- };
-
- shared_ptr< base > impl_;
-
-public:
- bounded_buffer(
- high_watermark const& hwm,
- low_watermark const& lwm) :
- impl_( new base( hwm, lwm) )
- {}
-
- bool active()
- { return impl_->active(); }
-
- void deactivate()
- { impl_->deactivate(); }
-
- bool empty()
- { return impl_->empty(); }
-
- std::size_t upper_bound()
- { return impl_->upper_bound(); }
-
- void upper_bound( std::size_t hwm)
- { impl_->upper_bound( hwm); }
-
- std::size_t lower_bound()
- { return impl_->lower_bound; }
-
- void lower_bound( std::size_t lwm)
- { impl_->lower_bound( lwm); }
-
- void put( T const& t)
- { impl_->put( t); }
-
- template< typename TimeDuration >
- void put(
- value_type const& va,
- TimeDuration const& rel_time)
- { impl_->put( va, rel_time); }
-
- bool take( optional< T > & t)
- { return impl_->take( t); }
-
- template< typename TimeDuration >
- bool take(
- optional< T > & t,
- TimeDuration const& rel_time)
- { return impl_->take( t, rel_time); }
-
- bool try_take( optional< T > & t)
- { return impl_->try_take( t); }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASK_BOUNDED_BUFFER_H
Modified: sandbox/task/boost/task/bounded_onelock_fifo.hpp
==============================================================================
--- sandbox/task/boost/task/bounded_onelock_fifo.hpp (original)
+++ sandbox/task/boost/task/bounded_onelock_fifo.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_BOUNDED_ONELOCK_FIFO_H
-#define BOOST_TASK_BOUNDED_ONELOCK_FIFO_H
+#ifndef BOOST_TASKS_BOUNDED_ONELOCK_FIFO_H
+#define BOOST_TASKS_BOUNDED_ONELOCK_FIFO_H
#include <cstddef>
#include <list>
@@ -26,7 +26,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
class bounded_onelock_fifo
{
@@ -309,4 +309,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_BOUNDED_ONELOCK_FIFO_H
+#endif // BOOST_TASKS_BOUNDED_ONELOCK_FIFO_H
Modified: sandbox/task/boost/task/bounded_onelock_prio_queue.hpp
==============================================================================
--- sandbox/task/boost/task/bounded_onelock_prio_queue.hpp (original)
+++ sandbox/task/boost/task/bounded_onelock_prio_queue.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_BOUNDED_ONELOCK_PRIO_QUEUE_H
-#define BOOST_TASK_BOUNDED_ONELOCK_PRIO_QUEUE_H
+#ifndef BOOST_TASKS_BOUNDED_ONELOCK_PRIO_QUEUE_H
+#define BOOST_TASKS_BOUNDED_ONELOCK_PRIO_QUEUE_H
#include <algorithm>
#include <cstddef>
@@ -28,7 +28,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
template<
typename Attr,
@@ -346,4 +346,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_BOUNDED_ONELOCK_PRIO_QUEUE_H
+#endif // BOOST_TASKS_BOUNDED_ONELOCK_PRIO_QUEUE_H
Modified: sandbox/task/boost/task/bounded_onelock_smart_queue.hpp
==============================================================================
--- sandbox/task/boost/task/bounded_onelock_smart_queue.hpp (original)
+++ sandbox/task/boost/task/bounded_onelock_smart_queue.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_BOUNDED_ONELOCK_SMART_QUEUE_H
-#define BOOST_TASK_BOUNDED_ONELOCK_SMART_QUEUE_H
+#ifndef BOOST_TASKS_BOUNDED_ONELOCK_SMART_QUEUE_H
+#define BOOST_TASKS_BOUNDED_ONELOCK_SMART_QUEUE_H
#include <algorithm>
#include <cstddef>
@@ -30,7 +30,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
template<
typename Attr,
@@ -353,4 +353,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_BOUNDED_ONELOCK_SMART_QUEUE_H
+#endif // BOOST_TASKS_BOUNDED_ONELOCK_SMART_QUEUE_H
Modified: sandbox/task/boost/task/bounded_twolock_fifo.hpp
==============================================================================
--- sandbox/task/boost/task/bounded_twolock_fifo.hpp (original)
+++ sandbox/task/boost/task/bounded_twolock_fifo.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_BOUNDED_TWOLOCK_FIFO_H
-#define BOOST_TASK_BOUNDED_TWOLOCK_FIFO_H
+#ifndef BOOST_TASKS_BOUNDED_TWOLOCK_FIFO_H
+#define BOOST_TASKS_BOUNDED_TWOLOCK_FIFO_H
#include <cstddef>
@@ -26,7 +26,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
class bounded_twolock_fifo
{
@@ -274,4 +274,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_BOUNDED_TWOLOCK_FIFO_H
+#endif // BOOST_TASKS_BOUNDED_TWOLOCK_FIFO_H
Modified: sandbox/task/boost/task/callable.hpp
==============================================================================
--- sandbox/task/boost/task/callable.hpp (original)
+++ sandbox/task/boost/task/callable.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_CALLABLE_H
-#define BOOST_TASK_CALLABLE_H
+#ifndef BOOST_TASKS_CALLABLE_H
+#define BOOST_TASKS_CALLABLE_H
#include <boost/config.hpp>
#include <boost/shared_ptr.hpp>
@@ -23,9 +23,9 @@
# endif
namespace boost {
-namespace task {
+namespace tasks {
-class BOOST_TASK_DECL callable
+class BOOST_TASKS_DECL callable
{
private:
struct impl
@@ -101,5 +101,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_CALLABLE_H
+#endif // BOOST_TASKS_CALLABLE_H
Modified: sandbox/task/boost/task/context.hpp
==============================================================================
--- sandbox/task/boost/task/context.hpp (original)
+++ sandbox/task/boost/task/context.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_CONTEXT_H
-#define BOOST_TASK_CONTEXT_H
+#ifndef BOOST_TASKS_CONTEXT_H
+#define BOOST_TASKS_CONTEXT_H
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
@@ -25,9 +25,9 @@
# endif
namespace boost {
-namespace task {
+namespace tasks {
-class BOOST_TASK_DECL context
+class BOOST_TASKS_DECL context
{
private:
class impl : private noncopyable
@@ -73,4 +73,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_context_H
+#endif // BOOST_TASKS_DETAIL_context_H
Modified: sandbox/task/boost/task/detail/atomic.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic.hpp (original)
+++ sandbox/task/boost/task/detail/atomic.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_ATOMIC_H
-#define BOOST_TASK_DETAIL_ATOMIC_H
+#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)
@@ -25,7 +25,7 @@
# elif defined( __GNUC__ ) && ( defined(__PPC__) || defined(__ppc__) )
#include <boost/task/detail/atomic_gcc_ppc.hpp>
-# elif defined( BOOST_TASK_HAS_SYNC)
+# elif defined( BOOST_TASKS_HAS_SYNC)
#include <boost/task/detail/atomic_sync.hpp>
# elif defined(__GLIBCPP__) || defined(__GLIBCXX__)
@@ -45,5 +45,5 @@
# endif
-#endif // BOOST_TASK_DETAIL_ATOMIC_H
+#endif // BOOST_TASKS_DETAIL_ATOMIC_H
Modified: sandbox/task/boost/task/detail/atomic_aix.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_aix.hpp (original)
+++ sandbox/task/boost/task/detail/atomic_aix.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_ATOMIC_AIX_H
-#define BOOST_TASK_DETAIL_ATOMIC_AIX_H
+#ifndef BOOST_TASKS_DETAIL_ATOMIC_AIX_H
+#define BOOST_TASKS_DETAIL_ATOMIC_AIX_H
extern "C"
{
@@ -18,7 +18,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
inline
@@ -51,5 +51,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_ATOMIC_AIX_H
+#endif // BOOST_TASKS_DETAIL_ATOMIC_AIX_H
Modified: sandbox/task/boost/task/detail/atomic_gcc.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_gcc.hpp (original)
+++ sandbox/task/boost/task/detail/atomic_gcc.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_ATOMIC_GCC_H
-#define BOOST_TASK_DETAIL_ATOMIC_GCC_H
+#ifndef BOOST_TASKS_DETAIL_ATOMIC_GCC_H
+#define BOOST_TASKS_DETAIL_ATOMIC_GCC_H
// based on boost/smart_ptr/detail/atomic_count_gcc.hpp
@@ -22,7 +22,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
#if defined(__GLIBCXX__) // g++ 3.4+
@@ -73,5 +73,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_ATOMIC_GCC_H
+#endif // BOOST_TASKS_DETAIL_ATOMIC_GCC_H
Modified: sandbox/task/boost/task/detail/atomic_gcc_ppc.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_gcc_ppc.hpp (original)
+++ sandbox/task/boost/task/detail/atomic_gcc_ppc.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_ATOMIC_GCC_PPC_H
-#define BOOST_TASK_DETAIL_ATOMIC_GCC_PPC_H
+#ifndef BOOST_TASKS_DETAIL_ATOMIC_GCC_PPC_H
+#define BOOST_TASKS_DETAIL_ATOMIC_GCC_PPC_H
#include <boost/assert.hpp>
#include <boost/cstdint.hpp>
@@ -13,7 +13,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
inline
@@ -110,5 +110,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_ATOMIC_GCC_PPC_H
+#endif // BOOST_TASKS_DETAIL_ATOMIC_GCC_PPC_H
Modified: sandbox/task/boost/task/detail/atomic_gcc_x86.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_gcc_x86.hpp (original)
+++ sandbox/task/boost/task/detail/atomic_gcc_x86.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_ATOMIC_GCC_X86_H
-#define BOOST_TASK_DETAIL_ATOMIC_GCC_X86_H
+#ifndef BOOST_TASKS_DETAIL_ATOMIC_GCC_X86_H
+#define BOOST_TASKS_DETAIL_ATOMIC_GCC_X86_H
#include <boost/assert.hpp>
#include <boost/cstdint.hpp>
@@ -13,7 +13,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
inline
@@ -87,5 +87,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_ATOMIC_GCC_X86_H
+#endif // BOOST_TASKS_DETAIL_ATOMIC_GCC_X86_H
Modified: sandbox/task/boost/task/detail/atomic_hpux.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_hpux.hpp (original)
+++ sandbox/task/boost/task/detail/atomic_hpux.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_ATOMIC_HPUX_H
-#define BOOST_TASK_DETAIL_ATOMIC_HPUX_H
+#ifndef BOOST_TASKS_DETAIL_ATOMIC_HPUX_H
+#define BOOST_TASKS_DETAIL_ATOMIC_HPUX_H
extern "C"
{
@@ -17,7 +17,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
inline
@@ -58,5 +58,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_ATOMIC_HPUX_H
+#endif // BOOST_TASKS_DETAIL_ATOMIC_HPUX_H
Modified: sandbox/task/boost/task/detail/atomic_interlocked.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_interlocked.hpp (original)
+++ sandbox/task/boost/task/detail/atomic_interlocked.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_ATOMIC_INTERLOCKED_H
-#define BOOST_TASK_DETAIL_ATOMIC_INTERLOCKED_H
+#ifndef BOOST_TASKS_DETAIL_ATOMIC_INTERLOCKED_H
+#define BOOST_TASKS_DETAIL_ATOMIC_INTERLOCKED_H
#include <boost/assert.hpp>
#include <boost/cstdint.hpp>
@@ -14,7 +14,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
inline
@@ -62,5 +62,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_ATOMIC_INTERLOCKED_H
+#endif // BOOST_TASKS_DETAIL_ATOMIC_INTERLOCKED_H
Modified: sandbox/task/boost/task/detail/atomic_interprocess.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_interprocess.hpp (original)
+++ sandbox/task/boost/task/detail/atomic_interprocess.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_ATOMIC_INTERPROCESS_H
-#define BOOST_TASK_DETAIL_ATOMIC_INTERPROCESS_H
+#ifndef BOOST_TASKS_DETAIL_ATOMIC_INTERPROCESS_H
+#define BOOST_TASKS_DETAIL_ATOMIC_INTERPROCESS_H
#include <boost/assert.hpp>
#include <boost/cstdint.hpp>
@@ -14,7 +14,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
inline
@@ -55,5 +55,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_ATOMIC_INTERPROCESS_H
+#endif // BOOST_TASKS_DETAIL_ATOMIC_INTERPROCESS_H
Modified: sandbox/task/boost/task/detail/atomic_solaris.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_solaris.hpp (original)
+++ sandbox/task/boost/task/detail/atomic_solaris.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_ATOMIC_SOLARIS_H
-#define BOOST_TASK_DETAIL_ATOMIC_SOLARIS_H
+#ifndef BOOST_TASKS_DETAIL_ATOMIC_SOLARIS_H
+#define BOOST_TASKS_DETAIL_ATOMIC_SOLARIS_H
extern "C"
{
@@ -18,7 +18,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
inline
@@ -59,5 +59,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_ATOMIC_SOLARIS_H
+#endif // BOOST_TASKS_DETAIL_ATOMIC_SOLARIS_H
Modified: sandbox/task/boost/task/detail/atomic_sync.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic_sync.hpp (original)
+++ sandbox/task/boost/task/detail/atomic_sync.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_ATOMIC_SYNC_H
-#define BOOST_TASK_DETAIL_ATOMIC_SYNC_H
+#ifndef BOOST_TASKS_DETAIL_ATOMIC_SYNC_H
+#define BOOST_TASKS_DETAIL_ATOMIC_SYNC_H
// based on boost/smart_ptr/detail/atomic_count_gc.hpp
@@ -22,7 +22,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
inline
@@ -63,5 +63,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_ATOMIC_SYNC_H
+#endif // BOOST_TASKS_DETAIL_ATOMIC_SYNC_H
Modified: sandbox/task/boost/task/detail/bind_processor.hpp
==============================================================================
--- sandbox/task/boost/task/detail/bind_processor.hpp (original)
+++ sandbox/task/boost/task/detail/bind_processor.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_BIND_PROCESSOR_H
-#define BOOST_TASK_DETAIL_BIND_PROCESSOR_H
+#ifndef BOOST_TASKS_DETAIL_BIND_PROCESSOR_H
+#define BOOST_TASKS_DETAIL_BIND_PROCESSOR_H
#include <boost/task/detail/config.hpp>
@@ -34,4 +34,4 @@
# undef BOOST_HAS_PROCESSOR_BINDINGS
# endif
-#endif // BOOST_TASK_DETAIL_BIND_PROCESSOR_H
+#endif // BOOST_TASKS_DETAIL_BIND_PROCESSOR_H
Modified: sandbox/task/boost/task/detail/bind_processor_aix.hpp
==============================================================================
--- sandbox/task/boost/task/detail/bind_processor_aix.hpp (original)
+++ sandbox/task/boost/task/detail/bind_processor_aix.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_BIND_PROCESSOR_AIX_H
-#define BOOST_TASK_DETAIL_BIND_PROCESSOR_AIX_H
+#ifndef BOOST_TASKS_DETAIL_BIND_PROCESSOR_AIX_H
+#define BOOST_TASKS_DETAIL_BIND_PROCESSOR_AIX_H
extern "C"
{
@@ -49,4 +49,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_BIND_PROCESSOR_AIX_H
+#endif // BOOST_TASKS_DETAIL_BIND_PROCESSOR_AIX_H
Modified: sandbox/task/boost/task/detail/bind_processor_freebsd.hpp
==============================================================================
--- sandbox/task/boost/task/detail/bind_processor_freebsd.hpp (original)
+++ sandbox/task/boost/task/detail/bind_processor_freebsd.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_BIND_PROCESSOR_FREEBSD_H
-#define BOOST_TASK_DETAIL_BIND_PROCESSOR_FREEBSD_H
+#ifndef BOOST_TASKS_DETAIL_BIND_PROCESSOR_FREEBSD_H
+#define BOOST_TASKS_DETAIL_BIND_PROCESSOR_FREEBSD_H
extern "C"
{
@@ -60,4 +60,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_BIND_PROCESSOR_FREEBSD_H
+#endif // BOOST_TASKS_DETAIL_BIND_PROCESSOR_FREEBSD_H
Modified: sandbox/task/boost/task/detail/bind_processor_hpux.hpp
==============================================================================
--- sandbox/task/boost/task/detail/bind_processor_hpux.hpp (original)
+++ sandbox/task/boost/task/detail/bind_processor_hpux.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_BIND_PROCESSOR_HPUX_H
-#define BOOST_TASK_DETAIL_BIND_PROCESSOR_HPUX_H
+#ifndef BOOST_TASKS_DETAIL_BIND_PROCESSOR_HPUX_H
+#define BOOST_TASKS_DETAIL_BIND_PROCESSOR_HPUX_H
extern "C"
{
@@ -62,4 +62,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_BIND_PROCESSOR_HPUX_H
+#endif // BOOST_TASKS_DETAIL_BIND_PROCESSOR_HPUX_H
Modified: sandbox/task/boost/task/detail/bind_processor_linux.hpp
==============================================================================
--- sandbox/task/boost/task/detail/bind_processor_linux.hpp (original)
+++ sandbox/task/boost/task/detail/bind_processor_linux.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_BIND_PRCESSOR_LINUX_H
-#define BOOST_TASK_DETAIL_BIND_PRCESSOR_LINUX_H
+#ifndef BOOST_TASKS_DETAIL_BIND_PRCESSOR_LINUX_H
+#define BOOST_TASKS_DETAIL_BIND_PRCESSOR_LINUX_H
extern "C"
{
@@ -63,4 +63,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_BIND_PRCESSOR_LINUX_H
+#endif // BOOST_TASKS_DETAIL_BIND_PRCESSOR_LINUX_H
Modified: sandbox/task/boost/task/detail/bind_processor_solaris.hpp
==============================================================================
--- sandbox/task/boost/task/detail/bind_processor_solaris.hpp (original)
+++ sandbox/task/boost/task/detail/bind_processor_solaris.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_BIND_PROCESSOR_SOLARIS_H
-#define BOOST_TASK_DETAIL_BIND_PROCESSOR_SOLARIS_H
+#ifndef BOOST_TASKS_DETAIL_BIND_PROCESSOR_SOLARIS_H
+#define BOOST_TASKS_DETAIL_BIND_PROCESSOR_SOLARIS_H
extern "C"
{
@@ -50,4 +50,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_BIND_PROCESSOR_SOLARIS_H
+#endif // BOOST_TASKS_DETAIL_BIND_PROCESSOR_SOLARIS_H
Modified: sandbox/task/boost/task/detail/bind_processor_windows.hpp
==============================================================================
--- sandbox/task/boost/task/detail/bind_processor_windows.hpp (original)
+++ sandbox/task/boost/task/detail/bind_processor_windows.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_BIND_PROCESSOR_WINDOWS_H
-#define BOOST_TASK_DETAIL_BIND_PROCESSOR_WINDOWS_H
+#ifndef BOOST_TASKS_DETAIL_BIND_PROCESSOR_WINDOWS_H
+#define BOOST_TASKS_DETAIL_BIND_PROCESSOR_WINDOWS_H
extern "C"
{
@@ -52,4 +52,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_BIND_PROCESSOR_WINDOWS_H
+#endif // BOOST_TASKS_DETAIL_BIND_PROCESSOR_WINDOWS_H
Modified: sandbox/task/boost/task/detail/config.hpp
==============================================================================
--- sandbox/task/boost/task/detail/config.hpp (original)
+++ sandbox/task/boost/task/detail/config.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -6,8 +6,8 @@
// this file is based on config.hpp of boost.thread
-#ifndef BOOST_TASK_DETAIL_CONFIG_H
-#define BOOST_TASK_DETAIL_CONFIG_H
+#ifndef BOOST_TASKS_DETAIL_CONFIG_H
+#define BOOST_TASKS_DETAIL_CONFIG_H
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
@@ -19,9 +19,9 @@
# pragma warn -8066 // Unreachable code
# endif
-# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_TASK_DYN_LINK)
-# undef BOOST_TASK_USE_LIB
-# define BOOST_TASK_USE_DLL
+# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_TASKS_DYN_LINK)
+# undef BOOST_TASKS_USE_LIB
+# define BOOST_TASKS_USE_DLL
# endif
# if defined(BOOST_WINDOWS_API) && defined(BOOST_POSIX_API)
@@ -34,49 +34,49 @@
# endif
# endif
-# if defined(BOOST_TASK_BUILD_DLL) //Build dll
-# elif defined(BOOST_TASK_BUILD_LIB) //Build lib
-# elif defined(BOOST_TASK_USE_DLL) //Use dll
-# elif defined(BOOST_TASK_USE_LIB) //Use lib
+# if defined(BOOST_TASKS_BUILD_DLL) //Build dll
+# elif defined(BOOST_TASKS_BUILD_LIB) //Build lib
+# elif defined(BOOST_TASKS_USE_DLL) //Use dll
+# elif defined(BOOST_TASKS_USE_LIB) //Use lib
# else //Use default
-# if defined(BOOST_TASK_PLATFORM_WIN32)
+# if defined(BOOST_TASKS_PLATFORM_WIN32)
# if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN)
//For compilers supporting auto-tss cleanup
//with Boost.Threads lib, use Boost.Threads lib
-# define BOOST_TASK_USE_LIB
+# define BOOST_TASKS_USE_LIB
# else
//For compilers not yet supporting auto-tss cleanup
//with Boost.Threads lib, use Boost.Threads dll
-# define BOOST_TASK_USE_DLL
+# define BOOST_TASKS_USE_DLL
# endif
# else
-# define BOOST_TASK_USE_LIB
+# define BOOST_TASKS_USE_LIB
# endif
# endif
# if defined(BOOST_HAS_DECLSPEC)
-# if defined(BOOST_TASK_BUILD_DLL) //Build dll
-# define BOOST_TASK_DECL __declspec(dllexport)
-# elif defined(BOOST_TASK_USE_DLL) //Use dll
-# define BOOST_TASK_DECL __declspec(dllimport)
+# if defined(BOOST_TASKS_BUILD_DLL) //Build dll
+# define BOOST_TASKS_DECL __declspec(dllexport)
+# elif defined(BOOST_TASKS_USE_DLL) //Use dll
+# define BOOST_TASKS_DECL __declspec(dllimport)
# else
-# define BOOST_TASK_DECL
+# define BOOST_TASKS_DECL
# endif
# else
-# define BOOST_TASK_DECL
+# define BOOST_TASKS_DECL
# endif
// Automatically link to the correct build variant where possible.
-# if ! defined(BOOST_ALL_NO_LIB) && ! defined(BOOST_TASK_NO_LIB) && ! defined(BOOST_TASK_BUILD_DLL) && ! defined(BOOST_TASK_BUILD_LIB)
+# if ! defined(BOOST_ALL_NO_LIB) && ! defined(BOOST_TASKS_NO_LIB) && ! defined(BOOST_TASKS_BUILD_DLL) && ! defined(BOOST_TASKS_BUILD_LIB)
// Tell the autolink to link dynamically, this will get undef'ed by auto_link.hpp
-# if defined(BOOST_TASK_USE_DLL)
+# if defined(BOOST_TASKS_USE_DLL)
# define BOOST_DYN_LINK
# endif
// Set the name of our library, this will get undef'ed by auto_link.hpp
-# if defined(BOOST_TASK_LIB_NAME)
-# define BOOST_LIB_NAME BOOST_TASK_LIB_NAME
+# if defined(BOOST_TASKS_LIB_NAME)
+# define BOOST_LIB_NAME BOOST_TASKS_LIB_NAME
# else
# define BOOST_LIB_NAME boost_task
# endif
@@ -86,5 +86,5 @@
#include <boost/config/auto_link.hpp>
# endif // auto-linking disabled
-#endif // BOOST_TASK_DETAIL_CONFIG_H
+#endif // BOOST_TASKS_DETAIL_CONFIG_H
Deleted: sandbox/task/boost/task/detail/fiber.hpp
==============================================================================
--- sandbox/task/boost/task/detail/fiber.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,25 +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_TASK_DETAIL_FIBER_H
-#define BOOST_TASK_DETAIL_FIBER_H
-
-// MS compatible compilers support #pragma once
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
-#include <boost/config.hpp>
-
-# if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
-#include <boost/task/detail/fiber_windows.hpp>
-
-# elif defined(_POSIX_VERSION)
-#include <boost/task/detail/fiber_posix.hpp>
-
-# endif
-
-#endif // BOOST_TASK_DETAIL_FIBER_H
Deleted: sandbox/task/boost/task/detail/fiber_posix.hpp
==============================================================================
--- sandbox/task/boost/task/detail/fiber_posix.hpp 2009-12-26 17:00:51 EST (Sat, 26 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_TASK_DETAIL_FIBER_POSIX_H
-#define BOOST_TASK_DETAIL_FIBER_POSIX_H
-
-extern "C"
-{
-#include <ucontext.h>
-}
-
-#include <cstddef>
-#include <utility>
-
-#include <boost/assert.hpp>
-#include <boost/function.hpp>
-#include <boost/shared_array.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/system/system_error.hpp>
-
-namespace boost {
-namespace task {
-namespace detail {
-
-template< typename Fiber >
-void trampoline( Fiber * fib)
-{
- BOOST_ASSERT( fib);
- BOOST_ASSERT( ! fib->fn_.empty() );
- fib->fn_();
- fib->exit();
-}
-
-class fiber
-{
-private:
- enum st_state
- {
- st_uninitialized = 0,
- st_ready = 1,
- st_running = 2,
- st_exited = 3
- };
-
- template< typename Fiber >
- friend
- void trampoline( Fiber *);
-
- function< void() > fn_;
- std::size_t stack_size_;
- ::ucontext_t caller_;
- ::ucontext_t callee_;
- shared_array< char > stack_;
- st_state state_;
-
- fiber(
- function< void() > fn,
- std::size_t stack_size) :
- fn_( fn),
- stack_size_( stack_size),
- caller_(),
- callee_(),
- stack_( new char[stack_size]),
- state_( st_uninitialized)
- { BOOST_ASSERT( stack_size_ > 0); }
-
- bool uninitialized_() const
- { return state_ == st_uninitialized; }
-
- bool ready_() const
- { return state_ == st_ready; }
-
- bool running_() const
- { return state_ == st_running; }
-
- bool exited_() const
- { return state_ == st_exited; }
-
- void exit_()
- { BOOST_ASSERT( ::swapcontext( & callee_, & caller_) != -1); }
-
- void switch_to_( fiber & to)
- {
- std::swap( caller_, to.caller_);
- std::swap( state_, to.state_);
- BOOST_ASSERT( ::swapcontext( & callee_, & to.callee_) != -1);
- }
-
- void run_()
- { BOOST_ASSERT( ::swapcontext( & caller_, & callee_) != -1); }
-
- void init_()
- {
- BOOST_ASSERT( state_ == st_uninitialized);
-
- if ( ::getcontext( & caller_) == -1)
- throw system::system_error(
- system::error_code(
- errno,
- system::system_category) );
- BOOST_ASSERT( stack_);
- if ( ::getcontext( & callee_) == -1)
- throw system::system_error(
- system::error_code(
- errno,
- system::system_category) );
- callee_.uc_stack.ss_sp = stack_.get();
- callee_.uc_stack.ss_size = stack_size_;
- callee_.uc_link = 0;
- typedef void fn_type( fiber *);
- typedef void ( * st_fn)();
- fn_type * fn_ptr( trampoline< fiber >);
-
- ::makecontext(
- & callee_,
- ( st_fn)( fn_ptr),
- 1,
- this);
-
- state_ = st_ready;
- }
-
-public:
- typedef shared_ptr< fiber > sptr_t;
-
- static void convert_thread_to_fiber()
- {}
-
- static sptr_t create(
- function< void() > fn,
- std::size_t stack_size)
- { return sptr_t( new fiber( fn, stack_size) ); }
-
- ~fiber()
- { BOOST_ASSERT( ! running_() ); }
-
- bool ready() const
- { return uninitialized_() || ready_(); }
-
- bool running() const
- { return running_(); }
-
- bool exited() const
- { return exited_(); }
-
- void switch_to( sptr_t & to)
- {
- BOOST_ASSERT( to);
- BOOST_ASSERT( running_() );
- if ( to->uninitialized_() ) to->init_();
- switch_to_( * to);
- BOOST_ASSERT( running_() );
- }
-
- void run()
- {
- BOOST_ASSERT( uninitialized_() );
- init_();
- BOOST_ASSERT( ready_() );
- state_ = st_running;
- run_();
- BOOST_ASSERT( ready_() || exited_() );
- }
-
- void exit()
- {
- BOOST_ASSERT( running_() ) ;
- state_ = st_exited;
- exit_();
- BOOST_ASSERT(!"should never be reached");
- }
-};
-
-}}}
-
-#endif // BOOST_TASK_DETAIL_FIBER_POSIX_H
-
Deleted: sandbox/task/boost/task/detail/fiber_windows.hpp
==============================================================================
--- sandbox/task/boost/task/detail/fiber_windows.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,179 +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_TASK_DETAIL_FIBER_WINDOWS_H
-#define BOOST_TASK_DETAIL_FIBER_WINDOWS_H
-
-extern "C"
-{
-#include <windows.h>
-#include <winnt.h>
-}
-
-#include <cstddef>
-
-#include <boost/assert.hpp>
-#include <boost/function.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/system/system_error.hpp>
-
-namespace boost {
-namespace task {
-namespace detail {
-
-template< typename Fiber >
-VOID CALLBACK trampoline( LPVOID vp)
-{
- Fiber * fib( static_cast< Fiber * >( vp) );
- BOOST_ASSERT( fib);
- BOOST_ASSERT( ! fib->fn_.empty() );
- fib->fn_();
- fib->exit();
-}
-
-class fiber
-{
-private:
- enum st_state
- {
- st_uninitialized = 0,
- st_ready = 1,
- st_running = 2,
- st_exited = 3
- };
-
- template< typename Fiber >
- friend
- VOID CALLBACK trampoline( LPVOID);
-
- function< void() > fn_;
- std::size_t stack_size_;
- LPVOID caller_;
- LPVOID callee_;
- st_state state_;
-
- fiber(
- function< void() > fn,
- std::size_t stack_size) :
- fn_( fn),
- stack_size_( stack_size),
- caller_( 0),
- callee_( 0),
- state_( st_uninitialized)
- { BOOST_ASSERT( stack_size_ > 0); }
-
- bool uninitialized_() const
- { return state_ == st_uninitialized; }
-
- bool ready_() const
- { return state_ == st_ready; }
-
- bool running_() const
- { return state_ == st_running; }
-
- bool exited_() const
- { return state_ == st_exited; }
-
- void exit_()
- { ::SwitchToFiber( caller_); }
-
- void switch_to_( fiber & to)
- {
- std::swap( caller_, to.caller_);
- std::swap( state_, to.state_);
- ::SwitchToFiber( to.callee_);
- }
-
- void run_()
- { ::SwitchToFiber( callee_); }
-
- void init_()
- {
- BOOST_ASSERT( state_ == st_uninitialized);
-
- caller_ = ::GetCurrentFiber();
- if ( ! caller_)
- throw system::system_error(
- system::error_code(
- ::GetLastError(),
- system::system_category) );
- callee_ = ::CreateFiber(
- stack_size_,
- static_cast< LPFIBER_START_ROUTINE >( & trampoline< fiber >),
- static_cast< LPVOID >( this) );
- if ( ! callee_)
- throw system::system_error(
- system::error_code(
- ::GetLastError(),
- system::system_category) );
-
- state_ = st_ready;
- }
-
-public:
- typedef shared_ptr< fiber > sptr_t;
-
- static void convert_thread_to_fiber()
- {
- if ( ! ::ConvertThreadToFiber( 0) )
- throw system::system_error(
- system::error_code(
- ::GetLastError(),
- system::system_category) );
- }
-
- static sptr_t create(
- function< void() > fn,
- std::size_t stack_size)
- { return sptr_t( new fiber( fn, stack_size) ); }
-
- ~fiber()
- {
- BOOST_ASSERT( ! running_() );
- ::DeleteFiber( callee_);
- }
-
- bool ready() const
- { return uninitialized_() || ready_(); }
-
- bool running() const
- { return running_(); }
-
- bool exited() const
- { return exited_(); }
-
- void switch_to( sptr_t & to)
- {
- BOOST_ASSERT( to);
- BOOST_ASSERT( running_() );
- if ( to->uninitialized_() ) to->init_();
- switch_to_( * to);
- BOOST_ASSERT( running_() );
- }
-
- void run()
- {
- BOOST_ASSERT( uninitialized_() );
- init_();
- BOOST_ASSERT( ready_() );
- state_ = st_running;
- run_();
- BOOST_ASSERT( ready_() || exited_() );
- }
-
- void exit()
- {
- BOOST_ASSERT( running_() ) ;
- state_ = st_exited;
- exit_();
- BOOST_ASSERT(!"should never be reached");
- }
-};
-
-}}}
-
-#endif // BOOST_TASK_DETAIL_FIBER_WINDOWS_H
-
Modified: sandbox/task/boost/task/detail/guard.hpp
==============================================================================
--- sandbox/task/boost/task/detail/guard.hpp (original)
+++ sandbox/task/boost/task/detail/guard.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_GUARD_H
-#define BOOST_TASK_DETAIL_GUARD_H
+#ifndef BOOST_TASKS_DETAIL_GUARD_H
+#define BOOST_TASKS_DETAIL_GUARD_H
#include <boost/cstdint.hpp>
#include <boost/utility.hpp>
@@ -20,10 +20,10 @@
# endif
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
-class BOOST_TASK_DECL guard : private noncopyable
+class BOOST_TASKS_DECL guard : private noncopyable
{
private:
volatile uint32_t & active_worker_;
@@ -42,5 +42,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_GUARD_H
+#endif // BOOST_TASKS_DETAIL_GUARD_H
Modified: sandbox/task/boost/task/detail/has_sync.hpp
==============================================================================
--- sandbox/task/boost/task/detail/has_sync.hpp (original)
+++ sandbox/task/boost/task/detail/has_sync.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -1,5 +1,5 @@
-#ifndef BOOST_TASK_DETAIL_HAS_SYNC_H
-#define BOOST_TASK_DETAIL_HAS_SYNC_H
+#ifndef BOOST_TASKS_DETAIL_HAS_SYNC_H
+#define BOOST_TASKS_DETAIL_HAS_SYNC_H
// MS compatible compilers support #pragma once
@@ -22,28 +22,28 @@
#if defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 401 )
-#define BOOST_TASK_HAS_SYNC
+#define BOOST_TASKS_HAS_SYNC
#if defined( __arm__ ) || defined( __armel__ )
-#undef BOOST_TASK_HAS_SYNC
+#undef BOOST_TASKS_HAS_SYNC
#endif
#if defined( __hppa ) || defined( __hppa__ )
-#undef BOOST_TASK_HAS_SYNC
+#undef BOOST_TASKS_HAS_SYNC
#endif
#if defined( __m68k__ )
-#undef BOOST_TASK_HAS_SYNC
+#undef BOOST_TASKS_HAS_SYNC
#endif
#if defined( __sparc__ )
-#undef BOOST_TASK_HAS_SYNC
+#undef BOOST_TASKS_HAS_SYNC
#endif
#if defined( __INTEL_COMPILER ) && !defined( __ia64__ )
-#undef BOOST_TASK_HAS_SYNC
+#undef BOOST_TASKS_HAS_SYNC
#endif
#endif // __GNUC__ * 100 + __GNUC_MINOR__ >= 401
-#endif // BOOST_TASK_DETAIL_HAS_SYNC_H
+#endif // BOOST_TASKS_DETAIL_HAS_SYNC_H
Modified: sandbox/task/boost/task/detail/meta.hpp
==============================================================================
--- sandbox/task/boost/task/detail/meta.hpp (original)
+++ sandbox/task/boost/task/detail/meta.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,13 +4,13 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_INFO_H
-#define BOOST_TASK_DETAIL_INFO_H
+#ifndef BOOST_TASKS_DETAIL_INFO_H
+#define BOOST_TASKS_DETAIL_INFO_H
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
struct has_attribute
@@ -23,5 +23,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_INFO_H
+#endif // BOOST_TASKS_DETAIL_INFO_H
Modified: sandbox/task/boost/task/detail/pool_base.hpp
==============================================================================
--- sandbox/task/boost/task/detail/pool_base.hpp (original)
+++ sandbox/task/boost/task/detail/pool_base.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_POOL_BASE_H
-#define BOOST_TASK_DETAIL_POOL_BASE_H
+#ifndef BOOST_TASKS_DETAIL_POOL_BASE_H
+#define BOOST_TASKS_DETAIL_POOL_BASE_H
#include <cstddef>
@@ -26,11 +26,10 @@
#include <boost/task/callable.hpp>
#include <boost/task/context.hpp>
#include <boost/task/exceptions.hpp>
-#include <boost/task/future.hpp>
+#include <boost/thread/future.hpp>
#include <boost/task/handle.hpp>
#include <boost/task/poolsize.hpp>
#include <boost/task/scanns.hpp>
-#include <boost/task/spin_manual_reset_event.hpp>
#include <boost/task/stacksize.hpp>
#include <boost/task/task.hpp>
#include <boost/task/watermark.hpp>
@@ -38,14 +37,14 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
template<
typename Queue,
typename UMS
>
-class pool_base : public UMS
+class pool_base
{
private:
friend class worker;
@@ -55,14 +54,15 @@
typedef Queue queue_type;
typedef typename queue_type::value_type value_type;
+ typedef UMS ums_type;
- worker_group wg_;
- shared_mutex mtx_wg_;
- volatile uint32_t state_;
- queue_type queue_;
- volatile uint32_t idle_worker_;
- spin_manual_reset_event shtdwn_ev_;
- spin_manual_reset_event shtdwn_now_ev_;
+ worker_group wg_;
+ shared_mutex mtx_wg_;
+ volatile uint32_t state_;
+ queue_type queue_;
+ volatile uint32_t idle_worker_;
+ bool shtdwn_;
+ bool shtdwn_now_;
void worker_entry_()
{
@@ -141,8 +141,8 @@
state_( 0),
queue_(),
idle_worker_( 0),
- shtdwn_ev_(),
- shtdwn_now_ev_()
+ shtdwn_( false),
+ shtdwn_now_( false)
{
if ( asleep.is_special() || asleep.is_negative() )
throw invalid_timeduration();
@@ -163,8 +163,8 @@
state_( 0),
queue_( hwm, lwm),
idle_worker_( 0),
- shtdwn_ev_(),
- shtdwn_now_ev_()
+ shtdwn_( false),
+ shtdwn_now_( false)
{
if ( asleep.is_special() || asleep.is_negative() )
throw invalid_timeduration();
@@ -183,8 +183,8 @@
state_( 0),
queue_(),
idle_worker_( 0),
- shtdwn_ev_(),
- shtdwn_now_ev_()
+ shtdwn_( false),
+ shtdwn_now_( false)
{
if ( asleep.is_special() || asleep.is_negative() )
throw invalid_timeduration();
@@ -206,8 +206,8 @@
state_( 0),
queue_( hwm, lwm),
idle_worker_( 0),
- shtdwn_ev_(),
- shtdwn_now_ev_()
+ shtdwn_( false),
+ shtdwn_now_( false)
{
if ( asleep.is_special() || asleep.is_negative() )
throw invalid_timeduration();
@@ -236,7 +236,7 @@
queue_.deactivate();
shared_lock< shared_mutex > lk( mtx_wg_);
- shtdwn_ev_.set();
+ shtdwn_ = true;
wg_.join_all();
}
@@ -246,7 +246,7 @@
queue_.deactivate();
shared_lock< shared_mutex > lk( mtx_wg_);
- shtdwn_now_ev_.set();
+ shtdwn_now_ = true;
wg_.interrupt_all();
wg_.join_all();
}
@@ -310,5 +310,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_POOL_BASE_H
+#endif // BOOST_TASKS_DETAIL_POOL_BASE_H
Modified: sandbox/task/boost/task/detail/smart.hpp
==============================================================================
--- sandbox/task/boost/task/detail/smart.hpp (original)
+++ sandbox/task/boost/task/detail/smart.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -12,7 +12,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
struct replace_oldest
@@ -64,4 +64,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_SMART_H
+#endif // BOOST_TASKS_DETAIL_SMART_H
Modified: sandbox/task/boost/task/detail/worker.hpp
==============================================================================
--- sandbox/task/boost/task/detail/worker.hpp (original)
+++ sandbox/task/boost/task/detail/worker.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,13 +4,14 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_WORKER_H
-#define BOOST_TASK_DETAIL_WORKER_H
+#ifndef BOOST_TASKS_DETAIL_WORKER_H
+#define BOOST_TASKS_DETAIL_WORKER_H
#include <cstddef>
#include <utility>
#include <boost/assert.hpp>
+#include <boost/fiber.hpp>
#include <boost/function.hpp>
#include <boost/random.hpp>
#include <boost/shared_ptr.hpp>
@@ -19,13 +20,11 @@
#include <boost/task/callable.hpp>
#include <boost/task/detail/config.hpp>
-#include <boost/task/detail/fiber.hpp>
#include <boost/task/detail/guard.hpp>
#include <boost/task/detail/wsq.hpp>
#include <boost/task/poolsize.hpp>
#include <boost/task/scanns.hpp>
#include <boost/task/stacksize.hpp>
-#include <boost/task/semaphore.hpp>
#include <boost/config/abi_prefix.hpp>
@@ -35,7 +34,7 @@
# endif
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
struct worker_base
@@ -87,16 +86,17 @@
typedef shared_ptr< thread > thread_t;
- Pool & pool_;
- thread_t thrd_;
- fiber::sptr_t fib_;
- wsq wsq_;
- bool shtdwn_;
- posix_time::time_duration asleep_;
- scanns max_scns_;
- std::size_t scns_;
- std::size_t stack_size_;
- random_idx rnd_idx_;
+ Pool & pool_;
+ thread_t thrd_;
+ fibers::scheduler<
+ typename Pool::ums_type > sched_;
+ wsq wsq_;
+ bool shtdwn_;
+ posix_time::time_duration asleep_;
+ scanns max_scns_;
+ std::size_t scns_;
+ std::size_t stack_size_;
+ random_idx rnd_idx_;
void execute_( callable & ca)
{
@@ -134,38 +134,22 @@
return false;
}
- bool try_blocked_fibers_()
- {
- if ( pool_.has_blocked() )
- {
- fiber::sptr_t this_fib = fib_;
- BOOST_ASSERT( this_fib);
- pool_.put_runnable( this_fib);
- fiber::sptr_t blocked_fib;
- pool_.try_take_blocked( blocked_fib);
- BOOST_ASSERT( blocked_fib);
- fib_ = blocked_fib;
- BOOST_ASSERT( this_fib->running() );
- this_fib->switch_to( blocked_fib);
- BOOST_ASSERT( this_fib->running() );
- fib_ = this_fib;
- return true;
- }
- return false;
- }
-
void run_()
{
while ( ! shutdown_() )
{
- try_blocked_fibers_();
callable ca;
if ( try_take_local_callable_( ca) ||
try_steal_other_callable_( ca) ||
try_take_global_callable_( ca) )
{
+ fprintf(stdout,"run_(): execute_( ca)\n");
execute_( ca);
scns_ = 0;
+ if ( 0 < sched_.ready() ){
+ fprintf(stdout,"run_(): return because %d fibers are ready\n", sched_.ready() );
+ return;
+ }
}
else
{
@@ -176,9 +160,12 @@
if ( pool_.size_() > pool_.idle_worker_)
{
if ( take_global_callable_( ca, asleep_) )
+ {
execute_( ca);
+ if ( 0 < sched_.ready() ) return;
+ }
}
- else if ( ! pool_.has_blocked() )
+ else if ( 0 == sched_.ready() )
{
try
{ this_thread::sleep( asleep_); }
@@ -188,14 +175,19 @@
scns_ = 0;
}
else
- this_thread::yield();
+ {
+ if ( 0 < sched_.ready() )
+ return;
+ else
+ this_thread::yield();
+ }
}
}
}
bool shutdown_()
{
- if ( shutdown__() && pool_.queue_.empty() && ! pool_.has_blocked() )
+ if ( shutdown__() && pool_.queue_.empty() && 0 == sched_.ready() )
return true;
else if ( shutdown_now__() )
return true;
@@ -205,12 +197,12 @@
bool shutdown__()
{
if ( ! shtdwn_)
- shtdwn_ = pool_.shtdwn_ev_.try_wait();
+ shtdwn_ = pool_.shtdwn_;
return shtdwn_;
}
bool shutdown_now__()
- { return pool_.shtdwn_now_ev_.try_wait(); }
+ { return pool_.shtdwn_now_; }
public:
worker_object(
@@ -222,7 +214,7 @@
function< void() > const& fn) :
pool_( pool),
thrd_( new thread( fn) ),
- fib_(),
+ sched_(),
wsq_(),
shtdwn_( false),
asleep_( asleep),
@@ -255,44 +247,57 @@
{
BOOST_ASSERT( get_id() == this_thread::get_id() );
- fiber::convert_thread_to_fiber();
-
- pool_.attach();
-
- fib_ = fiber::create(
- bind( & worker_object::run_, this),
- stack_size_);
- fib_->run();
- BOOST_ASSERT( fib_->exited() );
+ sched_.make_fiber(
+ bind(
+ & worker_object::run_,
+ this),
+ stack_size_);
+ while ( ! shutdown_() )
+ {
+ fprintf(stdout,"run(): call scheduler::run()\n");
+ sched_.run();
+ }
}
void reschedule_until( function< bool() > const& pred)
{
- while ( ! pred() )
- block();
+ while (true)
+ {
+ if ( pred() )
+ {
+ fprintf(stdout,"predicate is true- will return\n");
+ break;
+ }
+ else
+ {
+ fprintf(stdout,"predicate is not true - will block\n");
+ block();
+ }
+ }
}
void block()
{
- fiber::sptr_t this_fib = fib_;
- pool_.put_blocked( this_fib);
- fiber::sptr_t runnable_fib;
- if ( pool_.has_runnable() )
- pool_.try_take_runnable( runnable_fib);
- else
- runnable_fib = fiber::create(
- bind( & worker_object::run_, this),
+ if ( 0 == sched_.ready() )
+ {
+ sched_.make_fiber(
+ bind(
+ & worker_object::run_,
+ this),
stack_size_);
- BOOST_ASSERT( runnable_fib);
- fib_ = runnable_fib;
- BOOST_ASSERT( this_fib->running() );
- this_fib->switch_to( runnable_fib);
- BOOST_ASSERT( this_fib->running() );
- fib_ = this_fib;
+ fprintf(stdout,"block(): new fiber added to scheduler\n");
+ }
+ else
+ {
+ fprintf(stdout,"block(): scheduler has == ready fibers%d\n", sched_.ready() );
+ }
+ fprintf(stdout,"block(): before this_fiber::yield()\n");
+ this_fiber::yield();
+ fprintf(stdout,"block: after this_fiber::yield()\n");
}
};
-class BOOST_TASK_DECL worker
+class BOOST_TASKS_DECL worker
{
private:
static thread_specific_ptr< worker > tss_;
@@ -341,5 +346,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_WORKER_H
+#endif // BOOST_TASKS_DETAIL_WORKER_H
Modified: sandbox/task/boost/task/detail/worker_group.hpp
==============================================================================
--- sandbox/task/boost/task/detail/worker_group.hpp (original)
+++ sandbox/task/boost/task/detail/worker_group.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_WORKER_GROUP_H
-#define BOOST_TASK_DETAIL_WORKER_GROUP_H
+#ifndef BOOST_TASKS_DETAIL_WORKER_GROUP_H
+#define BOOST_TASKS_DETAIL_WORKER_GROUP_H
#include <cstddef>
@@ -17,7 +17,6 @@
#include <boost/task/detail/config.hpp>
#include <boost/task/detail/worker.hpp>
-#include <boost/task/spin_manual_reset_event.hpp>
#include <boost/config/abi_prefix.hpp>
@@ -27,10 +26,10 @@
# endif
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
-class BOOST_TASK_DECL worker_group
+class BOOST_TASKS_DECL worker_group
{
private:
struct id_idx_tag {};
@@ -98,5 +97,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_WORKER_GROUP_H
+#endif // BOOST_TASKS_DETAIL_WORKER_GROUP_H
Modified: sandbox/task/boost/task/detail/wsq.hpp
==============================================================================
--- sandbox/task/boost/task/detail/wsq.hpp (original)
+++ sandbox/task/boost/task/detail/wsq.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_DETAIL_WSQ_H
-#define BOOST_TASK_DETAIL_WSQ_H
+#ifndef BOOST_TASKS_DETAIL_WSQ_H
+#define BOOST_TASKS_DETAIL_WSQ_H
#include <boost/cstdint.hpp>
#include <boost/shared_array.hpp>
@@ -23,10 +23,10 @@
# endif
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
-class BOOST_TASK_DECL wsq : private noncopyable
+class BOOST_TASKS_DECL wsq : private noncopyable
{
private:
const int initial_size_;
@@ -59,5 +59,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_DETAIL_WSQ_H
+#endif // BOOST_TASKS_DETAIL_WSQ_H
Modified: sandbox/task/boost/task/exceptions.hpp
==============================================================================
--- sandbox/task/boost/task/exceptions.hpp (original)
+++ sandbox/task/boost/task/exceptions.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_EXCEPTIONS_H
-#define BOOST_TASK_EXCEPTIONS_H
+#ifndef BOOST_TASKS_EXCEPTIONS_H
+#define BOOST_TASKS_EXCEPTIONS_H
#include <stdexcept>
#include <string>
@@ -13,7 +13,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
class invalid_poolsize : public std::invalid_argument
{
@@ -118,4 +118,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_EXCEPTIONS_H
+#endif // BOOST_TASKS_EXCEPTIONS_H
Deleted: sandbox/task/boost/task/future.hpp
==============================================================================
--- sandbox/task/boost/task/future.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,1364 +0,0 @@
-// (C) Copyright 2008 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_FUTURE_HPP
-#define BOOST_FUTURE_HPP
-#include <stdexcept>
-#include <vector>
-#include <boost/exception.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/detail/move.hpp>
-#include <boost/thread/thread_time.hpp>
-#include <boost/exception_ptr.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/scoped_ptr.hpp>
-#include <boost/type_traits/is_fundamental.hpp>
-#include <boost/type_traits/is_convertible.hpp>
-#include <boost/mpl/if.hpp>
-#include <boost/config.hpp>
-#include <algorithm>
-#include <boost/function.hpp>
-#include <boost/bind.hpp>
-#include <boost/ref.hpp>
-#include <boost/scoped_array.hpp>
-#include <boost/utility/enable_if.hpp>
-#include <list>
-#include <boost/next_prior.hpp>
-
-namespace boost
-{
- class future_uninitialized:
- public std::logic_error
- {
- public:
- future_uninitialized():
- std::logic_error("Future Uninitialized")
- {}
- };
- class broken_promise:
- public std::logic_error
- {
- public:
- broken_promise():
- std::logic_error("Broken promise")
- {}
- };
- class future_already_retrieved:
- public std::logic_error
- {
- public:
- future_already_retrieved():
- std::logic_error("Future already retrieved")
- {}
- };
- class promise_already_satisfied:
- public std::logic_error
- {
- public:
- promise_already_satisfied():
- std::logic_error("Promise already satisfied")
- {}
- };
-
- class task_already_started:
- public std::logic_error
- {
- public:
- task_already_started():
- std::logic_error("Task already started")
- {}
- };
-
- class task_moved:
- public std::logic_error
- {
- public:
- task_moved():
- std::logic_error("Task moved")
- {}
- };
-
- namespace future_state
- {
- enum state { uninitialized, waiting, ready, moved };
- }
-
- namespace detail
- {
- struct future_object_base
- {
- boost::exception_ptr exception;
- bool done;
- boost::mutex mutex;
- boost::condition_variable waiters;
- typedef std::list<boost::condition_variable_any*> waiter_list;
- waiter_list external_waiters;
- boost::function<void()> callback;
-
- future_object_base():
- done(false)
- {}
- virtual ~future_object_base()
- {}
-
- waiter_list::iterator register_external_waiter(boost::condition_variable_any& cv)
- {
- boost::unique_lock<boost::mutex> lock(mutex);
- do_callback(lock);
- return external_waiters.insert(external_waiters.end(),&cv);
- }
-
- void remove_external_waiter(waiter_list::iterator it)
- {
- boost::lock_guard<boost::mutex> lock(mutex);
- external_waiters.erase(it);
- }
-
- void mark_finished_internal()
- {
- done=true;
- waiters.notify_all();
- for(waiter_list::const_iterator it=external_waiters.begin(),
- end=external_waiters.end();it!=end;++it)
- {
- (*it)->notify_all();
- }
- }
-
- struct relocker
- {
- boost::unique_lock<boost::mutex>& lock;
-
- relocker(boost::unique_lock<boost::mutex>& lock_):
- lock(lock_)
- {
- lock.unlock();
- }
- ~relocker()
- {
- lock.lock();
- }
- };
-
- void do_callback(boost::unique_lock<boost::mutex>& lock)
- {
- if(callback && !done)
- {
- boost::function<void()> local_callback=callback;
- relocker relock(lock);
- local_callback();
- }
- }
-
-
- void wait(bool rethrow=true)
- {
- boost::unique_lock<boost::mutex> lock(mutex);
- do_callback(lock);
- while(!done)
- {
- waiters.wait(lock);
- }
- if(rethrow && exception)
- {
- boost::rethrow_exception(exception);
- }
- }
-
- bool timed_wait_until(boost::system_time const& target_time)
- {
- boost::unique_lock<boost::mutex> lock(mutex);
- do_callback(lock);
- while(!done)
- {
- bool const success=waiters.timed_wait(lock,target_time);
- if(!success && !done)
- {
- return false;
- }
- }
- return true;
- }
-
- void mark_exceptional_finish_internal(boost::exception_ptr const& e)
- {
- exception=e;
- mark_finished_internal();
- }
- void mark_exceptional_finish()
- {
- boost::lock_guard<boost::mutex> lock(mutex);
- mark_exceptional_finish_internal(boost::current_exception());
- }
-
- bool has_value()
- {
- boost::lock_guard<boost::mutex> lock(mutex);
- return done && !exception;
- }
- bool has_exception()
- {
- boost::lock_guard<boost::mutex> lock(mutex);
- return done && exception;
- }
-
- template<typename F,typename U>
- void set_wait_callback(F f,U* u)
- {
- callback=boost::bind(f,boost::ref(*u));
- }
-
- private:
- future_object_base(future_object_base const&);
- future_object_base& operator=(future_object_base const&);
- };
-
- 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::detail::thread_move_t<T> >,boost::detail::thread_move_t<T>,T const&>::type rvalue_source_type;
- typedef typename boost::mpl::if_<boost::is_convertible<T&,boost::detail::thread_move_t<T> >,boost::detail::thread_move_t<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;
- }
-
- };
-
- template<typename T>
- struct future_object:
- detail::future_object_base
- {
- typedef typename future_traits<T>::storage_type storage_type;
- typedef typename future_traits<T>::source_reference_type source_reference_type;
- typedef typename future_traits<T>::rvalue_source_type rvalue_source_type;
- typedef typename future_traits<T>::move_dest_type move_dest_type;
-
- storage_type result;
-
- future_object():
- result(0)
- {}
-
- void mark_finished_with_result_internal(source_reference_type result_)
- {
- future_traits<T>::init(result,result_);
- mark_finished_internal();
- }
- void mark_finished_with_result_internal(rvalue_source_type result_)
- {
- future_traits<T>::init(result,static_cast<rvalue_source_type>(result_));
- mark_finished_internal();
- }
-
- void mark_finished_with_result(source_reference_type result_)
- {
- boost::lock_guard<boost::mutex> lock(mutex);
- mark_finished_with_result_internal(result_);
- }
- void mark_finished_with_result(rvalue_source_type result_)
- {
- boost::lock_guard<boost::mutex> lock(mutex);
- mark_finished_with_result_internal(result_);
- }
-
- move_dest_type get()
- {
- wait();
- return *result;
- }
-
- future_state::state get_state()
- {
- boost::lock_guard<boost::mutex> guard(mutex);
- if(!done)
- {
- return future_state::waiting;
- }
- else
- {
- return future_state::ready;
- }
- }
-
- private:
- future_object(future_object const&);
- future_object& operator=(future_object const&);
- };
-
- template<>
- struct future_object<void>:
- detail::future_object_base
- {
- future_object()
- {}
-
- void mark_finished_with_result_internal()
- {
- mark_finished_internal();
- }
-
- void mark_finished_with_result()
- {
- boost::lock_guard<boost::mutex> lock(mutex);
- mark_finished_with_result_internal();
- }
-
- void get()
- {
- wait();
- }
-
- future_state::state get_state()
- {
- boost::lock_guard<boost::mutex> guard(mutex);
- if(!done)
- {
- return future_state::waiting;
- }
- else
- {
- return future_state::ready;
- }
- }
-
- private:
- future_object(future_object const&);
- future_object& operator=(future_object const&);
- };
-
- class future_waiter
- {
- struct registered_waiter
- {
- boost::shared_ptr<detail::future_object_base> future;
- detail::future_object_base::waiter_list::iterator wait_iterator;
- unsigned index;
-
- registered_waiter(boost::shared_ptr<detail::future_object_base> const& future_,
- detail::future_object_base::waiter_list::iterator wait_iterator_,
- unsigned index_):
- future(future_),wait_iterator(wait_iterator_),index(index_)
- {}
-
- };
-
- struct all_futures_lock
- {
- unsigned count;
- boost::scoped_array<boost::unique_lock<boost::mutex> > locks;
-
- all_futures_lock(std::vector<registered_waiter>& futures):
- count(futures.size()),locks(new boost::unique_lock<boost::mutex>[count])
- {
- for(unsigned i=0;i<count;++i)
- {
- locks[i]=boost::unique_lock<boost::mutex>(futures[i].future->mutex);
- }
- }
-
- void lock()
- {
- boost::lock(locks.get(),locks.get()+count);
- }
-
- void unlock()
- {
- for(unsigned i=0;i<count;++i)
- {
- locks[i].unlock();
- }
- }
- };
-
- boost::condition_variable_any cv;
- std::vector<registered_waiter> futures;
- unsigned future_count;
-
- public:
- future_waiter():
- future_count(0)
- {}
-
- template<typename F>
- void add(F& f)
- {
- if(f.future)
- {
- futures.push_back(registered_waiter(f.future,f.future->register_external_waiter(cv),future_count));
- }
- ++future_count;
- }
-
- unsigned wait()
- {
- all_futures_lock lk(futures);
- for(;;)
- {
- for(unsigned i=0;i<futures.size();++i)
- {
- if(futures[i].future->done)
- {
- return futures[i].index;
- }
- }
- cv.wait(lk);
- }
- }
-
- ~future_waiter()
- {
- for(unsigned i=0;i<futures.size();++i)
- {
- futures[i].future->remove_external_waiter(futures[i].wait_iterator);
- }
- }
-
- };
-
- }
-
- template <typename R>
- class unique_future;
-
- template <typename R>
- class shared_future;
-
- template<typename T>
- struct is_future_type
- {
- BOOST_STATIC_CONSTANT(bool, value=false);
- };
-
- template<typename T>
- struct is_future_type<unique_future<T> >
- {
- BOOST_STATIC_CONSTANT(bool, value=true);
- };
-
- template<typename T>
- struct is_future_type<shared_future<T> >
- {
- BOOST_STATIC_CONSTANT(bool, value=true);
- };
-
- template<typename Iterator>
- typename boost::disable_if<is_future_type<Iterator>,void>::type wait_for_all(Iterator begin,Iterator end)
- {
- for(Iterator current=begin;current!=end;++current)
- {
- current->wait();
- }
- }
-
- template<typename F1,typename F2>
- typename boost::enable_if<is_future_type<F1>,void>::type wait_for_all(F1& f1,F2& f2)
- {
- f1.wait();
- f2.wait();
- }
-
- template<typename F1,typename F2,typename F3>
- void wait_for_all(F1& f1,F2& f2,F3& f3)
- {
- f1.wait();
- f2.wait();
- f3.wait();
- }
-
- template<typename F1,typename F2,typename F3,typename F4>
- void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4)
- {
- f1.wait();
- f2.wait();
- f3.wait();
- f4.wait();
- }
-
- template<typename F1,typename F2,typename F3,typename F4,typename F5>
- void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5)
- {
- f1.wait();
- f2.wait();
- f3.wait();
- f4.wait();
- f5.wait();
- }
-
- template<typename Iterator>
- typename boost::disable_if<is_future_type<Iterator>,Iterator>::type wait_for_any(Iterator begin,Iterator end)
- {
- detail::future_waiter waiter;
- for(Iterator current=begin;current!=end;++current)
- {
- waiter.add(*current);
- }
- return boost::next(begin,waiter.wait());
- }
-
- template<typename F1,typename F2>
- typename boost::enable_if<is_future_type<F1>,unsigned>::type wait_for_any(F1& f1,F2& f2)
- {
- detail::future_waiter waiter;
- waiter.add(f1);
- waiter.add(f2);
- return waiter.wait();
- }
-
- template<typename F1,typename F2,typename F3>
- unsigned wait_for_any(F1& f1,F2& f2,F3& f3)
- {
- detail::future_waiter waiter;
- waiter.add(f1);
- waiter.add(f2);
- waiter.add(f3);
- return waiter.wait();
- }
-
- template<typename F1,typename F2,typename F3,typename F4>
- unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4)
- {
- detail::future_waiter waiter;
- waiter.add(f1);
- waiter.add(f2);
- waiter.add(f3);
- waiter.add(f4);
- return waiter.wait();
- }
-
- template<typename F1,typename F2,typename F3,typename F4,typename F5>
- unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5)
- {
- detail::future_waiter waiter;
- waiter.add(f1);
- waiter.add(f2);
- waiter.add(f3);
- waiter.add(f4);
- waiter.add(f5);
- return waiter.wait();
- }
-
- template <typename R>
- class promise;
-
- template <typename R>
- class packaged_task;
-
- template <typename R>
- class unique_future
- {
- unique_future(unique_future & rhs);// = delete;
- unique_future& operator=(unique_future& rhs);// = delete;
-
- typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
-
- future_ptr future;
-
- friend class shared_future<R>;
- friend class promise<R>;
- friend class packaged_task<R>;
- friend class detail::future_waiter;
-
- typedef typename detail::future_traits<R>::move_dest_type move_dest_type;
-
- unique_future(future_ptr future_):
- future(future_)
- {}
-
- public:
- typedef future_state::state state;
-
- unique_future()
- {}
-
- ~unique_future()
- {}
-
-#ifdef BOOST_HAS_RVALUE_REFS
- unique_future(unique_future && other)
- {
- future.swap(other.future);
- }
- unique_future& operator=(unique_future && other)
- {
- future=other.future;
- other.future.reset();
- return *this;
- }
-#else
- unique_future(boost::detail::thread_move_t<unique_future> other):
- future(other->future)
- {
- other->future.reset();
- }
-
- unique_future& operator=(boost::detail::thread_move_t<unique_future> other)
- {
- future=other->future;
- other->future.reset();
- return *this;
- }
-
- operator boost::detail::thread_move_t<unique_future>()
- {
- return boost::detail::thread_move_t<unique_future>(*this);
- }
-#endif
-
- void swap(unique_future& other)
- {
- future.swap(other.future);
- }
-
- // retrieving the value
- move_dest_type get()
- {
- if(!future)
- {
- throw future_uninitialized();
- }
-
- return future->get();
- }
-
- // functions to check state, and wait for ready
- state get_state() const
- {
- if(!future)
- {
- return future_state::uninitialized;
- }
- return future->get_state();
- }
-
-
- bool is_ready() const
- {
- return get_state()==future_state::ready;
- }
-
- bool has_exception() const
- {
- return future && future->has_exception();
- }
-
- bool has_value() const
- {
- return future && future->has_value();
- }
-
- void wait() const
- {
- if(!future)
- {
- throw future_uninitialized();
- }
- future->wait(false);
- }
-
- template<typename Duration>
- bool timed_wait(Duration const& rel_time) const
- {
- return timed_wait_until(boost::get_system_time()+rel_time);
- }
-
- bool timed_wait_until(boost::system_time const& abs_time) const
- {
- if(!future)
- {
- throw future_uninitialized();
- }
- return future->timed_wait_until(abs_time);
- }
-
- };
-
- template <typename R>
- class shared_future
- {
- typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
-
- future_ptr future;
-
-// shared_future(const unique_future<R>& other);
-// shared_future& operator=(const unique_future<R>& other);
-
- friend class detail::future_waiter;
- friend class promise<R>;
- friend class packaged_task<R>;
-
- shared_future(future_ptr future_):
- future(future_)
- {}
-
- public:
- shared_future(shared_future const& other):
- future(other.future)
- {}
-
- typedef future_state::state state;
-
- shared_future()
- {}
-
- ~shared_future()
- {}
-
- shared_future& operator=(shared_future const& other)
- {
- future=other.future;
- return *this;
- }
-#ifdef BOOST_HAS_RVALUE_REFS
- shared_future(shared_future && other)
- {
- future.swap(other.future);
- }
- shared_future(unique_future<R> && other)
- {
- future.swap(other.future);
- }
- shared_future& operator=(shared_future && other)
- {
- future.swap(other.future);
- other.future.reset();
- return *this;
- }
- shared_future& operator=(unique_future<R> && other)
- {
- future.swap(other.future);
- other.future.reset();
- return *this;
- }
-#else
- shared_future(boost::detail::thread_move_t<shared_future> other):
- future(other->future)
- {
- other->future.reset();
- }
-// shared_future(const unique_future<R> &) = delete;
- shared_future(boost::detail::thread_move_t<unique_future<R> > other):
- future(other->future)
- {
- other->future.reset();
- }
- shared_future& operator=(boost::detail::thread_move_t<shared_future> other)
- {
- future.swap(other->future);
- other->future.reset();
- return *this;
- }
- shared_future& operator=(boost::detail::thread_move_t<unique_future<R> > other)
- {
- future.swap(other->future);
- other->future.reset();
- return *this;
- }
-
- operator boost::detail::thread_move_t<shared_future>()
- {
- return boost::detail::thread_move_t<shared_future>(*this);
- }
-
-#endif
-
- void swap(shared_future& other)
- {
- future.swap(other.future);
- }
-
- // retrieving the value
- R get()
- {
- if(!future)
- {
- throw future_uninitialized();
- }
-
- return future->get();
- }
-
- // functions to check state, and wait for ready
- state get_state() const
- {
- if(!future)
- {
- return future_state::uninitialized;
- }
- return future->get_state();
- }
-
-
- bool is_ready() const
- {
- return get_state()==future_state::ready;
- }
-
- bool has_exception() const
- {
- return future && future->has_exception();
- }
-
- bool has_value() const
- {
- return future && future->has_value();
- }
-
- void wait() const
- {
- if(!future)
- {
- throw future_uninitialized();
- }
- future->wait(false);
- }
-
- template<typename Duration>
- bool timed_wait(Duration const& rel_time) const
- {
- return timed_wait_until(boost::get_system_time()+rel_time);
- }
-
- bool timed_wait_until(boost::system_time const& abs_time) const
- {
- if(!future)
- {
- throw future_uninitialized();
- }
- return future->timed_wait_until(abs_time);
- }
-
- };
-
- template <typename R>
- class promise
- {
- typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
-
- future_ptr future;
- bool future_obtained;
-
- promise(promise & rhs);// = delete;
- promise & operator=(promise & rhs);// = delete;
-
- void lazy_init()
- {
- if(!future)
- {
- future_obtained=false;
- future.reset(new detail::future_object<R>);
- }
- }
-
- public:
-// template <class Allocator> explicit promise(Allocator a);
-
- promise():
- future(),future_obtained(false)
- {}
-
- ~promise()
- {
- if(future)
- {
- boost::lock_guard<boost::mutex> lock(future->mutex);
-
- if(!future->done)
- {
- future->mark_exceptional_finish_internal(boost::copy_exception(broken_promise()));
- }
- }
- }
-
- // Assignment
-#ifdef BOOST_HAS_RVALUE_REFS
- promise(promise && rhs):
- future_obtained(rhs.future_obtained)
- {
- future.swap(rhs.future);
- }
- promise & operator=(promise&& rhs)
- {
- future.swap(rhs.future);
- future_obtained=rhs.future_obtained;
- rhs.future.reset();
- return *this;
- }
-#else
- promise(boost::detail::thread_move_t<promise> rhs):
- future(rhs->future),future_obtained(rhs->future_obtained)
- {
- rhs->future.reset();
- }
- promise & operator=(boost::detail::thread_move_t<promise> rhs)
- {
- future=rhs->future;
- future_obtained=rhs->future_obtained;
- rhs->future.reset();
- return *this;
- }
-
- operator boost::detail::thread_move_t<promise>()
- {
- return boost::detail::thread_move_t<promise>(*this);
- }
-#endif
-
- void swap(promise& other)
- {
- future.swap(other.future);
- std::swap(future_obtained,other.future_obtained);
- }
-
- // Result retrieval
- unique_future<R> get_future()
- {
- lazy_init();
- if(future_obtained)
- {
- throw future_already_retrieved();
- }
- future_obtained=true;
- return unique_future<R>(future);
- }
-
- void set_value(typename detail::future_traits<R>::source_reference_type r)
- {
- lazy_init();
- boost::lock_guard<boost::mutex> lock(future->mutex);
- if(future->done)
- {
- throw promise_already_satisfied();
- }
- future->mark_finished_with_result_internal(r);
- }
-
-// void set_value(R && r);
- void set_value(typename detail::future_traits<R>::rvalue_source_type r)
- {
- lazy_init();
- boost::lock_guard<boost::mutex> lock(future->mutex);
- if(future->done)
- {
- throw promise_already_satisfied();
- }
- future->mark_finished_with_result_internal(static_cast<typename detail::future_traits<R>::rvalue_source_type>(r));
- }
-
- void set_exception(boost::exception_ptr p)
- {
- lazy_init();
- boost::lock_guard<boost::mutex> lock(future->mutex);
- if(future->done)
- {
- throw promise_already_satisfied();
- }
- future->mark_exceptional_finish_internal(p);
- }
-
- template<typename F>
- void set_wait_callback(F f)
- {
- lazy_init();
- future->set_wait_callback(f,this);
- }
-
- };
-
- template <>
- class promise<void>
- {
- typedef boost::shared_ptr<detail::future_object<void> > future_ptr;
-
- future_ptr future;
- bool future_obtained;
-
- promise(promise & rhs);// = delete;
- promise & operator=(promise & rhs);// = delete;
-
- void lazy_init()
- {
- if(!future)
- {
- future_obtained=false;
- future.reset(new detail::future_object<void>);
- }
- }
- public:
-// template <class Allocator> explicit promise(Allocator a);
-
- promise():
- future(),future_obtained(false)
- {}
-
- ~promise()
- {
- if(future)
- {
- boost::lock_guard<boost::mutex> lock(future->mutex);
-
- if(!future->done)
- {
- future->mark_exceptional_finish_internal(boost::copy_exception(broken_promise()));
- }
- }
- }
-
- // Assignment
-#ifdef BOOST_HAS_RVALUE_REFS
- promise(promise && rhs):
- future_obtained(rhs.future_obtained)
- {
- future.swap(rhs.future);
- }
- promise & operator=(promise&& rhs)
- {
- future.swap(rhs.future);
- future_obtained=rhs.future_obtained;
- rhs.future.reset();
- return *this;
- }
-#else
- promise(boost::detail::thread_move_t<promise> rhs):
- future(rhs->future),future_obtained(rhs->future_obtained)
- {
- rhs->future.reset();
- }
- promise & operator=(boost::detail::thread_move_t<promise> rhs)
- {
- future=rhs->future;
- future_obtained=rhs->future_obtained;
- rhs->future.reset();
- return *this;
- }
-
- operator boost::detail::thread_move_t<promise>()
- {
- return boost::detail::thread_move_t<promise>(*this);
- }
-#endif
-
- void swap(promise& other)
- {
- future.swap(other.future);
- std::swap(future_obtained,other.future_obtained);
- }
-
- // Result retrieval
- unique_future<void> get_future()
- {
- lazy_init();
-
- if(future_obtained)
- {
- throw future_already_retrieved();
- }
- future_obtained=true;
- return unique_future<void>(future);
- }
-
- void set_value()
- {
- lazy_init();
- boost::lock_guard<boost::mutex> lock(future->mutex);
- if(future->done)
- {
- throw promise_already_satisfied();
- }
- future->mark_finished_with_result_internal();
- }
-
- void set_exception(boost::exception_ptr p)
- {
- lazy_init();
- boost::lock_guard<boost::mutex> lock(future->mutex);
- if(future->done)
- {
- throw promise_already_satisfied();
- }
- future->mark_exceptional_finish_internal(p);
- }
-
- template<typename F>
- void set_wait_callback(F f)
- {
- lazy_init();
- future->set_wait_callback(f,this);
- }
-
- };
-
- namespace detail
- {
- template<typename R>
- struct task_base:
- detail::future_object<R>
- {
- bool started;
-
- task_base():
- started(false)
- {}
-
- void run()
- {
- {
- boost::lock_guard<boost::mutex> lk(this->mutex);
- if(started)
- {
- throw task_already_started();
- }
- started=true;
- }
- do_run();
- }
-
- void owner_destroyed()
- {
- boost::lock_guard<boost::mutex> lk(this->mutex);
- if(!started)
- {
- started=true;
- this->mark_exceptional_finish_internal(boost::copy_exception(boost::broken_promise()));
- }
- }
-
-
- virtual void do_run()=0;
- };
-
-
- template<typename R,typename F>
- struct task_object:
- task_base<R>
- {
- F f;
- task_object(F const& f_):
- f(f_)
- {}
- task_object(boost::detail::thread_move_t<F> f_):
- f(f_)
- {}
-
- void do_run()
- {
- try
- {
- this->mark_finished_with_result(f());
- }
- catch(...)
- {
- this->mark_exceptional_finish();
- }
- }
- };
-
- template<typename F>
- struct task_object<void,F>:
- task_base<void>
- {
- F f;
- task_object(F const& f_):
- f(f_)
- {}
- task_object(boost::detail::thread_move_t<F> f_):
- f(f_)
- {}
-
- void do_run()
- {
- try
- {
- f();
- this->mark_finished_with_result();
- }
- catch(...)
- {
- this->mark_exceptional_finish();
- }
- }
- };
-
- }
-
-
- template<typename R>
- class packaged_task
- {
- boost::shared_ptr<detail::task_base<R> > task;
- bool future_obtained;
-
- packaged_task(packaged_task&);// = delete;
- packaged_task& operator=(packaged_task&);// = delete;
-
- public:
- packaged_task():
- future_obtained(false)
- {}
-
- // construction and destruction
- template <class F>
- explicit packaged_task(F const& f):
- task(new detail::task_object<R,F>(f)),future_obtained(false)
- {}
- explicit packaged_task(R(*f)()):
- task(new detail::task_object<R,R(*)()>(f)),future_obtained(false)
- {}
-
- template <class F>
- explicit packaged_task(boost::detail::thread_move_t<F> f):
- task(new detail::task_object<R,F>(f)),future_obtained(false)
- {}
-
-// template <class F, class Allocator>
-// explicit packaged_task(F const& f, Allocator a);
-// template <class F, class Allocator>
-// explicit packaged_task(F&& f, Allocator a);
-
-
- ~packaged_task()
- {
- if(task)
- {
- task->owner_destroyed();
- }
- }
-
- // assignment
-#ifdef BOOST_HAS_RVALUE_REFS
- packaged_task(packaged_task&& other):
- future_obtained(other.future_obtained)
- {
- task.swap(other.task);
- other.future_obtained=false;
- }
- packaged_task& operator=(packaged_task&& other)
- {
- packaged_task temp(static_cast<packaged_task&&>(other));
- swap(temp);
- return *this;
- }
-#else
- packaged_task(boost::detail::thread_move_t<packaged_task> other):
- future_obtained(other->future_obtained)
- {
- task.swap(other->task);
- other->future_obtained=false;
- }
- packaged_task& operator=(boost::detail::thread_move_t<packaged_task> other)
- {
- packaged_task temp(other);
- swap(temp);
- return *this;
- }
- operator boost::detail::thread_move_t<packaged_task>()
- {
- return boost::detail::thread_move_t<packaged_task>(*this);
- }
-#endif
-
- void swap(packaged_task& other)
- {
- task.swap(other.task);
- std::swap(future_obtained,other.future_obtained);
- }
-
- // result retrieval
- unique_future<R> get_future()
- {
- if(!task)
- {
- throw task_moved();
- }
- else if(!future_obtained)
- {
- future_obtained=true;
- return unique_future<R>(task);
- }
- else
- {
- throw future_already_retrieved();
- }
- }
-
-
- // execution
- void operator()()
- {
- if(!task)
- {
- throw task_moved();
- }
- task->run();
- }
-
- template<typename F>
- void set_wait_callback(F f)
- {
- task->set_wait_callback(f,this);
- }
-
- };
-}
-
-#endif
Modified: sandbox/task/boost/task/handle.hpp
==============================================================================
--- sandbox/task/boost/task/handle.hpp (original)
+++ sandbox/task/boost/task/handle.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -6,21 +6,21 @@
//
// parts are based on boost.future by Anthony Williams
-#ifndef BOOST_TASK_HANDLE_H
-#define BOOST_TASK_HANDLE_H
+#ifndef BOOST_TASKS_HANDLE_H
+#define BOOST_TASKS_HANDLE_H
#include <boost/thread.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/task/context.hpp>
-#include <boost/task/future.hpp>
+#include <boost/thread/future.hpp>
#include <boost/task/exceptions.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
template< typename R >
class handle
@@ -246,4 +246,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_HANDLE_H
+#endif // BOOST_TASKS_HANDLE_H
Deleted: sandbox/task/boost/task/local_rr_ums.hpp
==============================================================================
--- sandbox/task/boost/task/local_rr_ums.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,74 +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_TASK_LOCAL_RR_UMS_H
-#define BOOST_TASK_LOCAL_RR_UMS_H
-
-#include <list>
-
-#include <boost/assert.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/thread.hpp>
-
-#include <boost/task/detail/fiber.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace task {
-
-class local_rr_ums
-{
-private:
- thread_specific_ptr< std::list< detail::fiber::sptr_t > > runnable_;
- thread_specific_ptr< std::list< detail::fiber::sptr_t > > blocked_;
-
-public:
- local_rr_ums() :
- runnable_(), blocked_()
- {}
-
- void attach()
- {
- runnable_.reset( new std::list< detail::fiber::sptr_t >() );
- blocked_.reset( new std::list< detail::fiber::sptr_t >() );
- }
-
- bool has_runnable() const
- { return ! runnable_->empty(); }
-
- bool has_blocked() const
- { return ! blocked_->empty(); }
-
- void put_runnable( detail::fiber::sptr_t const& fib)
- { runnable_->push_back( fib); }
-
- void put_blocked( detail::fiber::sptr_t const& fib)
- { blocked_->push_back( fib); }
-
- bool try_take_runnable( detail::fiber::sptr_t & fib)
- {
- if ( ! has_runnable() ) return false;
- fib = runnable_->front();
- runnable_->pop_front();
- return true;
- }
-
- bool try_take_blocked( detail::fiber::sptr_t & fib)
- {
- if ( ! has_blocked() ) return false;
- fib = blocked_->front();
- blocked_->pop_front();
- return true;
- }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASK_LOCAL_RR_UMS_H
-
Modified: sandbox/task/boost/task/meta.hpp
==============================================================================
--- sandbox/task/boost/task/meta.hpp (original)
+++ sandbox/task/boost/task/meta.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_META_H
-#define BOOST_TASK_META_H
+#ifndef BOOST_TASKS_META_H
+#define BOOST_TASKS_META_H
#include <boost/mpl/bool.hpp>
#include <boost/type_traits/is_same.hpp>
@@ -15,7 +15,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
template< typename Pool >
struct has_attribute : public mpl::bool_<
@@ -36,5 +36,5 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_META_H
+#endif // BOOST_TASKS_META_H
Modified: sandbox/task/boost/task/new_thread.hpp
==============================================================================
--- sandbox/task/boost/task/new_thread.hpp (original)
+++ sandbox/task/boost/task/new_thread.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_NEW_THREAD_H
-#define BOOST_TASK_NEW_THREAD_H
+#ifndef BOOST_TASKS_NEW_THREAD_H
+#define BOOST_TASKS_NEW_THREAD_H
#include <boost/assert.hpp>
#include <boost/config.hpp>
@@ -15,14 +15,14 @@
#include <boost/task/callable.hpp>
#include <boost/task/context.hpp>
-#include <boost/task/future.hpp>
+#include <boost/thread/future.hpp>
#include <boost/task/handle.hpp>
#include <boost/task/task.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
struct joiner
@@ -84,4 +84,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_NEW_THREAD_H
+#endif // BOOST_TASKS_NEW_THREAD_H
Modified: sandbox/task/boost/task/own_thread.hpp
==============================================================================
--- sandbox/task/boost/task/own_thread.hpp (original)
+++ sandbox/task/boost/task/own_thread.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_OWN_THREAD_H
-#define BOOST_TASK_OWN_THREAD_H
+#ifndef BOOST_TASKS_OWN_THREAD_H
+#define BOOST_TASKS_OWN_THREAD_H
#include <boost/config.hpp>
#include <boost/shared_ptr.hpp>
@@ -13,14 +13,14 @@
#include <boost/task/callable.hpp>
#include <boost/task/context.hpp>
-#include <boost/task/future.hpp>
+#include <boost/thread/future.hpp>
#include <boost/task/handle.hpp>
#include <boost/task/task.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
struct own_thread
{
@@ -42,4 +42,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_OWN_THREAD_H
+#endif // BOOST_TASKS_OWN_THREAD_H
Modified: sandbox/task/boost/task/poolsize.hpp
==============================================================================
--- sandbox/task/boost/task/poolsize.hpp (original)
+++ sandbox/task/boost/task/poolsize.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_POOLSIZE_H
-#define BOOST_TASK_POOLSIZE_H
+#ifndef BOOST_TASKS_POOLSIZE_H
+#define BOOST_TASKS_POOLSIZE_H
#include <cstddef>
@@ -19,9 +19,9 @@
# endif
namespace boost {
-namespace task {
+namespace tasks {
-class BOOST_TASK_DECL poolsize
+class BOOST_TASKS_DECL poolsize
{
private:
std::size_t value_;
@@ -40,4 +40,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_POOLSIZE_H
+#endif // BOOST_TASKS_POOLSIZE_H
Modified: sandbox/task/boost/task/scanns.hpp
==============================================================================
--- sandbox/task/boost/task/scanns.hpp (original)
+++ sandbox/task/boost/task/scanns.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_SCANNS_H
-#define BOOST_TASK_SCANNS_H
+#ifndef BOOST_TASKS_SCANNS_H
+#define BOOST_TASKS_SCANNS_H
#include <cstddef>
@@ -19,9 +19,9 @@
# endif
namespace boost {
-namespace task {
+namespace tasks {
-class BOOST_TASK_DECL scanns
+class BOOST_TASKS_DECL scanns
{
private:
std::size_t value_;
@@ -40,4 +40,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_SCANNS_H
+#endif // BOOST_TASKS_SCANNS_H
Deleted: sandbox/task/boost/task/semaphore.hpp
==============================================================================
--- sandbox/task/boost/task/semaphore.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,65 +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_TASK_SEMAPHORE_H
-#define BOOST_TASK_SEMAPHORE_H
-
-#include <boost/task/detail/config.hpp>
-
-extern "C"
-{
-# if defined(BOOST_WINDOWS_API)
-#include <Windows.h>
-# elif defined(BOOST_POSIX_API)
-#include <semaphore.h>
-# endif
-}
-
-#include <boost/utility.hpp>
-
-#include <boost/task/detail/config.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-# if defined(BOOST_MSVC)
-# pragma warning(push)
-# pragma warning(disable:4251 4275)
-# endif
-
-namespace boost {
-namespace task {
-
-class BOOST_TASK_DECL semaphore : private boost::noncopyable
-{
-private:
-# if defined(BOOST_WINDOWS_API)
- HANDLE handle_;
-# elif defined(BOOST_POSIX_API)
- sem_t handle_;;
-# endif
-public:
- semaphore( int);
-
- ~semaphore();
-
- void post();
-
- void wait();
- bool try_wait();
-
- int value();
-};
-
-}}
-
-# if defined(BOOST_MSVC)
-# pragma warning(pop)
-# endif
-
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASK_SEMAPHORE_H
Added: sandbox/task/boost/task/spin/auto_reset_event.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/spin/auto_reset_event.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,47 @@
+
+// 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_SPIN_AUTO_RESET_EVENT_H
+#define BOOST_TASKS_SPIN_AUTO_RESET_EVENT_H
+
+#include <boost/atomic.hpp>
+#include <boost/thread/thread_time.hpp>
+#include <boost/utility.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+class auto_reset_event : private noncopyable
+{
+private:
+ enum state
+ {
+ SET = 0,
+ RESET
+ };
+
+ atomic< state > state_;
+
+public:
+ explicit auto_reset_event( bool = false);
+
+ void set();
+
+ void wait();
+
+ bool try_wait();
+
+ bool wait( system_time const&);
+
+ template< typename TimeDuration >
+ bool wait( TimeDuration const& rel_time)
+ { return wait( get_system_time() + rel_time); }
+};
+
+}}}
+
+#endif // BOOST_TASKS_SPIN_AUTO_RESET_EVENT_H
Added: sandbox/task/boost/task/spin/barrier.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/spin/barrier.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,38 @@
+
+// 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_SPIN_BARRIER_H
+#define BOOST_TASKS_SPIN_BARRIER_H
+
+#include <cstddef>
+
+#include <boost/utility.hpp>
+
+#include <boost/task/spin/condition.hpp>
+#include <boost/task/spin/mutex.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+class barrier : private noncopyable
+{
+private:
+ std::size_t initial_;
+ std::size_t current_;
+ bool cycle_;
+ mutex mtx_;
+ condition cond_;
+
+public:
+ barrier( std::size_t);
+
+ bool wait();
+};
+
+}}}
+
+#endif // BOOST_TASKS_SPIN_BARRIER_H
Added: sandbox/task/boost/task/spin/bounded_channel.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/spin/bounded_channel.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,386 @@
+
+// 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_SPIN_BOUNDED_CHANNEL_H
+#define BOOST_TASKS_SPIN_BOUNDED_CHANNEL_H
+
+#include <cstddef>
+#include <stdexcept>
+
+#include <boost/atomic.hpp>
+#include <boost/intrusive_ptr.hpp>
+#include <boost/optional.hpp>
+#include <boost/thread/thread_time.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task/exceptions.hpp>
+#include <boost/task/spin/condition.hpp>
+#include <boost/task/spin/mutex.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+template< typename T >
+class bounded_channel
+{
+public:
+ typedef optional< T > value_type;
+
+private:
+ class impl : private noncopyable
+ {
+ private:
+ struct node
+ {
+ typedef intrusive_ptr< node > ptr;
+
+ atomic< std::size_t > use_count;
+ value_type va;
+ ptr next;
+
+ node() :
+ use_count( 0),
+ va(),
+ next()
+ {}
+
+ inline friend void intrusive_ptr_add_ref( node * p)
+ { p->use_count.fetch_add( 1, memory_order_relaxed); }
+
+ inline friend void intrusive_ptr_release( node * p)
+ {
+ if ( p->use_count.fetch_sub( 1, memory_order_release) == 1)
+ {
+ atomic_thread_fence( memory_order_acquire);
+ delete p;
+ }
+ }
+ };
+
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
+ };
+
+ atomic< state > state_;
+ atomic< std::size_t > count_;
+ typename node::ptr head_;
+ mutable mutex head_mtx_;
+ typename node::ptr tail_;
+ mutable mutex tail_mtx_;
+ condition not_empty_cond_;
+ condition not_full_cond_;
+ unsigned int hwm_;
+ unsigned int lwm_;
+ atomic< std::size_t > use_count_;
+
+ 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_; }
+
+ typename node::ptr get_tail_() const
+ {
+ mutex::scoped_lock lk( tail_mtx_);
+ typename node::ptr tmp = tail_;
+ return tmp;
+ }
+
+ typename node::ptr pop_head_()
+ {
+ typename node::ptr old_head = head_;
+ head_ = old_head->next;
+ count_.fetch_sub( 1);
+ return old_head;
+ }
+
+ public:
+ impl(
+ std::size_t hwm,
+ std::size_t lwm) :
+ state_( ACTIVE),
+ count_( 0),
+ head_( new node() ),
+ head_mtx_(),
+ tail_( head_),
+ tail_mtx_(),
+ not_empty_cond_(),
+ not_full_cond_(),
+ hwm_( hwm),
+ lwm_( lwm),
+ use_count_( 0)
+ {
+ if ( hwm_ < lwm_)
+ throw invalid_watermark();
+ }
+
+ impl( std::size_t wm) :
+ state_( ACTIVE),
+ count_( 0),
+ head_( new node() ),
+ head_mtx_(),
+ tail_( head_),
+ tail_mtx_(),
+ not_empty_cond_(),
+ not_full_cond_(),
+ hwm_( wm),
+ lwm_( wm),
+ use_count_( 0)
+ {}
+
+ void upper_bound_( std::size_t hwm)
+ {
+ if ( hwm < lwm_)
+ throw invalid_watermark();
+ unsigned int 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();
+ unsigned int tmp( lwm_);
+ lwm_ = lwm;
+ if ( lwm_ > tmp) not_full_cond_.notify_one();
+ }
+
+ std::size_t lower_bound() const
+ { return lwm_; }
+
+ void deactivate()
+ { deactivate_(); }
+
+ bool empty() const
+ {
+ mutex::scoped_lock lk( head_mtx_);
+ return empty_();
+ }
+
+ void put( T const& t)
+ {
+ typename node::ptr new_node( new node() );
+ {
+ mutex::scoped_lock lk( tail_mtx_);
+
+ if ( full_() )
+ {
+ while ( active_() && full_() )
+ not_full_cond_.wait( lk);
+ }
+
+ if ( ! active_() )
+ throw std::runtime_error("queue is not active");
+
+ tail_->va = t;
+ tail_->next = new_node;
+ tail_ = new_node;
+ count_.fetch_add( 1);
+ }
+ not_empty_cond_.notify_one();
+ }
+
+ bool put( T const& t, system_time const& abs_time)
+ {
+ typename node::ptr new_node( new node() );
+ {
+ mutex::scoped_lock lk( tail_mtx_);
+
+ if ( full_() )
+ {
+ while ( active_() && full_() )
+ if ( ! not_full_cond_.timed_wait( lk, abs_time) );
+ return false;
+ }
+
+ if ( ! active_() )
+ throw std::runtime_error("queue is not active");
+
+ tail_->va = t;
+ tail_->next = new_node;
+ tail_ = new_node;
+ count_.fetch_add( 1);
+ }
+ not_empty_cond_.notify_one();
+ return true;
+ }
+
+ bool take( value_type & va)
+ {
+ mutex::scoped_lock lk( head_mtx_);
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ while ( active_() && empty_() )
+ not_empty_cond_.wait( lk);
+ }
+ catch ( task_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ swap( va, 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;
+ }
+
+ bool take( value_type & va, system_time const& abs_time)
+ {
+ mutex::scoped_lock lk( head_mtx_);
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ while ( active_() && empty_() )
+ if ( ! not_empty_cond_.timed_wait( lk, abs_time) )
+ return false;
+ }
+ catch ( task_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ swap( va, 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;
+ }
+
+ bool try_take( value_type & va)
+ {
+ mutex::scoped_lock lk( head_mtx_);
+ if ( empty_() )
+ return false;
+ swap( va, head_->va);
+ pop_head_();
+ bool valid = va;
+ 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;
+ }
+
+ inline friend void intrusive_ptr_add_ref( impl * p)
+ { p->use_count_.fetch_add( 1, memory_order_relaxed); }
+
+ inline friend void intrusive_ptr_release( impl * p)
+ {
+ if ( p->use_count_.fetch_sub( 1, memory_order_release) == 1)
+ {
+ atomic_thread_fence( memory_order_acquire);
+ delete p;
+ }
+ }
+ };
+
+ intrusive_ptr< impl > impl_;
+
+public:
+ bounded_channel(
+ std::size_t hwm,
+ std::size_t lwm) :
+ impl_( new impl( hwm, lwm) )
+ {}
+
+ bounded_channel( std::size_t wm) :
+ impl_( new impl( wm) )
+ {}
+
+ void upper_bound( std::size_t hwm)
+ { impl_->upper_bound( hwm); }
+
+ std::size_t upper_bound() const
+ { return impl_->upper_bound(); }
+
+ void lower_bound( std::size_t lwm)
+ { impl_->lower_bound( lwm); }
+
+ std::size_t lower_bound() const
+ { return impl_->lower_bound(); }
+
+ void deactivate()
+ { impl_->deactivate(); }
+
+ bool empty() const
+ { return impl_->empty(); }
+
+ void put( T const& t)
+ { impl_->put( t); }
+
+ bool put( T const& t, system_time const& abs_time)
+ { return impl_->put( t, abs_time); }
+
+ template< typename TimeDuration >
+ bool put( T const& t, TimeDuration const& rel_time)
+ { return impl_->put( t, get_system_time() + rel_time); }
+
+ bool take( value_type & va)
+ { return impl_->take( va);}
+
+ bool take( value_type & va, system_time const& abs_time)
+ { return impl_->take( va, abs_time);}
+
+ template< typename TimeDuration >
+ bool take( value_type & va, TimeDuration const& rel_time)
+ { return impl_->take( va, get_system_time() + rel_time);}
+
+ bool try_take( value_type & va)
+ { return impl_->try_take( va); }
+};
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_TASKS_SPIN_BOUNDED_CHANNEL_H
Added: sandbox/task/boost/task/spin/condition.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/spin/condition.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,292 @@
+
+// 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)
+//
+// based on boost::interprocess::sync::interprocess_condition
+
+#ifndef BOOST_TASKS_SPIN_CONDITION_H
+#define BOOST_TASKS_SPIN_CONDITION_H
+
+#include <cstddef>
+
+#include <boost/assert.hpp>
+#include <boost/atomic.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/thread_time.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task/exceptions.hpp>
+#include <boost/task/spin/mutex.hpp>
+#include <boost/task/utility.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+class condition : private noncopyable
+{
+private:
+ enum command
+ {
+ SLEEPING = 0,
+ NOTIFY_ONE,
+ NOTIFY_ALL
+ };
+
+ atomic< command > cmd_;
+ atomic< std::size_t > waiters_;
+ mutex enter_mtx_;
+ mutex check_mtx_;
+
+ void notify_( command);
+
+public:
+ condition();
+
+ void notify_one();
+
+ void notify_all();
+
+ void wait( unique_lock< mutex > & lk)
+ {
+ if ( ! lk)
+ throw lock_error();
+ wait( * lk.mutex() );
+ }
+
+ template< typename Pred >
+ void wait( unique_lock< mutex > & lk, Pred pred)
+ {
+ if ( ! lk)
+ throw lock_error();
+
+ while ( ! pred() )
+ wait( * lk.mutex() );
+ }
+
+ bool timed_wait( unique_lock< mutex > & lk, system_time const& abs_time)
+ {
+ if ( abs_time.is_infinity() )
+ {
+ wait( lk);
+ return true;
+ }
+
+ if ( ! lk)
+ throw lock_error();
+ return timed_wait( * lk.mutex(), abs_time);
+ }
+
+ template< typename Pred >
+ bool timed_wait( unique_lock< mutex > & lk, system_time const& abs_time, Pred pred)
+ {
+ if ( abs_time.is_infinity() )
+ {
+ wait( lk, pred);
+ return true;
+ }
+
+ if ( ! lk)
+ throw lock_error();
+
+ while ( ! pred() )
+ if ( ! timed_wait( * lk.mutex(), abs_time) )
+ return pred();
+ return true;
+ }
+
+ template< typename TimeDuration >
+ bool timed_wait( unique_lock< mutex > & lk, TimeDuration const& rel_time)
+ { return timed_wait( lk, get_system_time() + rel_time); }
+
+ template<
+ typename TimeDuration,
+ typename Pred
+ >
+ bool timed_wait( unique_lock< mutex > & lk, TimeDuration const& rel_time, Pred pred)
+ { return timed_wait( lk, get_system_time() + rel_time, pred); }
+
+ template< typename LockType >
+ void wait( LockType & lt)
+ {
+ {
+ mutex::scoped_lock lk( enter_mtx_);
+ BOOST_ASSERT( lk);
+ waiters_.fetch_add( 1);
+ lt.unlock();
+ }
+
+ bool unlock_enter_mtx = false;
+ for (;;)
+ {
+ while ( SLEEPING == cmd_.load() )
+ {
+ this_thread::interruption_point();
+ if ( this_task::runs_in_pool() )
+ this_task::block();
+ else
+ this_thread::yield();
+ this_thread::interruption_point();
+ }
+
+ mutex::scoped_lock lk( check_mtx_);
+ BOOST_ASSERT( lk);
+
+ command expected = NOTIFY_ONE;
+ cmd_.compare_exchange_strong( expected, SLEEPING);
+ if ( SLEEPING == expected)
+ continue;
+ else if ( NOTIFY_ONE == expected)
+ {
+ unlock_enter_mtx = true;
+ waiters_.fetch_sub( 1);
+ break;
+ }
+ else
+ {
+ unlock_enter_mtx = 1 == waiters_.fetch_sub( 1);
+ if ( unlock_enter_mtx)
+ {
+ expected = NOTIFY_ALL;
+ cmd_.compare_exchange_strong( expected, SLEEPING);
+ }
+ break;
+ }
+ }
+
+ if ( unlock_enter_mtx)
+ enter_mtx_.unlock();
+
+ lt.lock();
+ }
+
+ template<
+ typename LockType,
+ typename Pred
+ >
+ void wait( LockType & lt, Pred pred)
+ {
+ while ( ! pred() )
+ wait( lt);
+ }
+
+ template< typename LockType >
+ bool timed_wait( LockType & lt, system_time const& abs_time)
+ {
+ if ( abs_time.is_infinity() )
+ {
+ wait( lt);
+ return true;
+ }
+
+ if ( get_system_time() >= abs_time) return false;
+
+ {
+ mutex::scoped_lock lk( enter_mtx_, abs_time);
+ BOOST_ASSERT( lk);
+ waiters_.fetch_add( 1);
+ lt.unlock();
+ }
+
+ bool timed_out = false, unlock_enter_mtx = false;
+ for (;;)
+ {
+ while ( SLEEPING == cmd_.load() )
+ {
+ this_thread::interruption_point();
+ if ( this_task::runs_in_pool() )
+ this_task::block();
+ else
+ this_thread::yield();
+ this_thread::interruption_point();
+
+ if ( get_system_time() >= abs_time)
+ {
+ timed_out = enter_mtx_.try_lock();
+ if ( ! timed_out)
+ continue;
+ break;
+ }
+ }
+
+ if ( timed_out)
+ {
+ waiters_.fetch_sub( 1);
+ unlock_enter_mtx = true;
+ break;
+ }
+ else
+ {
+ mutex::scoped_lock lk( check_mtx_);
+ BOOST_ASSERT( lk);
+
+ command expected = NOTIFY_ONE;
+ cmd_.compare_exchange_strong( expected, SLEEPING);
+ if ( SLEEPING == expected)
+ continue;
+ else if ( NOTIFY_ONE == expected)
+ {
+ unlock_enter_mtx = true;
+ waiters_.fetch_sub( 1);
+ break;
+ }
+ else
+ {
+ unlock_enter_mtx = 1 == waiters_.fetch_sub( 1);
+ if ( unlock_enter_mtx)
+ {
+ expected = NOTIFY_ALL;
+ cmd_.compare_exchange_strong( expected, SLEEPING);
+ }
+ break;
+ }
+ }
+ }
+
+ if ( unlock_enter_mtx)
+ enter_mtx_.unlock();
+
+ lt.lock();
+
+ return ! timed_out;
+ }
+
+ template<
+ typename LockType,
+ typename Pred
+ >
+ bool timed_wait( LockType & lt, system_time const& abs_time, Pred pred)
+ {
+ if ( abs_time.is_infinity() )
+ {
+ wait( lt, pred);
+ return true;
+ }
+
+ while ( ! pred() )
+ if ( ! wait( lt, abs_time) )
+ return pred();
+ return true;
+ }
+
+ template<
+ typename LockType,
+ typename TimeDuration
+ >
+ bool timed_wait( LockType & lt, TimeDuration const& rel_time)
+ { return timed_wait( lt, get_system_time() + rel_time); }
+
+ template<
+ typename LockType,
+ typename TimeDuration,
+ typename Pred
+ >
+ bool timed_wait( LockType & lt, TimeDuration const& rel_time, Pred pred)
+ { return timed_wait( lt, get_system_time() + rel_time, pred); }
+};
+
+}}}
+
+#endif // BOOST_TASKS_SPIN_CONDITION_H
Added: sandbox/task/boost/task/spin/count_down_event.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/spin/count_down_event.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,48 @@
+
+// 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_SPIN_COUNT_DOWN_EVENT_H
+#define BOOST_TASKS_SPIN_COUNT_DOWN_EVENT_H
+
+#include <cstddef>
+
+#include <boost/atomic.hpp>
+#include <boost/thread/thread_time.hpp>
+#include <boost/utility.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+class count_down_event : private noncopyable
+{
+private:
+ std::size_t initial_;
+ atomic< std::size_t > current_;
+
+public:
+ explicit count_down_event( std::size_t);
+
+ std::size_t initial() const;
+
+ std::size_t current() const;
+
+ bool is_set() const;
+
+ void set();
+
+ void wait();
+
+ bool wait( system_time const&);
+
+ template< typename TimeDuration >
+ bool wait( TimeDuration const& rel_time)
+ { return wait( get_system_time() + rel_time); }
+};
+
+}}}
+
+#endif // BOOST_TASKS_SPIN_COUNT_DOWN_EVENT_H
Added: sandbox/task/boost/task/spin/future.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/spin/future.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,1081 @@
+// (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_FIBERS_SPIN_FUTURE_HPP
+#define BOOST_FIBERS_SPIN_FUTURE_HPP
+
+#include <algorithm>
+#include <list>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/config.hpp>
+#include <boost/exception_ptr.hpp>
+#include <boost/function.hpp>
+#include <boost/move/move.hpp>
+#include <boost/next_prior.hpp>
+#include <boost/ref.hpp>
+#include <boost/scoped_array.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/utility/enable_if.hpp>
+
+#include <boost/fiber/detail/future_traits.hpp>
+#include <boost/fiber/spin/condition.hpp>
+#include <boost/fiber/spin/mutex.hpp>
+
+namespace boost {
+namespace fibers {
+
+namespace future_state {
+
+ enum state { uninitialized, waiting, ready, moved };
+
+}
+
+namespace spin {
+namespace detail {
+
+struct future_object_base
+{
+ boost::exception_ptr exception;
+ bool done;
+ mutex mtx;
+ condition waiters;
+ typedef std::list<condition*> waiter_list;
+ waiter_list external_waiters;
+ boost::function<void()> callback;
+
+ future_object_base():
+ done(false)
+ {}
+
+ virtual ~future_object_base()
+ {}
+
+ waiter_list::iterator register_external_waiter(condition& cv)
+ {
+ boost::unique_lock<mutex> lock(mtx);
+ do_callback(lock);
+ return external_waiters.insert(external_waiters.end(),&cv);
+ }
+
+ void remove_external_waiter(waiter_list::iterator it)
+ {
+ boost::lock_guard<mutex> lock(mtx);
+ external_waiters.erase(it);
+ }
+
+ void mark_finished_internal()
+ {
+ done=true;
+ waiters.notify_all();
+ for(waiter_list::const_iterator it=external_waiters.begin(),
+ end=external_waiters.end();it!=end;++it)
+ {
+ (*it)->notify_all();
+ }
+ }
+
+ struct relocker
+ {
+ boost::unique_lock<mutex>& lock;
+
+ relocker(boost::unique_lock<mutex>& lock_):
+ lock(lock_)
+ {
+ lock.unlock();
+ }
+ ~relocker()
+ {
+ lock.lock();
+ }
+ };
+
+ void do_callback(boost::unique_lock<mutex>& lock)
+ {
+ if(callback && !done)
+ {
+ boost::function<void()> local_callback=callback;
+ relocker relock(lock);
+ local_callback();
+ }
+ }
+
+
+ void wait(bool rethrow=true)
+ {
+ boost::unique_lock<mutex> lock(mtx);
+ do_callback(lock);
+ while(!done)
+ {
+ waiters.wait(lock);
+ }
+ if(rethrow && exception)
+ {
+ boost::rethrow_exception(exception);
+ }
+ }
+
+ void mark_exceptional_finish_internal(boost::exception_ptr const& e)
+ {
+ exception=e;
+ mark_finished_internal();
+ }
+ void mark_exceptional_finish()
+ {
+ boost::lock_guard<mutex> lock(mtx);
+ mark_exceptional_finish_internal(boost::current_exception());
+ }
+
+ bool has_value()
+ {
+ boost::lock_guard<mutex> lock(mtx);
+ return done && !exception;
+ }
+ bool has_exception()
+ {
+ boost::lock_guard<mutex> lock(mtx);
+ return done && exception;
+ }
+
+ template<typename F,typename U>
+ void set_wait_callback(F f,U* u)
+ {
+ callback=boost::bind(f,boost::ref(*u));
+ }
+
+private:
+ future_object_base(future_object_base const&);
+ future_object_base& operator=(future_object_base const&);
+};
+
+template<typename T>
+struct future_object: future_object_base
+{
+ typedef typename fibers::detail::future_traits<T>::storage_type storage_type;
+ typedef typename fibers::detail::future_traits<T>::source_reference_type source_reference_type;
+ typedef typename fibers::detail::future_traits<T>::rvalue_source_type rvalue_source_type;
+ typedef typename fibers::detail::future_traits<T>::move_dest_type move_dest_type;
+
+ storage_type result;
+
+ future_object():
+ result(0)
+ {}
+
+ void mark_finished_with_result_internal(source_reference_type result_)
+ {
+ fibers::detail::future_traits<T>::init(result,result_);
+ mark_finished_internal();
+ }
+ void mark_finished_with_result_internal(rvalue_source_type result_)
+ {
+ fibers::detail::future_traits<T>::init(result,static_cast<rvalue_source_type>(result_));
+ mark_finished_internal();
+ }
+
+ void mark_finished_with_result(source_reference_type result_)
+ {
+ boost::lock_guard<mutex> lock(mtx);
+ mark_finished_with_result_internal(result_);
+ }
+ void mark_finished_with_result(rvalue_source_type result_)
+ {
+ boost::lock_guard<mutex> lock(mtx);
+ mark_finished_with_result_internal(result_);
+ }
+
+ move_dest_type get()
+ {
+ wait();
+ return *result;
+ }
+
+ future_state::state get_state()
+ {
+ boost::lock_guard<mutex> guard(mtx);
+ if(!done)
+ {
+ return future_state::waiting;
+ }
+ else
+ {
+ return future_state::ready;
+ }
+ }
+
+private:
+ future_object(future_object const&);
+ future_object& operator=(future_object const&);
+};
+
+template<>
+struct future_object<void>: future_object_base
+{
+ future_object()
+ {}
+
+ void mark_finished_with_result_internal()
+ {
+ mark_finished_internal();
+ }
+
+ void mark_finished_with_result()
+ {
+ boost::lock_guard<mutex> lock(mtx);
+ mark_finished_with_result_internal();
+ }
+
+ void get()
+ {
+ wait();
+ }
+
+ future_state::state get_state()
+ {
+ boost::lock_guard<mutex> guard(mtx);
+ if(!done)
+ {
+ return future_state::waiting;
+ }
+ else
+ {
+ return future_state::ready;
+ }
+ }
+
+private:
+ future_object(future_object const&);
+ future_object& operator=(future_object const&);
+};
+
+class future_waiter
+{
+ struct registered_waiter
+ {
+ boost::shared_ptr<detail::future_object_base> future;
+ detail::future_object_base::waiter_list::iterator wait_iterator;
+ unsigned index;
+
+ registered_waiter(boost::shared_ptr<detail::future_object_base> const& future_,
+ detail::future_object_base::waiter_list::iterator wait_iterator_,
+ unsigned index_):
+ future(future_),wait_iterator(wait_iterator_),index(index_)
+ {}
+
+ };
+
+ struct all_futures_lock
+ {
+ unsigned count;
+ boost::scoped_array<boost::unique_lock<mutex> > locks;
+
+ all_futures_lock(std::vector<registered_waiter>& futures):
+ count(futures.size()),locks(new boost::unique_lock<mutex>[count])
+ {
+ for(unsigned i=0;i<count;++i)
+ {
+ locks[i]=boost::unique_lock<mutex>(futures[i].future->mtx);
+ }
+ }
+
+ void lock()
+ {
+ boost::lock(locks.get(),locks.get()+count);
+ }
+
+ void unlock()
+ {
+ for(unsigned i=0;i<count;++i)
+ {
+ locks[i].unlock();
+ }
+ }
+ };
+
+ condition cv;
+ std::vector<registered_waiter> futures;
+ unsigned future_count;
+
+public:
+ future_waiter():
+ future_count(0)
+ {}
+
+ template<typename F>
+ void add(F& f)
+ {
+ if(f.future)
+ {
+ futures.push_back(registered_waiter(f.future,f.future->register_external_waiter(cv),future_count));
+ }
+ ++future_count;
+ }
+
+ unsigned wait()
+ {
+ all_futures_lock lk(futures);
+ for(;;)
+ {
+ for(unsigned i=0;i<futures.size();++i)
+ {
+ if(futures[i].future->done)
+ {
+ return futures[i].index;
+ }
+ }
+ cv.wait(lk);
+ }
+ }
+
+ ~future_waiter()
+ {
+ for(unsigned i=0;i<futures.size();++i)
+ {
+ futures[i].future->remove_external_waiter(futures[i].wait_iterator);
+ }
+ }
+
+};
+
+}
+
+template <typename R>
+class unique_future;
+
+template <typename R>
+class shared_future;
+
+template<typename T>
+struct is_future_type
+{
+ BOOST_STATIC_CONSTANT(bool, value=false);
+};
+
+template<typename T>
+struct is_future_type<unique_future<T> >
+{
+ BOOST_STATIC_CONSTANT(bool, value=true);
+};
+
+template<typename T>
+struct is_future_type<shared_future<T> >
+{
+ BOOST_STATIC_CONSTANT(bool, value=true);
+};
+
+template<typename Iterator>
+typename boost::disable_if<is_future_type<Iterator>,void>::type wait_for_all(Iterator begin,Iterator end)
+{
+ for(Iterator current=begin;current!=end;++current)
+ {
+ current->wait();
+ }
+}
+
+template<typename F1,typename F2>
+typename boost::enable_if<is_future_type<F1>,void>::type wait_for_all(F1& f1,F2& f2)
+{
+ f1.wait();
+ f2.wait();
+}
+
+template<typename F1,typename F2,typename F3>
+void wait_for_all(F1& f1,F2& f2,F3& f3)
+{
+ f1.wait();
+ f2.wait();
+ f3.wait();
+}
+
+template<typename F1,typename F2,typename F3,typename F4>
+void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4)
+{
+ f1.wait();
+ f2.wait();
+ f3.wait();
+ f4.wait();
+}
+
+template<typename F1,typename F2,typename F3,typename F4,typename F5>
+void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5)
+{
+ f1.wait();
+ f2.wait();
+ f3.wait();
+ f4.wait();
+ f5.wait();
+}
+
+template<typename Iterator>
+typename boost::disable_if<is_future_type<Iterator>,Iterator>::type wait_for_any(Iterator begin,Iterator end)
+{
+ detail::future_waiter waiter;
+ for(Iterator current=begin;current!=end;++current)
+ {
+ waiter.add(*current);
+ }
+ return boost::next(begin,waiter.wait());
+}
+
+template<typename F1,typename F2>
+typename boost::enable_if<is_future_type<F1>,unsigned>::type wait_for_any(F1& f1,F2& f2)
+{
+ detail::future_waiter waiter;
+ waiter.add(f1);
+ waiter.add(f2);
+ return waiter.wait();
+}
+
+template<typename F1,typename F2,typename F3>
+unsigned wait_for_any(F1& f1,F2& f2,F3& f3)
+{
+ detail::future_waiter waiter;
+ waiter.add(f1);
+ waiter.add(f2);
+ waiter.add(f3);
+ return waiter.wait();
+}
+
+template<typename F1,typename F2,typename F3,typename F4>
+unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4)
+{
+ detail::future_waiter waiter;
+ waiter.add(f1);
+ waiter.add(f2);
+ waiter.add(f3);
+ waiter.add(f4);
+ return waiter.wait();
+}
+
+template<typename F1,typename F2,typename F3,typename F4,typename F5>
+unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5)
+{
+ detail::future_waiter waiter;
+ waiter.add(f1);
+ waiter.add(f2);
+ waiter.add(f3);
+ waiter.add(f4);
+ waiter.add(f5);
+ return waiter.wait();
+}
+
+template <typename R>
+class promise;
+
+template <typename R>
+class packaged_task;
+
+template <typename R>
+class unique_future
+{
+ typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
+
+ BOOST_MOVABLE_BUT_NOT_COPYABLE( unique_future);
+
+ future_ptr future;
+
+ friend class shared_future<R>;
+ friend class promise<R>;
+ friend class packaged_task<R>;
+ friend class detail::future_waiter;
+
+ typedef typename fibers::detail::future_traits<R>::move_dest_type move_dest_type;
+
+ unique_future(future_ptr future_):
+ future(future_)
+ {}
+
+public:
+ typedef future_state::state state;
+
+ unique_future()
+ {}
+
+ ~unique_future()
+ {}
+
+ unique_future( BOOST_RV_REF( unique_future) other):
+ future(other.future)
+ {
+ other.future.reset();
+ }
+
+ unique_future& operator=( BOOST_RV_REF( unique_future) other)
+ {
+ future=other.future;
+ other.future.reset();
+ return *this;
+ }
+
+ void swap(unique_future& other)
+ {
+ future.swap(other.future);
+ }
+
+ // retrieving the value
+ move_dest_type get()
+ {
+ if(!future)
+ {
+ throw future_uninitialized();
+ }
+
+ return future->get();
+ }
+
+ // functions to check state, and wait for ready
+ state get_state() const
+ {
+ if(!future)
+ {
+ return future_state::uninitialized;
+ }
+ return future->get_state();
+ }
+
+
+ bool is_ready() const
+ {
+ return get_state()==future_state::ready;
+ }
+
+ bool has_exception() const
+ {
+ return future && future->has_exception();
+ }
+
+ bool has_value() const
+ {
+ return future && future->has_value();
+ }
+
+ void wait() const
+ {
+ if(!future)
+ {
+ throw future_uninitialized();
+ }
+ future->wait(false);
+ }
+};
+
+template <typename R>
+class shared_future
+{
+ typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
+
+ BOOST_COPYABLE_AND_MOVABLE( shared_future);
+
+ future_ptr future;
+
+ friend class detail::future_waiter;
+ friend class promise<R>;
+ friend class packaged_task<R>;
+
+ shared_future(future_ptr future_):
+ future(future_)
+ {}
+
+public:
+ shared_future(shared_future const& other):
+ future(other.future)
+ {}
+
+ typedef future_state::state state;
+
+ shared_future()
+ {}
+
+ ~shared_future()
+ {}
+
+ shared_future& operator=( BOOST_COPY_ASSIGN_REF( shared_future) other)
+ {
+ future=other.future;
+ return *this;
+ }
+
+ shared_future( BOOST_RV_REF( shared_future) other):
+ future(other.future)
+ {
+ other->future.reset();
+ }
+ shared_future( BOOST_RV_REF( unique_future<R>) other):
+ future(other.future)
+ {
+ other.future.reset();
+ }
+ shared_future& operator=(BOOST_RV_REF( shared_future) other)
+ {
+ future.swap(other.future);
+ other.future.reset();
+ return *this;
+ }
+ shared_future& operator=( BOOST_RV_REF( unique_future<R>) other)
+ {
+ future.swap(other.future);
+ other.future.reset();
+ return *this;
+ }
+
+ void swap(shared_future& other)
+ {
+ future.swap(other.future);
+ }
+
+ // retrieving the value
+ R get()
+ {
+ if(!future)
+ {
+ throw future_uninitialized();
+ }
+
+ return future->get();
+ }
+
+ // functions to check state, and wait for ready
+ state get_state() const
+ {
+ if(!future)
+ {
+ return future_state::uninitialized;
+ }
+ return future->get_state();
+ }
+
+
+ bool is_ready() const
+ {
+ return get_state()==future_state::ready;
+ }
+
+ bool has_exception() const
+ {
+ return future && future->has_exception();
+ }
+
+ bool has_value() const
+ {
+ return future && future->has_value();
+ }
+
+ void wait() const
+ {
+ if(!future)
+ {
+ throw future_uninitialized();
+ }
+ future->wait(false);
+ }
+};
+
+template <typename R>
+class promise
+{
+ typedef boost::shared_ptr<detail::future_object<R> > future_ptr;
+
+ BOOST_MOVABLE_BUT_NOT_COPYABLE( promise);
+
+ future_ptr future;
+ bool future_obtained;
+
+ void lazy_init()
+ {
+ if(!future)
+ {
+ future_obtained=false;
+ future.reset(new detail::future_object<R>);
+ }
+ }
+
+public:
+// template <class Allocator> explicit promise(Allocator a);
+
+ promise():
+ future(),future_obtained(false)
+ {}
+
+ ~promise()
+ {
+ if(future)
+ {
+ boost::lock_guard<mutex> lock(future->mtx);
+
+ if(!future->done)
+ {
+ future->mark_exceptional_finish_internal(boost::copy_exception(broken_promise()));
+ }
+ }
+ }
+
+ promise( BOOST_RV_REF( promise) rhs):
+ future(rhs.future),future_obtained(rhs.future_obtained)
+ {
+ rhs.future.reset();
+ }
+ promise & operator=( BOOST_RV_REF( promise) rhs)
+ {
+ future=rhs.future;
+ future_obtained=rhs.future_obtained;
+ rhs.future.reset();
+ return *this;
+ }
+
+ void swap(promise& other)
+ {
+ future.swap(other.future);
+ std::swap(future_obtained,other.future_obtained);
+ }
+
+ // Result retrieval
+ unique_future<R> get_future()
+ {
+ lazy_init();
+ if(future_obtained)
+ {
+ throw future_already_retrieved();
+ }
+ future_obtained=true;
+ return unique_future<R>(future);
+ }
+
+ void set_value(typename fibers::detail::future_traits<R>::source_reference_type r)
+ {
+ lazy_init();
+ boost::lock_guard<mutex> lock(future->mtx);
+ if(future->done)
+ {
+ throw promise_already_satisfied();
+ }
+ future->mark_finished_with_result_internal(r);
+ }
+
+// void set_value(R && r);
+ void set_value(typename fibers::detail::future_traits<R>::rvalue_source_type r)
+ {
+ lazy_init();
+ boost::lock_guard<mutex> lock(future->mtx);
+ if(future->done)
+ {
+ throw promise_already_satisfied();
+ }
+ future->mark_finished_with_result_internal(static_cast<typename fibers::detail::future_traits<R>::rvalue_source_type>(r));
+ }
+
+ void set_exception(boost::exception_ptr p)
+ {
+ lazy_init();
+ boost::lock_guard<mutex> lock(future->mtx);
+ if(future->done)
+ {
+ throw promise_already_satisfied();
+ }
+ future->mark_exceptional_finish_internal(p);
+ }
+
+ template<typename F>
+ void set_wait_callback(F f)
+ {
+ lazy_init();
+ future->set_wait_callback(f,this);
+ }
+
+};
+
+template <>
+class promise<void>
+{
+ typedef boost::shared_ptr<detail::future_object<void> > future_ptr;
+
+ BOOST_MOVABLE_BUT_NOT_COPYABLE( promise);
+
+ future_ptr future;
+ bool future_obtained;
+
+ void lazy_init()
+ {
+ if(!future)
+ {
+ future_obtained=false;
+ future.reset(new detail::future_object<void>);
+ }
+ }
+public:
+ promise():
+ future(),future_obtained(false)
+ {}
+
+ ~promise()
+ {
+ if(future)
+ {
+ boost::lock_guard<mutex> lock(future->mtx);
+
+ if(!future->done)
+ {
+ future->mark_exceptional_finish_internal(boost::copy_exception(broken_promise()));
+ }
+ }
+ }
+
+ promise( BOOST_RV_REF( promise) rhs):
+ future(rhs.future),future_obtained(rhs.future_obtained)
+ {
+ rhs.future.reset();
+ }
+ promise & operator=( BOOST_RV_REF( promise) rhs)
+ {
+ future=rhs.future;
+ future_obtained=rhs.future_obtained;
+ rhs.future.reset();
+ return *this;
+ }
+
+ void swap(promise& other)
+ {
+ future.swap(other.future);
+ std::swap(future_obtained,other.future_obtained);
+ }
+
+ // Result retrieval
+ unique_future<void> get_future()
+ {
+ lazy_init();
+
+ if(future_obtained)
+ {
+ throw future_already_retrieved();
+ }
+ future_obtained=true;
+ return unique_future<void>(future);
+ }
+
+ void set_value()
+ {
+ lazy_init();
+ boost::lock_guard<mutex> lock(future->mtx);
+ if(future->done)
+ {
+ throw promise_already_satisfied();
+ }
+ future->mark_finished_with_result_internal();
+ }
+
+ void set_exception(boost::exception_ptr p)
+ {
+ lazy_init();
+ boost::lock_guard<mutex> lock(future->mtx);
+ if(future->done)
+ {
+ throw promise_already_satisfied();
+ }
+ future->mark_exceptional_finish_internal(p);
+ }
+
+ template<typename F>
+ void set_wait_callback(F f)
+ {
+ lazy_init();
+ future->set_wait_callback(f,this);
+ }
+};
+
+namespace detail {
+
+template<typename R>
+struct task_base:
+ detail::future_object<R>
+{
+ bool started;
+
+ task_base():
+ started(false)
+ {}
+
+ void run()
+ {
+ {
+ boost::lock_guard<mutex> lk(this->mtx);
+ if(started)
+ {
+ throw task_already_started();
+ }
+ started=true;
+ }
+ do_run();
+ }
+
+ void owner_destroyed()
+ {
+ boost::lock_guard<mutex> lk(this->mtx);
+ if(!started)
+ {
+ started=true;
+ this->mark_exceptional_finish_internal(boost::copy_exception(broken_promise()));
+ }
+ }
+
+
+ virtual void do_run()=0;
+};
+
+
+template<typename R,typename F>
+struct task_object:
+ task_base<R>
+{
+ F f;
+ task_object(F const& f_):
+ f(f_)
+ {}
+ task_object( BOOST_RV_REF( F) f_):
+ f(f_)
+ {}
+
+ void do_run()
+ {
+ try
+ {
+ this->mark_finished_with_result(f());
+ }
+ catch(...)
+ {
+ this->mark_exceptional_finish();
+ }
+ }
+};
+
+template<typename F>
+struct task_object<void,F>:
+ task_base<void>
+{
+ F f;
+ task_object(F const& f_):
+ f(f_)
+ {}
+ task_object( BOOST_RV_REF( F) f_):
+ f(f_)
+ {}
+
+ void do_run()
+ {
+ try
+ {
+ f();
+ this->mark_finished_with_result();
+ }
+ catch(...)
+ {
+ this->mark_exceptional_finish();
+ }
+ }
+};
+
+}
+
+
+template<typename R>
+class packaged_task
+{
+ BOOST_MOVABLE_BUT_NOT_COPYABLE( packaged_task);
+
+ boost::shared_ptr<detail::task_base<R> > task;
+ bool future_obtained;
+
+public:
+ packaged_task():
+ future_obtained(false)
+ {}
+
+ // construction and destruction
+ template <class F>
+ explicit packaged_task(F const& f):
+ task(new detail::task_object<R,F>(f)),future_obtained(false)
+ {}
+ explicit packaged_task(R(*f)()):
+ task(new detail::task_object<R,R(*)()>(f)),future_obtained(false)
+ {}
+
+ template <class F>
+ explicit packaged_task( BOOST_RV_REF( F) f):
+ task(new detail::task_object<R,F>(f)),future_obtained(false)
+ {}
+
+// template <class F, class Allocator>
+// explicit packaged_task(F const& f, Allocator a);
+// template <class F, class Allocator>
+// explicit packaged_task(F&& f, Allocator a);
+
+
+ ~packaged_task()
+ {
+ if(task)
+ {
+ task->owner_destroyed();
+ }
+ }
+
+ packaged_task( BOOST_RV_REF( packaged_task) other):
+ future_obtained(other.future_obtained)
+ {
+ task.swap(other.task);
+ other.future_obtained=false;
+ }
+ packaged_task& operator=( BOOST_RV_REF( packaged_task) other)
+ {
+ packaged_task temp(other);
+ swap(temp);
+ return *this;
+ }
+
+ void swap(packaged_task& other)
+ {
+ task.swap(other.task);
+ std::swap(future_obtained,other.future_obtained);
+ }
+
+ // result retrieval
+ unique_future<R> get_future()
+ {
+ if(!task)
+ {
+ throw task_moved();
+ }
+ else if(!future_obtained)
+ {
+ future_obtained=true;
+ return unique_future<R>(task);
+ }
+ else
+ {
+ throw future_already_retrieved();
+ }
+ }
+
+
+ // execution
+ void operator()()
+ {
+ if(!task)
+ {
+ throw task_moved();
+ }
+ task->run();
+ }
+
+ template<typename F>
+ void set_wait_callback(F f)
+ {
+ task->set_wait_callback(f,this);
+ }
+};
+
+}}}
+
+#endif // BOOST_FIBERS_SPIN_FUTURE_H
Added: sandbox/task/boost/task/spin/manual_reset_event.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/spin/manual_reset_event.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,55 @@
+
+// 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_SPIN_MANUAL_RESET_EVENT_H
+#define BOOST_TASKS_SPIN_MANUAL_RESET_EVENT_H
+
+#include <cstddef>
+
+#include <boost/atomic.hpp>
+#include <boost/thread/thread_time.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task/spin/mutex.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+class manual_reset_event : private noncopyable
+{
+private:
+ enum state
+ {
+ SET = 0,
+ RESET
+ };
+
+ atomic< state > state_;
+ atomic< std::size_t > waiters_;
+ mutex enter_mtx_;
+
+public:
+ explicit manual_reset_event( bool = false);
+
+ void set();
+
+ void reset();
+
+ void wait();
+
+ bool try_wait();
+
+ bool wait( system_time const&);
+
+ template< typename TimeDuration >
+ bool wait( TimeDuration const& rel_time)
+ { return wait( get_system_time() + rel_time); }
+};
+
+}}}
+
+#endif // BOOST_TASKS_SPIN_MANUAL_RESET_EVENT_H
Added: sandbox/task/boost/task/spin/mutex.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/spin/mutex.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,54 @@
+
+// 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)
+//
+// based on boost::interprocess::sync::interprocess_spin::mutex
+
+#ifndef BOOST_TASKS_SPIN_MUTEX_H
+#define BOOST_TASKS_SPIN_MUTEX_H
+
+#include <boost/atomic.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/thread_time.hpp>
+#include <boost/utility.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+class mutex : private noncopyable
+{
+private:
+ enum state
+ {
+ LOCKED = 0,
+ UNLOCKED
+ };
+
+ atomic< state > state_;
+
+public:
+ typedef unique_lock< mutex > scoped_lock;
+
+ mutex();
+
+ void lock();
+
+ bool try_lock();
+
+ bool timed_lock( system_time const& abs_time);
+
+ template< typename TimeDuration >
+ bool timed_lock( TimeDuration const& rel_time)
+ { return timed_lock( get_system_time() + rel_time); }
+
+ void unlock();
+};
+
+typedef mutex try_mutex;
+
+}}}
+
+#endif // BOOST_TASKS_SPIN_MUTEX_H
Added: sandbox/task/boost/task/spin/unbounded_channel.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/spin/unbounded_channel.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,245 @@
+
+// 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_SPIN_UNBOUNDED_CHANNEL_H
+#define BOOST_TASKS_SPIN_UNBOUNDED_CHANNEL_H
+
+#include <cstddef>
+#include <stdexcept>
+
+#include <boost/atomic.hpp>
+#include <boost/config.hpp>
+#include <boost/intrusive_ptr.hpp>
+#include <boost/optional.hpp>
+#include <boost/thread/thread_time.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task/exceptions.hpp>
+#include <boost/task/spin/condition.hpp>
+#include <boost/task/spin/mutex.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+template< typename T >
+class unbounded_channel
+{
+public:
+ typedef optional< T > value_type;
+
+private:
+ class impl : private noncopyable
+ {
+ private:
+ struct node
+ {
+ typedef intrusive_ptr< node > ptr;
+
+ atomic< std::size_t > use_count;
+ value_type va;
+ ptr next;
+
+ node() :
+ use_count( 0),
+ va(),
+ next()
+ {}
+
+ inline friend void intrusive_ptr_add_ref( node * p)
+ { p->use_count.fetch_add( 1, memory_order_relaxed); }
+
+ inline friend void intrusive_ptr_release( node * p)
+ {
+ if ( p->use_count.fetch_sub( 1, memory_order_release) == 1)
+ {
+ atomic_thread_fence( memory_order_acquire);
+ delete p;
+ }
+ }
+ };
+
+ enum state
+ {
+ ACTIVE = 0,
+ DEACTIVE
+ };
+
+ atomic< state > state_;
+ typename node::ptr head_;
+ mutable mutex head_mtx_;
+ typename node::ptr tail_;
+ mutable mutex tail_mtx_;
+ condition not_empty_cond_;
+ atomic< std::size_t > use_count_;
+
+ bool active_() const
+ { return ACTIVE == state_.load(); }
+
+ void deactivate_()
+ { state_.store( DEACTIVE); }
+
+ bool empty_() const
+ { return head_ == get_tail_(); }
+
+ typename node::ptr get_tail_() const
+ {
+ mutex::scoped_lock lk( tail_mtx_);
+ typename node::ptr tmp = tail_;
+ return tmp;
+ }
+
+ typename node::ptr pop_head_()
+ {
+ typename node::ptr old_head = head_;
+ head_ = old_head->next;
+ return old_head;
+ }
+
+ public:
+ impl() :
+ state_( ACTIVE),
+ head_( new node() ),
+ head_mtx_(),
+ tail_( head_),
+ tail_mtx_(),
+ not_empty_cond_(),
+ use_count_( 0)
+ {}
+
+ void deactivate()
+ { deactivate_(); }
+
+ bool empty() const
+ {
+ mutex::scoped_lock lk( head_mtx_);
+ return empty_();
+ }
+
+ void put( T const& t)
+ {
+ typename node::ptr new_node( new node() );
+ {
+ mutex::scoped_lock lk( tail_mtx_);
+
+ if ( ! active_() )
+ throw std::runtime_error("queue is not active");
+
+ tail_->va = t;
+ tail_->next = new_node;
+ tail_ = new_node;
+ }
+ not_empty_cond_.notify_one();
+ }
+
+ bool take( value_type & va)
+ {
+ mutex::scoped_lock lk( head_mtx_);
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ while ( active_() && empty_() )
+ not_empty_cond_.wait( lk);
+ }
+ catch ( task_interrupted const&)
+ { return false; }
+ }
+
+ if ( ! active_() && empty_() )
+ return false;
+ swap( va, head_->va);
+ pop_head_();
+ return va;
+ }
+
+ bool take( value_type & va, system_time const& abs_time)
+ {
+ mutex::scoped_lock lk( head_mtx_);
+ bool empty = empty_();
+ if ( ! active_() && empty)
+ return false;
+ if ( empty)
+ {
+ try
+ {
+ while ( active_() && empty_() )
+ if ( ! not_empty_cond_.timed_wait( lk, abs_time) )
+ return false;
+ }
+ catch ( task_interrupted const&)
+ { return false; }
+ }
+ if ( ! active_() && empty_() )
+ return false;
+ swap( va, head_->va);
+ pop_head_();
+ return va;
+ }
+
+ bool try_take( value_type & va)
+ {
+ mutex::scoped_lock lk( head_mtx_);
+ if ( empty_() )
+ return false;
+ swap( va, head_->va);
+ pop_head_();
+ return va;
+ }
+
+ inline friend void intrusive_ptr_add_ref( impl * p)
+ { p->use_count_.fetch_add( 1, memory_order_relaxed); }
+
+ inline friend void intrusive_ptr_release( impl * p)
+ {
+ if ( p->use_count_.fetch_sub( 1, memory_order_release) == 1)
+ {
+ atomic_thread_fence( memory_order_acquire);
+ delete p;
+ }
+ }
+ };
+
+ intrusive_ptr< impl > impl_;
+
+public:
+ unbounded_channel() :
+ impl_( new impl() )
+ {}
+
+ void deactivate()
+ { impl_->deactivate(); }
+
+ bool empty()
+ { return impl_->empty(); }
+
+ void put( T const& t)
+ { impl_->put( t); }
+
+ bool take( value_type & va)
+ { return impl_->take( va); }
+
+ bool take( value_type & va, system_time const& abs_time)
+ { return impl_->take( va, abs_time); }
+
+ template< typename TimeDuration >
+ bool take( value_type & va, TimeDuration const& rel_time)
+ { return impl_->take( va, get_system_time() + rel_time); }
+
+ bool try_take( value_type & va)
+ { return impl_->try_take( va); }
+};
+
+}}}
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_TASKS_SPIN_UNBOUNDED_CHANNEL_H
Deleted: sandbox/task/boost/task/spin_auto_reset_event.hpp
==============================================================================
--- sandbox/task/boost/task/spin_auto_reset_event.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,46 +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_TASK_SPIN_AUTO_RESET_EVENT_H
-#define BOOST_TASK_SPIN_AUTO_RESET_EVENT_H
-
-#include <boost/cstdint.hpp>
-#include <boost/thread/thread_time.hpp>
-#include <boost/utility.hpp>
-
-namespace boost {
-namespace task {
-
-class spin_auto_reset_event : private noncopyable
-{
-private:
- enum state_t
- {
- RESET = 0,
- SET
- };
-
- volatile uint32_t state_;
-
-public:
- explicit spin_auto_reset_event( bool = false);
-
- void set();
-
- void wait();
-
- bool wait( system_time const&);
-
- template< typename TimeDuration >
- bool wait( TimeDuration const& rel_time)
- { return wait( get_system_time() + rel_time); }
-
- bool try_wait();
-};
-
-}}
-
-#endif // BOOST_TASK_SPIN_AUTO_RESET_EVENT_H
Deleted: sandbox/task/boost/task/spin_condition.hpp
==============================================================================
--- sandbox/task/boost/task/spin_condition.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,122 +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)
-//
-// based on boost::interprocess::sync::interprocess_condition
-
-#ifndef BOOST_TASK_SPIN_CONDITION_H
-#define BOOST_TASK_SPIN_CONDITION_H
-
-#include <boost/cstdint.hpp>
-#include <boost/thread/thread_time.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task/exceptions.hpp>
-#include <boost/task/spin_mutex.hpp>
-
-namespace boost {
-namespace task {
-
-class spin_condition : private noncopyable
-{
-private:
- enum command_t
- {
- SLEEPING = 0,
- NOTIFY_ONE,
- NOTIFY_ALL
- };
-
- volatile uint32_t cmd_;
- volatile uint32_t waiters_;
- spin_mutex enter_mtx_;
- spin_mutex check_mtx_;
-
- void wait_( spin_mutex &);
- bool wait_( spin_mutex &, system_time const&);
- void notify_( uint32_t);
-
-public:
- spin_condition();
-
- void notify_one();
-
- void notify_all();
-
- template< typename Lock >
- void wait( Lock & lk)
- {
- if ( ! lk)
- throw lock_error();
- wait_( * lk.mutex() );
- }
-
- template<
- typename Lock,
- typename Pred
- >
- void wait( Lock & lk, Pred pred)
- {
- if ( ! lk)
- throw lock_error();
-
- while ( ! pred() )
- wait_( * lk.mutex() );
- }
-
- template< typename Lock >
- bool timed_wait( Lock & lk, system_time const& abs_time)
- {
- if ( abs_time.is_infinity() )
- {
- wait( lk);
- return true;
- }
-
- if ( ! lk)
- throw lock_error();
- return wait_( * lk.mutex(), abs_time);
- }
-
- template<
- typename Lock,
- typename Pred
- >
- bool timed_wait( Lock & lk, system_time const& abs_time, Pred pred)
- {
- if ( abs_time.is_infinity() )
- {
- wait( lk, pred);
- return true;
- }
-
- if ( ! lk)
- throw lock_error();
-
- while ( ! pred() )
- if ( ! wait_( * lk.mutex(), abs_time) )
- return pred();
- return true;
- }
-
- template<
- typename Lock,
- typename TimeDuration
- >
- bool timed_wait( Lock & lk, TimeDuration const& rel_time)
- { return timed_wait( lk, get_system_time() + rel_time); }
-
- template<
- typename Lock,
- typename TimeDuration,
- typename Pred
- >
- bool timed_wait( Lock & lk, TimeDuration const& rel_time, Pred pred)
- { return timed_wait( lk, get_system_time() + rel_time, pred); }
-};
-
-}}
-
-#endif // BOOST_TASK_SPIN_CONDITION_H
Deleted: sandbox/task/boost/task/spin_count_down_event.hpp
==============================================================================
--- sandbox/task/boost/task/spin_count_down_event.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,47 +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_TASK_SPIN_COUNT_DOWN_EVENT_H
-#define BOOST_TASK_SPIN_COUNT_DOWN_EVENT_H
-
-#include <boost/cstdint.hpp>
-#include <boost/thread/thread_time.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task/spin_mutex.hpp>
-
-namespace boost {
-namespace task {
-
-class spin_count_down_event : private noncopyable
-{
-private:
- uint32_t initial_;
- volatile uint32_t current_;
-
-public:
- explicit spin_count_down_event( uint32_t);
-
- uint32_t initial() const;
-
- uint32_t current() const;
-
- bool is_set() const;
-
- void set();
-
- void wait();
-
- bool wait( system_time const&);
-
- template< typename TimeDuration >
- bool wait( TimeDuration const& rel_time)
- { return wait( get_system_time() + rel_time); }
-};
-
-}}
-
-#endif // BOOST_TASK_SPIN_COUNT_DOWN_EVENT_H
Deleted: sandbox/task/boost/task/spin_manual_reset_event.hpp
==============================================================================
--- sandbox/task/boost/task/spin_manual_reset_event.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,52 +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_TASK_SPIN_MANUAL_RESET_EVENT_H
-#define BOOST_TASK_SPIN_MANUAL_RESET_EVENT_H
-
-#include <boost/cstdint.hpp>
-#include <boost/thread/thread_time.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task/spin_mutex.hpp>
-
-namespace boost {
-namespace task {
-
-class spin_manual_reset_event : private noncopyable
-{
-private:
- enum state_t
- {
- RESET = 0,
- SET
- };
-
- volatile uint32_t state_;
- volatile uint32_t waiters_;
- spin_mutex enter_mtx_;
-
-public:
- explicit spin_manual_reset_event( bool = false);
-
- void set();
-
- void reset();
-
- void wait();
-
- bool wait( system_time const&);
-
- template< typename TimeDuration >
- bool wait( TimeDuration const& rel_time)
- { return wait( get_system_time() + rel_time); }
-
- bool try_wait();
-};
-
-}}
-
-#endif // BOOST_TASK_SPIN_MANUAL_RESET_EVENT_H
Deleted: sandbox/task/boost/task/spin_mutex.hpp
==============================================================================
--- sandbox/task/boost/task/spin_mutex.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,48 +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)
-//
-// based on boost::interprocess::sync::interprocess_mutex
-
-#ifndef BOOST_TASK_SPIN_MUTEX_H
-#define BOOST_TASK_SPIN_MUTEX_H
-
-#include <boost/cstdint.hpp>
-#include <boost/thread/thread_time.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task/spin_unique_lock.hpp>
-
-namespace boost {
-namespace task {
-
-class spin_mutex : private noncopyable
-{
-private:
- volatile uint32_t state_;
-
-public:
- typedef spin_unique_lock< spin_mutex > scoped_lock;
-
- spin_mutex();
-
- void lock();
-
- bool try_lock();
-
- bool timed_lock( system_time const& abs_time);
-
- template< typename TimeDuration >
- bool timed_lock( TimeDuration const& rel_time)
- { return timed_lock( get_system_time() + rel_time); }
-
- void unlock();
-};
-
-typedef spin_mutex spin_try_mutex;
-
-}}
-
-#endif // BOOST_TASK_SPIN_MUTEX_H
Deleted: sandbox/task/boost/task/spin_unique_lock.hpp
==============================================================================
--- sandbox/task/boost/task/spin_unique_lock.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,147 +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)
-//
-// based on boost::interprocess::sync::scoped_lock
-
-#ifndef BOOST_TASK_SPIN_UNIQUE_LOCK_H
-#define BOOST_TASK_SPIN_UNIQUE_LOCK_H
-
-#include <algorithm>
-
-#include <boost/thread/locks.hpp>
-#include <boost/thread/thread_time.hpp>
-
-#include <boost/task/exceptions.hpp>
-
-namespace boost {
-namespace task {
-
-template< typename Mutex >
-class spin_unique_lock
-{
-private:
- typedef spin_unique_lock< Mutex > lock_t;
- typedef bool spin_unique_lock::*unspecified_bool_type;
-
- Mutex * mtx_;
- bool locked_;
-
- spin_unique_lock( spin_unique_lock &);
- spin_unique_lock & operator=( spin_unique_lock &);
-
-public:
- spin_unique_lock() :
- mtx_( 0),
- locked_( false)
- {}
-
- explicit spin_unique_lock( Mutex & mtx) :
- mtx_( & mtx),
- locked_( false)
- {
- mtx_->lock();
- locked_ = true;
- }
-
- spin_unique_lock( Mutex & mtx, adopt_lock_t) :
- mtx_( & mtx),
- locked_( true)
- {}
-
- spin_unique_lock( Mutex & mtx, defer_lock_t) :
- mtx_( & mtx),
- locked_( false)
- {}
-
- spin_unique_lock( Mutex & mtx, try_to_lock_t) :
- mtx_( & mtx),
- locked_( mtx_->try_lock() )
- {}
-
- spin_unique_lock( Mutex & mtx, system_time const& abs_time) :
- mtx_( & mtx),
- locked_( mtx_->timed_lock( abs_time) )
- {}
-
- template< typename TimeDuration >
- spin_unique_lock( Mutex & mtx, TimeDuration const& rel_time) :
- mtx_( & mtx),
- locked_( mtx_->timed_lock( rel_time) )
- {}
-
- ~spin_unique_lock()
- {
- try
- { if ( locked_ && mtx_) mtx_->unlock(); }
- catch (...) {}
- }
-
- void lock()
- {
- if ( ! mtx_ || locked_)
- throw lock_error();
- mtx_->lock();
- locked_ = true;
- }
-
- bool try_lock()
- {
- if ( ! mtx_ || locked_)
- throw lock_error();
- locked_ = mtx_->try_lock();
- return locked_;
- }
-
- bool timed_lock( system_time const& abs_time)
- {
- if ( ! mtx_ || locked_)
- throw lock_error();
- locked_ = mtx_->timed_lock( abs_time);
- return locked_;
- }
-
- template< typename TimeDuration >
- bool timed_lock( TimeDuration const& rel_time)
- { return timed_lock( get_system_time() + rel_time); }
-
- void unlock()
- {
- if ( ! mtx_ || ! locked_)
- throw lock_error();
- mtx_->unlock();
- locked_ = false;
- }
-
- bool owns_lock() const
- { return locked_ && mtx_; }
-
- operator unspecified_bool_type() const
- { return locked_ ? & lock_t::locked_ : 0; }
-
- bool operator!() const
- { return ! locked_; }
-
- Mutex * mutex() const
- { return mtx_; }
-
- Mutex * release()
- {
- Mutex * mtx = mtx_;
- mtx_ = 0;
- locked_ = false;
- return mtx;
- }
-
- void swap( spin_unique_lock & other)
- {
- std::swap( mtx_, other.mtx_);
- std::swap( locked_, other.locked_);
- }
-};
-
-}}
-
-#endif // BOOST_TASK_SPIN_UNIQUE_LOCK_H
Modified: sandbox/task/boost/task/stacksize.hpp
==============================================================================
--- sandbox/task/boost/task/stacksize.hpp (original)
+++ sandbox/task/boost/task/stacksize.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_STACKSIZE_H
-#define BOOST_TASK_STACKSIZE_H
+#ifndef BOOST_TASKS_STACKSIZE_H
+#define BOOST_TASKS_STACKSIZE_H
#include <cstddef>
@@ -19,9 +19,9 @@
# endif
namespace boost {
-namespace task {
+namespace tasks {
-class BOOST_TASK_DECL stacksize
+class BOOST_TASKS_DECL stacksize
{
private:
std::size_t value_;
@@ -40,4 +40,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_STACKSIZE_H
+#endif // BOOST_TASKS_STACKSIZE_H
Modified: sandbox/task/boost/task/static_pool.hpp
==============================================================================
--- sandbox/task/boost/task/static_pool.hpp (original)
+++ sandbox/task/boost/task/static_pool.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,22 +4,21 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_STATIC_POOL_H
-#define BOOST_TASK_STATIC_POOL_H
+#ifndef BOOST_TASKS_STATIC_POOL_H
+#define BOOST_TASKS_STATIC_POOL_H
#include <cstddef>
#include <boost/config.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/thread/detail/move.hpp>
+#include <boost/fiber/round_robin.hpp>
+#include <boost/move/move.hpp>
#include <boost/task/detail/bind_processor.hpp>
#include <boost/task/detail/pool_base.hpp>
-
#include <boost/task/detail/worker_group.hpp>
#include <boost/task/exceptions.hpp>
#include <boost/task/handle.hpp>
-#include <boost/task/local_rr_ums.hpp>
#include <boost/task/poolsize.hpp>
#include <boost/task/scanns.hpp>
#include <boost/task/stacksize.hpp>
@@ -29,11 +28,11 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
template<
typename Queue,
- typename UMS = local_rr_ums
+ typename UMS = fibers::round_robin
>
class static_pool
{
@@ -47,15 +46,14 @@
template< typename T, typename X >
friend class detail::worker_object;
+ BOOST_MOVABLE_BUT_NOT_COPYABLE( static_pool);
+
# if defined(BOOST_HAS_PROCESSOR_BINDINGS)
struct tag_bind_to_processors {};
# endif
shared_ptr< base_type > pool_;
- static_pool( static_pool &);
- static_pool & operator=( static_pool &);
-
public:
static_pool() :
pool_()
@@ -102,42 +100,17 @@
{ return tag_bind_to_processors(); }
# endif
-# if defined(BOOST_HAS_RVALUE_REFS)
- static_pool( static_pool && other) :
+ static_pool( BOOST_RV_REF( static_pool) other) :
pool_()
{ pool_.swap( other.pool_); }
- static_pool & operator=( static_pool && other)
- {
- static_pool tmp( static_cast< static_pool && >( other) );
- swap( tmp);
- return * this;
- }
-
- static_pool && move()
- { return static_cast< static_pool && >( * this); }
-# else
- static_pool( boost::detail::thread_move_t< static_pool > other) :
- pool_()
- { pool_.swap( other->pool_); }
-
- static_pool & operator=( boost::detail::thread_move_t< static_pool > other)
+ static_pool & operator=( BOOST_RV_REF( static_pool) other)
{
static_pool tmp( other);
swap( tmp);
return * this;
}
- operator boost::detail::thread_move_t< static_pool >()
- { return move(); }
-
- boost::detail::thread_move_t< static_pool > move()
- {
- boost::detail::thread_move_t< static_pool > t( * this);
- return t;
- }
-# endif
-
void interrupt_all_worker()
{
if ( ! pool_)
@@ -232,22 +205,12 @@
}
template< typename Queue, typename UMS >
-void swap( task::static_pool< Queue, UMS > & l, task::static_pool< Queue, UMS > & r)
+void swap( tasks::static_pool< Queue, UMS > & l, tasks::static_pool< Queue, UMS > & r)
{ return l.swap( r); }
-# if defined(BOOST_HAS_RVALUE_REFS)
-template< typename Queue, typename UMS >
-task::static_pool< Queue, UMS > && move( task::static_pool< Queue, UMS > && t)
-{ return t; }
-# else
-template< typename Queue, typename UMS >
-task::static_pool< Queue, UMS > move( boost::detail::thread_move_t< task::static_pool< Queue, UMS > > t)
-{ return task::static_pool< Queue, UMS >( t); }
-# endif
-
}
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_STATIC_POOL_H
+#endif // BOOST_TASKS_STATIC_POOL_H
Modified: sandbox/task/boost/task/task.hpp
==============================================================================
--- sandbox/task/boost/task/task.hpp (original)
+++ sandbox/task/boost/task/task.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,23 +4,23 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_TASK_H
-#define BOOST_TASK_TASK_H
+#ifndef BOOST_TASKS_TASK_H
+#define BOOST_TASKS_TASK_H
#include <boost/bind.hpp>
#include <boost/config.hpp>
#include <boost/preprocessor/repetition.hpp>
-#include <boost/thread.hpp>
+#include <boost/move/move.hpp>
+#include <boost/thread/future.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/utility/result_of.hpp>
#include <boost/task/exceptions.hpp>
-#include <boost/task/future.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
template< typename R >
@@ -170,19 +170,17 @@
task_base< void >(), fn_( fn)
{}
};
+
}
template< typename R >
class task
{
private:
- struct dummy;
+ BOOST_MOVABLE_BUT_NOT_COPYABLE( task);
shared_ptr< detail::task_base< R > > task_;
- task( task &);
- task & operator=( task &);
-
public:
task() :
task_()
@@ -192,74 +190,31 @@
task_( new detail::task_wrapper< R, R( *)() >( fn) )
{}
-# if defined(BOOST_HAS_RVALUE_REFS)
template< typename Fn >
- task( Fn && fn) :
+ explicit task( BOOST_RV_REF( Fn) fn) :
task_( new detail::task_wrapper< R, Fn >( fn) )
{}
- task( task && other) :
+ task( BOOST_RV_REF( task) other) :
task_()
{ task_.swap( other.task_); }
- task & operator=( task && other)
- {
- task tmp( static_cast< task && >( other) );
- swap( tmp);
- return * this;
- }
-
- task && move()
- { return static_cast< task && >( * this); }
-# else
-#ifdef BOOST_NO_SFINAE
- template< typename Fn >
- explicit task( Fn fn) :
- task_( new detail::task_wrapper< R, Fn >( fn) )
- {}
-#else
- template< typename Fn >
- explicit task(
- Fn fn,
- typename disable_if< boost::is_convertible< Fn &, boost::detail::thread_move_t< Fn > >, dummy * >::type = 0) :
- task_( new detail::task_wrapper< R, Fn >( fn) )
- {}
-#endif
- template< typename Fn >
- explicit task( boost::detail::thread_move_t< Fn > fn) :
- task_( new detail::task_wrapper< R, Fn >( fn) )
- {}
-
- task( boost::detail::thread_move_t< task > other) :
- task_()
- { task_.swap( other->task_); }
-
- task & operator=( boost::detail::thread_move_t< task > other)
+ task & operator=( BOOST_RV_REF( task) other)
{
task tmp( other);
swap( tmp);
return * this;
}
- operator boost::detail::thread_move_t< task >()
- { return move(); }
-
- boost::detail::thread_move_t< task > move()
- {
- boost::detail::thread_move_t< task > t( * this);
- return t;
- }
-# endif
-
-# ifndef BOOST_TASK_MAX_ARITY
-# define BOOST_TASK_MAX_ARITY 10
+# ifndef BOOST_TASKS_MAX_ARITY
+# define BOOST_TASKS_MAX_ARITY 10
# endif
-# define BOOST_TASK_ARG(z, n, unused) \
+# define BOOST_TASKS_ARG(z, n, unused) \
BOOST_PP_CAT(A, n) BOOST_PP_CAT(a, n)
-# define BOOST_ENUM_TASK_ARGS(n) BOOST_PP_ENUM(n, BOOST_TASK_ARG, ~)
+# define BOOST_ENUM_TASK_ARGS(n) BOOST_PP_ENUM(n, BOOST_TASKS_ARG, ~)
-# define BOOST_TASK_CTOR(z, n, unused) \
+# define BOOST_TASKS_CTOR(z, n, unused) \
template< \
typename Fn, \
BOOST_PP_ENUM_PARAMS(n, typename A) \
@@ -270,9 +225,9 @@
bind( fn, BOOST_PP_ENUM_PARAMS(n, a)) ) ) \
{}
-BOOST_PP_REPEAT_FROM_TO( 1, BOOST_TASK_MAX_ARITY, BOOST_TASK_CTOR, ~)
+BOOST_PP_REPEAT_FROM_TO( 1, BOOST_TASKS_MAX_ARITY, BOOST_TASKS_CTOR, ~)
-# undef BOOST_TASK_CTOR
+# undef BOOST_TASKS_CTOR
void operator()()
{
@@ -312,7 +267,7 @@
task< typename result_of< Fn() >::type > make_task( Fn fn)
{ return task< typename boost::result_of< Fn() >::type >( fn); }
-# define BOOST_TASK_MAKE_TASK_FUNCTION(z, n, unused) \
+# define BOOST_TASKS_MAKE_TASK_FUNCTION(z, n, unused) \
template< \
typename Fn, \
BOOST_PP_ENUM_PARAMS(n, typename A) \
@@ -321,30 +276,23 @@
make_task( Fn fn, BOOST_ENUM_TASK_ARGS(n)) \
{ return task< typename result_of< Fn( BOOST_PP_ENUM_PARAMS(n, A)) >::type >( fn, BOOST_PP_ENUM_PARAMS(n, a)); }
-BOOST_PP_REPEAT_FROM_TO( 1, BOOST_TASK_MAX_ARITY, BOOST_TASK_MAKE_TASK_FUNCTION, ~)
+BOOST_PP_REPEAT_FROM_TO( 1, BOOST_TASKS_MAX_ARITY, BOOST_TASKS_MAKE_TASK_FUNCTION, ~)
-# undef BOOST_TASK_MAKE_TASK_FUNCTION
+# undef BOOST_TASKS_MAKE_TASK_FUNCTION
# undef BOOST_ENUM_TASK_ARGS
-# undef BOOST_TASK_ARG
-# undef BOOST_TASK_MAX_ARITY
+# undef BOOST_TASKS_ARG
+# undef BOOST_TASKS_MAX_ARITY
}
+using tasks::task;
+
template< typename R >
-void swap( task::task< R > & l, task::task< R > & r)
+void swap( task< R > & l, task< R > & r)
{ return l.swap( r); }
-# if defined(BOOST_HAS_RVALUE_REFS)
-template< typename R >
-task::task< R > && move( task::task< R > && t)
-{ return t; }
-# else
-template< typename R >
-task::task< R > move( boost::detail::thread_move_t< task::task< R > > t)
-{ return task::task< R >( t); }
-# endif
}
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_TASK_H
+#endif // BOOST_TASKS_TASK_H
Deleted: sandbox/task/boost/task/unbounded_buffer.hpp
==============================================================================
--- sandbox/task/boost/task/unbounded_buffer.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,220 +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_TASK_UNBOUNDED_BUFFER_H
-#define BOOST_TASK_UNBOUNDED_BUFFER_H
-
-#include <deque>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/optional.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/exceptions.hpp>
-#include <boost/task/semaphore.hpp>
-#include <boost/task/spin_condition.hpp>
-#include <boost/task/spin_unique_lock.hpp>
-#include <boost/task/spin_mutex.hpp>
-
-#include <boost/config/abi_prefix.hpp>
-
-namespace boost {
-namespace task {
-
-template< typename T >
-class unbounded_buffer
-{
-private:
- typedef T value_type;
-
- class base
- {
- private:
- volatile uint32_t state_;
- std::deque< value_type > queue_;
- spin_mutex mtx_;
- spin_condition not_empty_cond_;
-
- base( base &);
-
- base & operator=( base const&);
-
- 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_(
- optional< value_type > & va,
- spin_unique_lock< spin_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- not_empty_cond_.wait(
- lk,
- bind(
- & base::consumers_activate_,
- this) );
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va = queue_.front();
- queue_.pop_front();
- return va;
- }
-
- template< typename Duration >
- bool take_(
- optional< value_type > & va,
- Duration const& rel_time,
- spin_unique_lock< spin_mutex > & lk)
- {
- bool empty = empty_();
- if ( ! active_() && empty)
- return false;
- if ( empty)
- {
- try
- {
- if ( ! not_empty_cond_.timed_wait(
- lk,
- rel_time,
- bind(
- & base::consumers_activate_,
- this) ) )
- return false;
- }
- catch ( thread_interrupted const&)
- { return false; }
- }
- if ( ! active_() && empty_() )
- return false;
- va = queue_.front();
- queue_.pop_front();
- return va;
- }
-
- bool try_take_( optional< value_type > & va)
- {
- if ( empty_() )
- return false;
- va = queue_.front();
- queue_.pop_front();
- return va;
- }
-
- bool consumers_activate_() const
- { return ! active_() || ! empty_(); }
-
- public:
- base() :
- state_( 0),
- queue_(),
- mtx_(),
- not_empty_cond_()
- {}
-
- bool active()
- { return active_(); }
-
- void deactivate()
- { deactivate_(); }
-
- bool empty()
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- return empty_();
- }
-
- void put( value_type const& va)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- put_( va);
- }
-
- bool take( optional< value_type > & va)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- return take_( va, lk);
- }
-
- template< typename TimeDuration >
- bool take(
- optional< value_type > & va,
- TimeDuration const& rel_time)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- return take_( va, rel_time, lk);
- }
-
- bool try_take( optional< value_type > & va)
- {
- spin_unique_lock< spin_mutex > lk( mtx_);
- return try_take_( va);
- }
- };
-
- shared_ptr< base > impl_;
-
-public:
- unbounded_buffer() :
- impl_( new base)
- {}
-
- bool active()
- { return impl_->active(); }
-
- void deactivate()
- { impl_->deactivate(); }
-
- bool empty()
- { return impl_->empty(); }
-
- void put( T const& t)
- { impl_->put( t); }
-
- bool take( optional< T > & t)
- { return impl_->take( t); }
-
- template< typename TimeDuration >
- bool take(
- optional< T > & t,
- TimeDuration const& rel_time)
- { return impl_->take( t, rel_time); }
-
- bool try_take( optional< T > & t)
- { return impl_->try_take( t); }
-};
-
-}}
-
-#include <boost/config/abi_suffix.hpp>
-
-#endif // BOOST_TASK_UNBOUNDED_BUFFER_H
Modified: sandbox/task/boost/task/unbounded_onelock_fifo.hpp
==============================================================================
--- sandbox/task/boost/task/unbounded_onelock_fifo.hpp (original)
+++ sandbox/task/boost/task/unbounded_onelock_fifo.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_UNBOUNDED_ONELOCK_FIFO_H
-#define BOOST_TASK_UNBOUNDED_ONELOCK_FIFO_H
+#ifndef BOOST_TASKS_UNBOUNDED_ONELOCK_FIFO_H
+#define BOOST_TASKS_UNBOUNDED_ONELOCK_FIFO_H
#include <cstddef>
#include <list>
@@ -25,7 +25,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
class unbounded_onelock_fifo
{
@@ -177,4 +177,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_UNBOUNDED_ONELOCK_FIFO_H
+#endif // BOOST_TASKS_UNBOUNDED_ONELOCK_FIFO_H
Modified: sandbox/task/boost/task/unbounded_onelock_prio_queue.hpp
==============================================================================
--- sandbox/task/boost/task/unbounded_onelock_prio_queue.hpp (original)
+++ sandbox/task/boost/task/unbounded_onelock_prio_queue.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_UNBOUNDED_ONELOCK_PRIO_QUEUE_H
-#define BOOST_TASK_UNBOUNDED_ONELOCK_PRIO_QUEUE_H
+#ifndef BOOST_TASKS_UNBOUNDED_ONELOCK_PRIO_QUEUE_H
+#define BOOST_TASKS_UNBOUNDED_ONELOCK_PRIO_QUEUE_H
#include <algorithm>
#include <cstddef>
@@ -27,7 +27,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
template<
typename Attr,
@@ -214,4 +214,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_UNBOUNDED_ONELOCK_PRIO_QUEUE_H
+#endif // BOOST_TASKS_UNBOUNDED_ONELOCK_PRIO_QUEUE_H
Modified: sandbox/task/boost/task/unbounded_onelock_smart_queue.hpp
==============================================================================
--- sandbox/task/boost/task/unbounded_onelock_smart_queue.hpp (original)
+++ sandbox/task/boost/task/unbounded_onelock_smart_queue.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_UNBOUNDED_ONELOCK_SMART_QUEUE_H
-#define BOOST_TASK_UNBOUNDED_ONELOCK_SMART_QUEUE_H
+#ifndef BOOST_TASKS_UNBOUNDED_ONELOCK_SMART_QUEUE_H
+#define BOOST_TASKS_UNBOUNDED_ONELOCK_SMART_QUEUE_H
#include <algorithm>
#include <cstddef>
@@ -29,7 +29,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
template<
typename Attr,
@@ -221,4 +221,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_UNBOUNDED_ONELOCK_SMART_QUEUE_H
+#endif // BOOST_TASKS_UNBOUNDED_ONELOCK_SMART_QUEUE_H
Modified: sandbox/task/boost/task/unbounded_twolock_fifo.hpp
==============================================================================
--- sandbox/task/boost/task/unbounded_twolock_fifo.hpp (original)
+++ sandbox/task/boost/task/unbounded_twolock_fifo.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_UNBOUNDED_TWOLOCK_FIFO_H
-#define BOOST_TASK_UNBOUNDED_TWOLOCK_FIFO_H
+#ifndef BOOST_TASKS_UNBOUNDED_TWOLOCK_FIFO_H
+#define BOOST_TASKS_UNBOUNDED_TWOLOCK_FIFO_H
#include <cstddef>
@@ -25,7 +25,7 @@
#include <boost/config/abi_prefix.hpp>
namespace boost {
-namespace task {
+namespace tasks {
class unbounded_twolock_fifo
{
@@ -168,4 +168,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_UNBOUNDED_TWOLOCK_FIFO_H
+#endif // BOOST_TASKS_UNBOUNDED_TWOLOCK_FIFO_H
Modified: sandbox/task/boost/task/utility.hpp
==============================================================================
--- sandbox/task/boost/task/utility.hpp (original)
+++ sandbox/task/boost/task/utility.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)txt)
-#ifndef BOOST_TASK_UTILITY_H
-#define BOOST_TASK_UTILITY_H
+#ifndef BOOST_TASKS_UTILITY_H
+#define BOOST_TASKS_UTILITY_H
#include <boost/assert.hpp>
#include <boost/thread.hpp>
@@ -20,19 +20,19 @@
inline
void block()
{
- task::detail::worker * w( task::detail::worker::tss_get() );
+ tasks::detail::worker * w( tasks::detail::worker::tss_get() );
BOOST_ASSERT( w);
w->block();
}
inline
bool runs_in_pool()
-{ return task::detail::worker::tss_get() != 0; }
+{ return tasks::detail::worker::tss_get() != 0; }
inline
thread::id worker_id()
{
- task::detail::worker * w( task::detail::worker::tss_get() );
+ tasks::detail::worker * w( tasks::detail::worker::tss_get() );
BOOST_ASSERT( w);
return w->get_id();
}
@@ -41,4 +41,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_UTILITY_H
+#endif // BOOST_TASKS_UTILITY_H
Modified: sandbox/task/boost/task/watermark.hpp
==============================================================================
--- sandbox/task/boost/task/watermark.hpp (original)
+++ sandbox/task/boost/task/watermark.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_TASK_WATER_MARK_H
-#define BOOST_TASK_WATER_MARK_H
+#ifndef BOOST_TASKS_WATER_MARK_H
+#define BOOST_TASKS_WATER_MARK_H
#include <cstddef>
@@ -19,9 +19,9 @@
# endif
namespace boost {
-namespace task {
+namespace tasks {
-class BOOST_TASK_DECL high_watermark
+class BOOST_TASKS_DECL high_watermark
{
private:
std::size_t value_;
@@ -32,7 +32,7 @@
operator std::size_t () const;
};
-class BOOST_TASK_DECL low_watermark
+class BOOST_TASKS_DECL low_watermark
{
private:
std::size_t value_;
@@ -51,4 +51,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_TASK_WATER_MARK_H
+#endif // BOOST_TASKS_WATER_MARK_H
Modified: sandbox/task/libs/task/build/Jamfile.v2
==============================================================================
--- sandbox/task/libs/task/build/Jamfile.v2 (original)
+++ sandbox/task/libs/task/build/Jamfile.v2 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -14,10 +14,11 @@
: source-location
../src
: requirements
- <library>/boost/system//boost_system
+ <library>/boost/fiber//boost_fiber
<library>/boost/thread//boost_thread
- <link>static:<define>BOOST_TASK_BUILD_LIB=1
- <link>shared:<define>BOOST_TASK_BUILD_DLL=1
+ <library>/boost/system//boost_system
+ <link>static:<define>BOOST_TASKS_BUILD_LIB=1
+ <link>shared:<define>BOOST_TASKS_BUILD_DLL=1
<threading>multi
: default-build
<threading>multi
@@ -40,12 +41,12 @@
guard.cpp
poolsize.cpp
scanns.cpp
- semaphore_windows.cpp
- spin_auto_reset_event.cpp
- spin_condition.cpp
- spin_count_down_event.cpp
- spin_manual_reset_event.cpp
- spin_mutex.cpp
+ spin/auto_reset_event.cpp
+ spin/barrier.cpp
+ spin/condition.cpp
+ spin/count_down_event.cpp
+ spin/manual_reset_event.cpp
+ spin/mutex.cpp
stacksize.cpp
watermark.cpp
worker.cpp
@@ -62,12 +63,12 @@
guard.cpp
poolsize.cpp
scanns.cpp
- semaphore_posix.cpp
- spin_auto_reset_event.cpp
- spin_condition.cpp
- spin_count_down_event.cpp
- spin_manual_reset_event.cpp
- spin_mutex.cpp
+ spin/auto_reset_event.cpp
+ spin/barrier.cpp
+ spin/condition.cpp
+ spin/count_down_event.cpp
+ spin/manual_reset_event.cpp
+ spin/mutex.cpp
stacksize.cpp
watermark.cpp
worker.cpp
@@ -81,8 +82,8 @@
lib boost_task
: task_sources
- : <link>shared:<define>BOOST_TASK_USE_DLL=1
- <link>static:<define>BOOST_TASK_USE_LIB=1
+ : <link>shared:<define>BOOST_TASKS_USE_DLL=1
+ <link>static:<define>BOOST_TASKS_USE_LIB=1
;
boost-install boost_task ;
Modified: sandbox/task/libs/task/examples/Jamfile.v2
==============================================================================
--- sandbox/task/libs/task/examples/Jamfile.v2 (original)
+++ sandbox/task/libs/task/examples/Jamfile.v2 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -16,6 +16,7 @@
project boost/task/example
: requirements
+ <library>../../fiber/build//boost_fiber
<library>../../thread/build//boost_thread
<library>../../system/build//boost_system
<library>../build//boost_task
@@ -25,13 +26,12 @@
;
exe bind_to_processors : bind_to_processors.cpp ;
-exe sub_tasks : sub_tasks.cpp ;
exe interrupt : interrupt.cpp ;
exe priority : priority.cpp ;
exe shutdown_now : shutdown_now.cpp ;
exe smart : smart.cpp ;
exe submit : submit.cpp ;
+exe sub_tasks : sub_tasks.cpp ;
exe sync/fork_join_event : sync/fork_join_event.cpp ;
-exe sync/buffer_ping_pong : sync/buffer_ping_pong.cpp ;
-exe sync/semaphore_ping_pong : sync/semaphore_ping_pong.cpp ;
exe sync/message_passing : sync/message_passing.cpp ;
+exe sync/ping_pong : sync/ping_pong.cpp ;
Modified: sandbox/task/libs/task/examples/bind_to_processors.cpp
==============================================================================
--- sandbox/task/libs/task/examples/bind_to_processors.cpp (original)
+++ sandbox/task/libs/task/examples/bind_to_processors.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -16,7 +16,7 @@
#include "boost/task.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
typedef tsk::static_pool< tsk::unbounded_onelock_fifo > pool_type;
Modified: sandbox/task/libs/task/examples/interrupt.cpp
==============================================================================
--- sandbox/task/libs/task/examples/interrupt.cpp (original)
+++ sandbox/task/libs/task/examples/interrupt.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -15,7 +15,7 @@
#include "boost/task.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
typedef tsk::static_pool< tsk::unbounded_twolock_fifo > pool_type;
Modified: sandbox/task/libs/task/examples/priority.cpp
==============================================================================
--- sandbox/task/libs/task/examples/priority.cpp (original)
+++ sandbox/task/libs/task/examples/priority.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -15,7 +15,7 @@
#include "boost/task.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
inline
void print_fn( std::string const& msg)
Modified: sandbox/task/libs/task/examples/shutdown_now.cpp
==============================================================================
--- sandbox/task/libs/task/examples/shutdown_now.cpp (original)
+++ sandbox/task/libs/task/examples/shutdown_now.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -16,7 +16,7 @@
#include "boost/task.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
inline
int fibonacci_fn( int n)
Modified: sandbox/task/libs/task/examples/smart.cpp
==============================================================================
--- sandbox/task/libs/task/examples/smart.cpp (original)
+++ sandbox/task/libs/task/examples/smart.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -15,7 +15,7 @@
#include "boost/task.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
inline
void fibonacci_fn( int n)
Modified: sandbox/task/libs/task/examples/sub_tasks.cpp
==============================================================================
--- sandbox/task/libs/task/examples/sub_tasks.cpp (original)
+++ sandbox/task/libs/task/examples/sub_tasks.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -15,7 +15,7 @@
#include "boost/task.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
typedef tsk::static_pool< tsk::unbounded_twolock_fifo > pool_type;
Modified: sandbox/task/libs/task/examples/submit.cpp
==============================================================================
--- sandbox/task/libs/task/examples/submit.cpp (original)
+++ sandbox/task/libs/task/examples/submit.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -12,7 +12,7 @@
#include "boost/task.hpp"
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
inline
int fibonacci_fn( int n)
Deleted: sandbox/task/libs/task/examples/sync/buffer_ping_pong.cpp
==============================================================================
--- sandbox/task/libs/task/examples/sync/buffer_ping_pong.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,142 +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 <iostream>
-#include <cstdlib>
-#include <stdexcept>
-#include <string>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/lexical_cast.hpp>
-#include <boost/optional.hpp>
-#include <boost/ref.hpp>
-
-#include "boost/task.hpp"
-
-namespace tsk = boost::task;
-
-void send_ping(
- int n,
- tsk::unbounded_buffer< std::string > & buf_ping,
- tsk::unbounded_buffer< std::string > & buf_pong)
-{
- for ( int i = 0; i < n; ++i)
- {
- printf("task 1: buf_ping.put(%d-th ping)\n", i);
- buf_ping.put(
- boost::lexical_cast< std::string >( i) + "-th ping");
- boost::optional< std::string > msg;
- buf_pong.take( msg);
- BOOST_ASSERT( msg);
- printf("task 1: buf_pong.take(%s)\n", msg->c_str() );
- }
- printf("task 1: end\n");
-}
-
-void send_pong(
- int n,
- tsk::unbounded_buffer< std::string > & buf_ping,
- tsk::unbounded_buffer< std::string > & buf_pong)
-{
- for ( int i = 0; i < n; ++i)
- {
- printf("task 2: buf_pong.put(%d-th pong)\n", i);
- buf_pong.put(
- boost::lexical_cast< std::string >( i) + "-th pong");
- boost::optional< std::string > msg;
- buf_ping.take( msg);
- BOOST_ASSERT( msg);
- printf("task 2: buf_ping.take(%s)\n", msg->c_str() );
- }
- printf("task 2: end\n");
-}
-
-void thread_only()
-{
- int n = 5;
- tsk::unbounded_buffer< std::string > buf_ping, buf_pong;
- tsk::handle< void > h1 = tsk::async(
- tsk::make_task(
- & send_ping,
- n,
- buf_ping,
- buf_pong),
- tsk::new_thread() );
- tsk::handle< void > h2 = tsk::async(
- tsk::make_task(
- & send_pong,
- n,
- buf_ping,
- buf_pong),
- tsk::new_thread() );
-
- tsk::waitfor_all( h1, h2);
-}
-
-void pool_only()
-{
- tsk::static_pool< tsk::unbounded_twolock_fifo > pool( tsk::poolsize( 1) );
-
- int n = 5;
- tsk::unbounded_buffer< std::string > buf_ping, buf_pong;
- tsk::async(
- tsk::make_task(
- & send_ping,
- n,
- buf_ping,
- buf_pong),
- pool);
- tsk::async(
- tsk::make_task(
- & send_pong,
- n,
- buf_ping,
- buf_pong),
- pool);
-}
-
-void pool_and_thread()
-{
- tsk::static_pool< tsk::unbounded_twolock_fifo > pool( tsk::poolsize( 1) );
-
- int n = 5;
- tsk::unbounded_buffer< std::string > buf_ping, buf_pong;
- tsk::async(
- tsk::make_task(
- & send_ping,
- n,
- buf_ping,
- buf_pong),
- pool);
- tsk::handle< void > h = tsk::async(
- tsk::make_task(
- & send_pong,
- n,
- buf_ping,
- buf_pong),
- tsk::new_thread() );
-
- h.wait();
-}
-
-int main( int argc, char *argv[])
-{
- try
- {
- pool_only();
- thread_only();
- pool_and_thread();
-
- return EXIT_SUCCESS;
- }
- catch ( std::exception const& e)
- { std::cerr << "exception: " << e.what() << std::endl; }
- catch ( ... )
- { std::cerr << "unhandled" << std::endl; }
-
- return EXIT_FAILURE;
-}
Modified: sandbox/task/libs/task/examples/sync/fork_join_event.cpp
==============================================================================
--- sandbox/task/libs/task/examples/sync/fork_join_event.cpp (original)
+++ sandbox/task/libs/task/examples/sync/fork_join_event.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -16,11 +16,11 @@
#include "boost/task.hpp"
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
typedef tsk::static_pool< tsk::unbounded_twolock_fifo > pool_type;
-void sub_task( int i, int n, tsk::spin_count_down_event & ev)
+void sub_task( int i, int n, tsk::spin::count_down_event & ev)
{
BOOST_ASSERT( boost::this_task::runs_in_pool() );
@@ -34,13 +34,13 @@
void main_task(
pool_type & pool,
int n,
- tsk::spin_count_down_event & outer_ev)
+ tsk::spin::count_down_event & outer_ev)
{
BOOST_ASSERT( boost::this_task::runs_in_pool() );
fprintf( stderr, "main-task running %d sub-tasks\n", n);
- tsk::spin_count_down_event inner_ev( n);
+ tsk::spin::count_down_event inner_ev( n);
for ( int i = 0; i < n; ++i)
tsk::async(
@@ -63,7 +63,7 @@
pool_type pool( psize);
int n = 32;
- tsk::spin_count_down_event ev( 1);
+ tsk::spin::count_down_event ev( 1);
tsk::async(
tsk::make_task(
& main_task,
Modified: sandbox/task/libs/task/examples/sync/message_passing.cpp
==============================================================================
--- sandbox/task/libs/task/examples/sync/message_passing.cpp (original)
+++ sandbox/task/libs/task/examples/sync/message_passing.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -16,7 +16,7 @@
#include "boost/task.hpp"
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
typedef tsk::static_pool< tsk::unbounded_twolock_fifo > pool_type;
@@ -56,8 +56,8 @@
inline
void submit(
- tsk::unbounded_buffer< int > & send,
- tsk::unbounded_buffer< std::pair< int , int > > & recv,
+ tsk::spin::unbounded_channel< int > & send,
+ tsk::spin::unbounded_channel< std::pair< int , int > > & recv,
int n)
{
for ( int i = 0; i <= n; ++i)
@@ -73,8 +73,8 @@
inline
void calculate(
- tsk::unbounded_buffer< int > & recv,
- tsk::unbounded_buffer< std::pair< int , int > > & send)
+ tsk::spin::unbounded_channel< int > & recv,
+ tsk::spin::unbounded_channel< std::pair< int , int > > & send)
{
boost::optional< int > n;
while ( recv.take( n) )
@@ -92,8 +92,8 @@
{
pool_type pool( tsk::poolsize( 2) );
- tsk::unbounded_buffer< int > buf1;
- tsk::unbounded_buffer< std::pair< int , int > > buf2;
+ tsk::spin::unbounded_channel< int > buf1;
+ tsk::spin::unbounded_channel< std::pair< int , int > > buf2;
tsk::async(
tsk::make_task( submit, buf1, buf2, 15),
Added: sandbox/task/libs/task/examples/sync/ping_pong.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/sync/ping_pong.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,125 @@
+#include <cstdlib>
+#include <iostream>
+#include <string>
+#include <sstream>
+
+#include <boost/assert.hpp>
+#include <boost/intrusive_ptr.hpp>
+#include <boost/ref.hpp>
+#include <boost/optional.hpp>
+#include <boost/system/system_error.hpp>
+#include <boost/thread.hpp>
+
+#include <boost/task.hpp>
+
+typedef boost::tasks::static_pool< boost::tasks::unbounded_twolock_fifo > pool_t;
+typedef boost::tasks::spin::unbounded_channel< std::string > fifo_t;
+
+inline
+void ping(
+ fifo_t & recv_buf,
+ fifo_t & send_buf,
+ boost::tasks::spin::barrier & b)
+{
+ sleep( 1);
+ b.wait();
+
+ std::stringstream tss;
+ tss << boost::this_thread::get_id();
+ std::stringstream fss;
+ fss << boost::this_fiber::get_id();
+
+ fprintf( stderr, "start fiber task %s in thread %s\n", fss.str().c_str(), tss.str().c_str() );
+
+ boost::optional< std::string > value;
+
+ send_buf.put("ping");
+ BOOST_ASSERT( recv_buf.take( value) );
+ fprintf( stderr, "ping fiber %s in thread %s recevied %s\n", fss.str().c_str(), tss.str().c_str(), value->c_str());
+ value.reset();
+
+ send_buf.put("ping");
+ BOOST_ASSERT( recv_buf.take( value) );
+ fprintf( stderr, "ping fiber %s in thread %s recevied %s\n", fss.str().c_str(), tss.str().c_str(), value->c_str());
+ value.reset();
+
+ send_buf.put("ping");
+ BOOST_ASSERT( recv_buf.take( value) );
+ fprintf( stderr, "ping fiber %s in thread %s recevied %s\n", fss.str().c_str(), tss.str().c_str(), value->c_str());
+ value.reset();
+
+ send_buf.deactivate();
+
+ fprintf( stderr, "end ping fiber %s in thread %s\n", fss.str().c_str(), tss.str().c_str() );
+}
+
+inline
+void pong(
+ fifo_t & recv_buf,
+ fifo_t & send_buf,
+ boost::tasks::spin::barrier & b)
+{
+ b.wait();
+ std::stringstream tss;
+ tss << boost::this_thread::get_id();
+ std::stringstream fss;
+ fss << boost::this_fiber::get_id();
+
+ fprintf( stderr, "start pong fiber %s in thread %s\n", fss.str().c_str(), tss.str().c_str() );
+
+ boost::optional< std::string > value;
+
+ BOOST_ASSERT( recv_buf.take( value) );
+ fprintf( stderr, "pong fiber %s in thread %s recevied %s\n", fss.str().c_str(), tss.str().c_str(), value->c_str());
+ value.reset();
+ send_buf.put("pong");
+
+ BOOST_ASSERT( recv_buf.take( value) );
+ fprintf( stderr, "pong fiber %s in thread %s recevied %s\n", fss.str().c_str(), tss.str().c_str(), value->c_str());
+ value.reset();
+ send_buf.put("pong");
+
+ BOOST_ASSERT( recv_buf.take( value) );
+ fprintf( stderr, "pong fiber %s in thread %s recevied %s\n", fss.str().c_str(), tss.str().c_str(), value->c_str());
+ value.reset();
+ send_buf.put("pong");
+
+ send_buf.deactivate();
+
+ fprintf( stderr, "end pong fiber %s in thread %s\n", fss.str().c_str(), tss.str().c_str() );
+}
+
+int main()
+{
+ try
+ {
+ fifo_t buf1;
+ fifo_t buf2;
+ boost::tasks::spin::barrier b( 2);
+
+ std::cout << "start" << std::endl;
+
+ pool_t pool( boost::tasks::poolsize( 2) );
+
+ boost::tasks::async(
+ boost::tasks::make_task( ping, buf1, buf2, boost::ref( b) ),
+ pool);
+
+ boost::tasks::async(
+ boost::tasks::make_task( pong, buf2, buf1, boost::ref( b) ),
+ pool);
+
+ pool.shutdown();
+
+ std::cout << "finish" << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( boost::system::system_error const& e)
+ { std::cerr << "system_error: " << e.code().value() << std::endl; }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch (...)
+ { std::cerr << "unhandled exception" << std::endl; }
+ return EXIT_FAILURE;
+}
Deleted: sandbox/task/libs/task/examples/sync/semaphore_ping_pong.cpp
==============================================================================
--- sandbox/task/libs/task/examples/sync/semaphore_ping_pong.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,131 +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 <iostream>
-#include <cstdlib>
-#include <stdexcept>
-
-#include <boost/bind.hpp>
-#include <boost/ref.hpp>
-
-#include "boost/task.hpp"
-
-namespace tsk = boost::task;
-
-void start_with_sem_a(
- int n,
- tsk::semaphore & sem_a,
- tsk::semaphore & sem_b)
-{
- for ( int i = 0; i < n; ++i)
- {
- printf("task 1: %d-th sema_a.post()\n", i);
- sem_a.post();
- printf("task 1: %d-th sema_b.wait()\n", i);
- sem_b.wait();
- }
- printf("task 1: end\n");
-}
-
-void start_with_sem_b(
- int n,
- tsk::semaphore & sem_a,
- tsk::semaphore & sem_b)
-{
- for ( int i = 0; i < n; ++i)
- {
- printf("task 2: %d-th sema_b.post()\n", i);
- sem_b.post();
- printf("task 2: %d-th sema_a.wait()\n", i);
- sem_a.wait();
- }
- printf("task 2: end\n");
-}
-
-void thread_only()
-{
- int n = 10;
- tsk::semaphore sem_a( 0), sem_b( 0);
- tsk::handle< void > h1 = tsk::async(
- tsk::make_task(
- & start_with_sem_a,
- n,
- boost::ref( sem_a),
- boost::ref( sem_b) ),
- tsk::new_thread() );
- tsk::handle< void > h2 = tsk::async(
- tsk::make_task(
- & start_with_sem_b,
- n,
- boost::ref( sem_a),
- boost::ref( sem_b) ),
- tsk::new_thread() );
-
- tsk::waitfor_all( h1, h2);
-}
-
-void pool_only()
-{
- tsk::static_pool< tsk::unbounded_twolock_fifo > pool( tsk::poolsize( 1) );
-
- int n = 10;
- tsk::semaphore sem_a( 0), sem_b( 0);
- tsk::async(
- tsk::make_task(
- & start_with_sem_a,
- n,
- boost::ref( sem_a),
- boost::ref( sem_b) ),
- pool);
- tsk::async(
- tsk::make_task(
- & start_with_sem_b,
- n,
- boost::ref( sem_a),
- boost::ref( sem_b) ),
- pool);
-}
-
-void pool_and_thread()
-{
- tsk::static_pool< tsk::unbounded_twolock_fifo > pool( tsk::poolsize( 1) );
-
- int n = 10;
- tsk::semaphore sem_a( 0), sem_b( 0);
- tsk::async(
- tsk::make_task(
- & start_with_sem_a,
- n,
- boost::ref( sem_a),
- boost::ref( sem_b) ),
- pool);
- tsk::handle< void > h = tsk::async(
- tsk::make_task(
- & start_with_sem_b,
- n,
- boost::ref( sem_a),
- boost::ref( sem_b) ),
- tsk::new_thread() );
-
- h.wait();
-}
-
-int main( int argc, char *argv[])
-{
- try
- {
- pool_only();
- thread_only();
- pool_and_thread();
- return EXIT_SUCCESS;
- }
- catch ( std::exception const& e)
- { std::cerr << "exception: " << e.what() << std::endl; }
- catch ( ... )
- { std::cerr << "unhandled" << std::endl; }
-
- return EXIT_FAILURE;
-}
Modified: sandbox/task/libs/task/src/callable.cpp
==============================================================================
--- sandbox/task/libs/task/src/callable.cpp (original)
+++ sandbox/task/libs/task/src/callable.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -7,7 +7,7 @@
#include "boost/task/callable.hpp"
namespace boost {
-namespace task {
+namespace tasks {
callable::callable() :
impl_()
Modified: sandbox/task/libs/task/src/context.cpp
==============================================================================
--- sandbox/task/libs/task/src/context.cpp (original)
+++ sandbox/task/libs/task/src/context.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -9,7 +9,7 @@
#include <boost/assert.hpp>
namespace boost {
-namespace task {
+namespace tasks {
void
context::impl::reset_( shared_ptr< thread > const& thrd)
Modified: sandbox/task/libs/task/src/guard.cpp
==============================================================================
--- sandbox/task/libs/task/src/guard.cpp (original)
+++ sandbox/task/libs/task/src/guard.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -11,7 +11,7 @@
#include <boost/task/detail/atomic.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
guard::guard( volatile uint32_t & active_worker) :
Modified: sandbox/task/libs/task/src/poolsize.cpp
==============================================================================
--- sandbox/task/libs/task/src/poolsize.cpp (original)
+++ sandbox/task/libs/task/src/poolsize.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -9,7 +9,7 @@
#include <boost/task/exceptions.hpp>
namespace boost {
-namespace task {
+namespace tasks {
poolsize::poolsize( std::size_t value) :
value_( value)
Modified: sandbox/task/libs/task/src/scanns.cpp
==============================================================================
--- sandbox/task/libs/task/src/scanns.cpp (original)
+++ sandbox/task/libs/task/src/scanns.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -9,7 +9,7 @@
#include <boost/task/exceptions.hpp>
namespace boost {
-namespace task {
+namespace tasks {
scanns::scanns( std::size_t value) :
value_( value)
Deleted: sandbox/task/libs/task/src/semaphore_posix.cpp
==============================================================================
--- sandbox/task/libs/task/src/semaphore_posix.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,87 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/semaphore.hpp"
-
-#include <cerrno>
-
-#include <boost/system/error_code.hpp>
-#include <boost/system/system_error.hpp>
-#include <boost/thread.hpp>
-
-#include "boost/task/exceptions.hpp"
-#include "boost/task/utility.hpp"
-
-namespace boost {
-namespace task {
-
-semaphore::semaphore( int value) :
- handle_()
-{
- if ( ::sem_init( & handle_, 0, value) == -1)
- throw system::system_error( errno, system::system_category);
-}
-
-semaphore::~semaphore()
-{ ::sem_destroy( & handle_); }
-
-void
-semaphore::post()
-{
- if ( ::sem_post( & handle_) == -1)
- throw system::system_error( errno, system::system_category);
-}
-
-void
-semaphore::wait()
-{
- int ret( -1);
- if ( this_task::runs_in_pool() )
- {
- while ( ! try_wait() )
- {
- this_thread::interruption_point();
- this_task::block();
- this_thread::interruption_point();
- }
- }
- else
- {
- do
- { ret = ::sem_wait( & handle_); }
- while ( ret == -1 && errno == EINTR);
- if ( ret == -1)
- throw system::system_error( errno, system::system_category);
- }
-}
-
-bool
-semaphore::try_wait()
-{
- int ret( -1);
- do
- { ret = ::sem_trywait( & handle_); }
- while ( ret == -1 && errno == EINTR);
- if ( ret == -1)
- {
- if ( errno == EAGAIN)
- return false;
- else
- throw system::system_error( errno, system::system_category);
- }
- return true;
-}
-
-int
-semaphore::value()
-{
- int value( 0);
- if ( ::sem_getvalue( & handle_, & value) == -1)
- throw system::system_error( errno, system::system_category);
- return value;
-}
-
-}}
Deleted: sandbox/task/libs/task/src/semaphore_windows.cpp
==============================================================================
--- sandbox/task/libs/task/src/semaphore_windows.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,81 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/semaphore.hpp"
-
-#include <cerrno>
-#include <limits>
-
-#include <boost/system/error_code.hpp>
-#include <boost/system/system_error.hpp>
-
-#include "boost/task/exceptions.hpp"
-#include "boost/task/utility.hpp"
-
-namespace boost {
-namespace task {
-
-semaphore::semaphore( int value) :
- handle_()
-{
- if ( ( handle_ = ::CreateSemaphore( 0, value, (std::numeric_limits< int >::max)(), 0) ) == 0)
- throw system::system_error( ::GetLastError(), system::system_category);
-}
-
-semaphore::~semaphore()
-{ ::CloseHandle( handle_); }
-
-void
-semaphore::post()
-{
- if ( ! ::ReleaseSemaphore( handle_, 1, 0) )
- throw system::system_error( ::GetLastError(), system::system_category);
-}
-
-void
-semaphore::wait()
-{
- if ( this_task::runs_in_pool() )
- {
- while ( ! try_wait() )
- this_task::block();
- }
- else
- {
- if ( ::WaitForSingleObject( handle_, INFINITE) != WAIT_OBJECT_0)
- throw system::system_error( ::GetLastError(), system::system_category);
- }
-}
-
-bool
-semaphore::try_wait()
-{
- switch ( ::WaitForSingleObject( handle_, 0) )
- {
- case WAIT_OBJECT_0:
- return true;
- case WAIT_TIMEOUT:
- return false;
- default:
- throw system::system_error( ::GetLastError(), system::system_category);
- }
- return true;
-}
-
-int
-semaphore::value()
-{
- int value( 0);
- if ( ::WaitForSingleObject( handle_, 0) != WAIT_TIMEOUT)
- {
- if ( ! ::ReleaseSemaphore( handle_, 1, ( LPLONG) & value) )
- throw system::system_error( ::GetLastError(), system::system_category);
- ++ value;
- }
- return value;
-}
-
-}}
Added: sandbox/task/libs/task/src/spin/auto_reset_event.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/spin/auto_reset_event.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,71 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/task/spin/auto_reset_event.hpp"
+
+#include <boost/thread/thread.hpp>
+
+#include <boost/task/utility.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+auto_reset_event::auto_reset_event( bool isset) :
+ state_( isset ? SET : RESET)
+{}
+
+void
+auto_reset_event::set()
+{ state_.exchange( SET); }
+
+void
+auto_reset_event::wait()
+{
+ state expected = SET;
+ while ( ! state_.compare_exchange_strong( expected, RESET) )
+ {
+ this_thread::interruption_point();
+ if ( this_task::runs_in_pool() )
+ this_task::block();
+ else
+ this_thread::yield();
+ this_thread::interruption_point();
+
+ expected = SET;
+ }
+}
+
+bool
+auto_reset_event::try_wait()
+{
+ state expected = SET;
+ return state_.compare_exchange_strong( expected, RESET);
+}
+
+bool
+auto_reset_event::wait( system_time const& abs_time)
+{
+ if ( get_system_time() >= abs_time) return false;
+
+ state expected = SET;
+ while ( ! state_.compare_exchange_strong( expected, RESET) )
+ {
+ this_thread::interruption_point();
+ if ( this_task::runs_in_pool() )
+ this_task::block();
+ else
+ this_thread::yield();
+ this_thread::interruption_point();
+
+ if ( get_system_time() >= abs_time) return false;
+ expected = SET;
+ }
+
+ return true;
+}
+
+}}}
Added: sandbox/task/libs/task/src/spin/barrier.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/spin/barrier.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,43 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/task/spin/barrier.hpp"
+
+#include <stdexcept>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+barrier::barrier( std::size_t initial) :
+ initial_( initial),
+ current_( initial_),
+ cycle_( true),
+ mtx_(),
+ cond_()
+{ if ( initial == 0) throw std::invalid_argument("invalid barrier count"); }
+
+bool
+barrier::wait()
+{
+ mutex::scoped_lock lk( mtx_);
+ bool cycle( cycle_);
+ if ( 0 == --current_)
+ {
+ cycle_ = ! cycle_;
+ current_ = initial_;
+ cond_.notify_all();
+ return true;
+ }
+ else
+ {
+ while ( cycle == cycle_)
+ cond_.wait( lk);
+ }
+ return false;
+}
+
+}}}
Added: sandbox/task/libs/task/src/spin/condition.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/spin/condition.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,52 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/task/spin/condition.hpp"
+
+#include <boost/thread/thread.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+void
+condition::notify_( command cmd)
+{
+ enter_mtx_.lock();
+
+ if ( 0 == waiters_.load() )
+ {
+ enter_mtx_.unlock();
+ return;
+ }
+
+ command expected = SLEEPING;
+ while ( ! cmd_.compare_exchange_strong( expected, cmd) )
+ {
+ if ( this_fiber::runs_as_fiber() )
+ this_fiber::yield();
+ else
+ this_thread::yield();
+ expected = SLEEPING;
+ }
+}
+
+condition::condition() :
+ cmd_( SLEEPING),
+ waiters_( 0),
+ enter_mtx_(),
+ check_mtx_()
+{}
+
+void
+condition::notify_one()
+{ notify_( NOTIFY_ONE); }
+
+void
+condition::notify_all()
+{ notify_( NOTIFY_ALL); }
+
+}}}
Added: sandbox/task/libs/task/src/spin/count_down_event.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/spin/count_down_event.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,82 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/task/spin/count_down_event.hpp"
+
+#include <boost/thread/thread.hpp>
+
+#include <boost/task/spin/mutex.hpp>
+#include <boost/task/utility.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+count_down_event::count_down_event( std::size_t initial) :
+ initial_( initial),
+ current_( initial_)
+{}
+
+std::size_t
+count_down_event::initial() const
+{ return initial_; }
+
+std::size_t
+count_down_event::current() const
+{ return current_.load(); }
+
+bool
+count_down_event::is_set() const
+{ return 0 == current_.load(); }
+
+void
+count_down_event::set()
+{
+ for (;;)
+ {
+ if ( 0 == current_.load() )
+ return;
+ std::size_t expected = current_.load();
+ if ( current_.compare_exchange_strong( expected, expected - 1) )
+ return;
+ }
+}
+
+void
+count_down_event::wait()
+{
+ while ( 0 != current_.load() )
+ {
+ this_thread::interruption_point();
+ if ( this_task::runs_in_pool() )
+ this_task::block();
+ else
+ this_thread::yield();
+ this_thread::interruption_point();
+ }
+}
+
+bool
+count_down_event::wait( system_time const& abs_time)
+{
+ if ( get_system_time() >= abs_time) return false;
+
+ while ( 0 != current_.load() )
+ {
+ this_thread::interruption_point();
+ if ( this_task::runs_in_pool() )
+ this_task::block();
+ else
+ this_thread::yield();
+ this_thread::interruption_point();
+
+ if ( get_system_time() >= abs_time) return false;
+ }
+
+ return true;
+}
+
+}}}
Added: sandbox/task/libs/task/src/spin/manual_reset_event.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/spin/manual_reset_event.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,104 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/task/spin/manual_reset_event.hpp"
+
+#include <boost/assert.hpp>
+#include <boost/thread/thread.hpp>
+
+#include <boost/task/utility.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+manual_reset_event::manual_reset_event( bool isset) :
+ state_( isset ? SET : RESET),
+ waiters_( 0),
+ enter_mtx_()
+{}
+
+void
+manual_reset_event::set()
+{
+ enter_mtx_.lock();
+
+ state expected = RESET;
+ if ( ! state_.compare_exchange_strong( expected, SET) ||
+ 0 == waiters_.load() )
+ enter_mtx_.unlock();
+}
+
+void
+manual_reset_event::reset()
+{
+ mutex::scoped_lock lk( enter_mtx_);
+ BOOST_ASSERT( lk);
+
+ state_.exchange( RESET);
+}
+
+void
+manual_reset_event::wait()
+{
+ {
+ mutex::scoped_lock lk( enter_mtx_);
+ BOOST_ASSERT( lk);
+ waiters_.fetch_add( 1);
+ }
+
+ while ( RESET == state_.load() )
+ {
+ this_thread::interruption_point();
+ if ( this_task::runs_in_pool() )
+ this_task::block();
+ else
+ this_thread::yield();
+ this_thread::interruption_point();
+ }
+
+ if ( 1 == waiters_.fetch_sub( 1) )
+ enter_mtx_.unlock();
+}
+
+bool
+manual_reset_event::wait( system_time const& abs_time)
+{
+ if ( get_system_time() >= abs_time) return false;
+
+ while ( RESET == state_.load() )
+ {
+ this_thread::interruption_point();
+ if ( this_task::runs_in_pool() )
+ this_task::block();
+ else
+ this_thread::yield();
+ this_thread::interruption_point();
+
+ if ( get_system_time() >= abs_time) return false;
+ }
+
+ return true;
+}
+
+bool
+manual_reset_event::try_wait()
+{
+ {
+ mutex::scoped_lock lk( enter_mtx_);
+ BOOST_ASSERT( lk);
+ waiters_.fetch_add( 1);
+ }
+
+ bool result = SET == state_.load();
+
+ if ( 1 == waiters_.fetch_sub( 1) )
+ enter_mtx_.unlock();
+
+ return result;
+}
+
+}}}
Added: sandbox/task/libs/task/src/spin/mutex.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/spin/mutex.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -0,0 +1,77 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/task/spin/mutex.hpp>
+
+#include <boost/thread/thread.hpp>
+
+#include <boost/task/utility.hpp>
+
+namespace boost {
+namespace tasks {
+namespace spin {
+
+mutex::mutex() :
+ state_( UNLOCKED)
+{}
+
+void
+mutex::lock()
+{
+ for (;;)
+ {
+ state expected = UNLOCKED;
+ if ( state_.compare_exchange_strong( expected, LOCKED) )
+ break;
+ if ( this_fiber::runs_as_fiber() )
+ this_fiber::yield();
+ else
+ this_thread::yield();
+ }
+}
+
+bool
+mutex::timed_lock( system_time const& abs_time)
+{
+ if ( abs_time.is_infinity() )
+ {
+ lock();
+ return true;
+ }
+
+ if ( get_system_time() >= abs_time)
+ return false;
+
+ for (;;)
+ {
+ if ( try_lock() ) break;
+
+ if ( get_system_time() >= abs_time)
+ return false;
+
+ this_thread::interruption_point();
+ if ( this_task::runs_in_pool() )
+ this_task::block();
+ else
+ this_thread::yield();
+ this_thread::interruption_point();
+ }
+
+ return true;
+}
+
+bool
+mutex::try_lock()
+{
+ state expected = UNLOCKED;
+ return state_.compare_exchange_strong( expected, LOCKED);
+}
+
+void
+mutex::unlock()
+{ state_.exchange( UNLOCKED); }
+
+}}}
Deleted: sandbox/task/libs/task/src/spin_auto_reset_event.cpp
==============================================================================
--- sandbox/task/libs/task/src/spin_auto_reset_event.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,79 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/spin_auto_reset_event.hpp"
-
-#include <boost/thread.hpp>
-
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/utility.hpp>
-
-namespace boost {
-namespace task {
-
-spin_auto_reset_event::spin_auto_reset_event( bool isset) :
- state_(
- isset ?
- static_cast< uint32_t >( SET) :
- static_cast< uint32_t >( RESET) )
-{}
-
-void
-spin_auto_reset_event::set()
-{ detail::atomic_exchange( & state_, static_cast< uint32_t >( SET) ); }
-
-void
-spin_auto_reset_event::wait()
-{
- uint32_t expected = static_cast< uint32_t >( SET);
- while ( ! detail::atomic_compare_exchange_strong(
- & state_, & expected,
- static_cast< uint32_t >( RESET) ) )
- {
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
- expected = static_cast< uint32_t >( SET);
- }
-}
-
-bool
-spin_auto_reset_event::wait( system_time const& abs_time)
-{
- if ( get_system_time() >= abs_time) return false;
-
- uint32_t expected = static_cast< uint32_t >( SET);
- while ( ! detail::atomic_compare_exchange_strong(
- & state_, & expected,
- static_cast< uint32_t >( RESET) ) )
- {
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
-
- if ( get_system_time() >= abs_time) return false;
- expected = static_cast< uint32_t >( SET);
- }
-
- return true;
-}
-
-bool
-spin_auto_reset_event::try_wait()
-{
- uint32_t expected = static_cast< uint32_t >( SET);
- return detail::atomic_compare_exchange_strong(
- & state_, & expected,
- static_cast< uint32_t >( RESET) );
-}
-
-}}
Deleted: sandbox/task/libs/task/src/spin_condition.cpp
==============================================================================
--- sandbox/task/libs/task/src/spin_condition.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,195 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/spin_condition.hpp"
-
-#include <boost/assert.hpp>
-#include <boost/thread.hpp>
-
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/spin_mutex.hpp>
-#include <boost/task/utility.hpp>
-
-namespace boost {
-namespace task {
-
-void
-spin_condition::notify_( uint32_t cmd)
-{
- enter_mtx_.lock();
-
- if ( 0 == detail::atomic_load( & waiters_) )
- {
- enter_mtx_.unlock();
- return;
- }
-
- uint32_t expected = static_cast< uint32_t >( SLEEPING);
- while ( ! detail::atomic_compare_exchange_strong(
- & cmd_, & expected, cmd) )
- {
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
- }
-}
-
-void
-spin_condition::wait_( spin_mutex & mtx)
-{
- {
- spin_mutex::scoped_lock lk( enter_mtx_);
- BOOST_ASSERT( lk);
- detail::atomic_fetch_add( & waiters_, 1);
- mtx.unlock();
- }
-
- bool unlock_enter_mtx = false;
- for (;;)
- {
- while ( static_cast< uint32_t >( SLEEPING) == detail::atomic_load( & cmd_) )
- {
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
- }
-
- spin_mutex::scoped_lock lk( check_mtx_);
- BOOST_ASSERT( lk);
-
- uint32_t expected = static_cast< uint32_t >( NOTIFY_ONE);
- detail::atomic_compare_exchange_strong(
- & cmd_, & expected,
- static_cast< uint32_t >( SLEEPING) );
- if ( static_cast< uint32_t >( SLEEPING) == expected)
- continue;
- else if ( static_cast< uint32_t >( NOTIFY_ONE) == expected)
- {
- unlock_enter_mtx = true;
- detail::atomic_fetch_sub( & waiters_, 1);
- break;
- }
- else
- {
- unlock_enter_mtx = 1 == detail::atomic_fetch_sub( & waiters_, 1);
- if ( unlock_enter_mtx)
- {
- expected = static_cast< uint32_t >( NOTIFY_ALL);
- detail::atomic_compare_exchange_strong(
- & cmd_, & expected,
- static_cast< uint32_t >( SLEEPING) );
- }
- break;
- }
- }
-
- if ( unlock_enter_mtx)
- enter_mtx_.unlock();
-
- mtx.lock();
-}
-
-bool
-spin_condition::wait_( spin_mutex & mtx, system_time const& abs_time)
-{
- if ( get_system_time() >= abs_time) return false;
-
- {
- spin_mutex::scoped_lock lk( enter_mtx_, abs_time);
- BOOST_ASSERT( lk);
- detail::atomic_fetch_add( & waiters_, 1);
- mtx.unlock();
- }
-
- bool timed_out = false, unlock_enter_mtx = false;
- for (;;)
- {
- while ( static_cast< uint32_t >( SLEEPING) == detail::atomic_load( & cmd_) )
- {
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
-
- if ( get_system_time() >= abs_time)
- {
- timed_out = enter_mtx_.try_lock();
- if ( ! timed_out)
- continue;
- break;
- }
- }
-
- if ( timed_out)
- {
- detail::atomic_fetch_sub( & waiters_, 1);
- unlock_enter_mtx = true;
- break;
- }
- else
- {
- spin_mutex::scoped_lock lk( check_mtx_);
- BOOST_ASSERT( lk);
-
- uint32_t expected = static_cast< uint32_t >( NOTIFY_ONE);
- detail::atomic_compare_exchange_strong(
- & cmd_, & expected,
- static_cast< uint32_t >( SLEEPING) );
- if ( static_cast< uint32_t >( SLEEPING) == expected)
- continue;
- else if ( static_cast< uint32_t >( NOTIFY_ONE) == expected)
- {
- unlock_enter_mtx = true;
- detail::atomic_fetch_sub( & waiters_, 1);
- break;
- }
- else
- {
- unlock_enter_mtx = 1 == detail::atomic_fetch_sub( & waiters_, 1);
- if ( unlock_enter_mtx)
- {
- expected = static_cast< uint32_t >( NOTIFY_ALL);
- detail::atomic_compare_exchange_strong(
- & cmd_, & expected,
- static_cast< uint32_t >( SLEEPING) );
- }
- break;
- }
- }
- }
-
- if ( unlock_enter_mtx)
- enter_mtx_.unlock();
-
- mtx.lock();
-
- return ! timed_out;
-}
-
-spin_condition::spin_condition() :
- cmd_( static_cast< uint32_t >( SLEEPING) ),
- waiters_( 0),
- enter_mtx_(),
- check_mtx_()
-{}
-
-void
-spin_condition::notify_one()
-{ notify_( static_cast< uint32_t >( NOTIFY_ONE) ); }
-
-void
-spin_condition::notify_all()
-{ notify_( static_cast< uint32_t >( NOTIFY_ALL) ); }
-
-}}
Deleted: sandbox/task/libs/task/src/spin_count_down_event.cpp
==============================================================================
--- sandbox/task/libs/task/src/spin_count_down_event.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,82 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/spin_count_down_event.hpp"
-
-#include <boost/thread.hpp>
-
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/spin_mutex.hpp>
-#include <boost/task/utility.hpp>
-
-namespace boost {
-namespace task {
-
-spin_count_down_event::spin_count_down_event( uint32_t initial) :
- initial_( initial),
- current_( initial_)
-{}
-
-uint32_t
-spin_count_down_event::initial() const
-{ return initial_; }
-
-uint32_t
-spin_count_down_event::current() const
-{ return detail::atomic_load( & current_); }
-
-bool
-spin_count_down_event::is_set() const
-{ return 0 == detail::atomic_load( & current_); }
-
-void
-spin_count_down_event::set()
-{
- for (;;)
- {
- if ( 0 == detail::atomic_load( & current_) )
- return;
- uint32_t expected = current_;
- if ( detail::atomic_compare_exchange_strong( & current_, & expected, expected - 1) )
- return;
- }
-}
-
-void
-spin_count_down_event::wait()
-{
- while ( 0 != detail::atomic_load( & current_) )
- {
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
- }
-}
-
-bool
-spin_count_down_event::wait( system_time const& abs_time)
-{
- if ( get_system_time() >= abs_time) return false;
-
- while ( 0 < detail::atomic_load( & current_) )
- {
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
-
- if ( get_system_time() >= abs_time) return false;
- }
-
- return true;
-}
-
-}}
Deleted: sandbox/task/libs/task/src/spin_manual_reset_event.cpp
==============================================================================
--- sandbox/task/libs/task/src/spin_manual_reset_event.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,110 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/spin_manual_reset_event.hpp"
-
-#include <boost/assert.hpp>
-#include <boost/thread.hpp>
-
-#include <boost/task/detail/atomic.hpp>
-#include <boost/task/utility.hpp>
-
-namespace boost {
-namespace task {
-
-spin_manual_reset_event::spin_manual_reset_event( bool isset) :
- state_(
- isset ?
- static_cast< uint32_t >( SET) :
- static_cast< uint32_t >( RESET) ),
- waiters_( 0),
- enter_mtx_()
-{}
-
-void
-spin_manual_reset_event::set()
-{
- enter_mtx_.lock();
-
- uint32_t expected = static_cast< uint32_t >( RESET);
- if ( ! detail::atomic_compare_exchange_strong(
- & state_, & expected,
- static_cast< uint32_t >( SET) ) ||
- ! detail::atomic_load( & waiters_ ) )
- enter_mtx_.unlock();
-}
-
-void
-spin_manual_reset_event::reset()
-{
- spin_mutex::scoped_lock lk( enter_mtx_);
- BOOST_ASSERT( lk);
-
- detail::atomic_exchange( & state_,
- static_cast< uint32_t >( RESET) );
-}
-
-void
-spin_manual_reset_event::wait()
-{
- {
- spin_mutex::scoped_lock lk( enter_mtx_);
- BOOST_ASSERT( lk);
- detail::atomic_fetch_add( & waiters_, 1);
- }
-
- while ( static_cast< uint32_t >( RESET) == detail::atomic_load( & state_) )
- {
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
- }
-
- if ( 1 == detail::atomic_fetch_sub( & waiters_, 1) )
- enter_mtx_.unlock();
-}
-
-bool
-spin_manual_reset_event::wait( system_time const& abs_time)
-{
- if ( get_system_time() >= abs_time) return false;
-
- while ( static_cast< uint32_t >( RESET) == detail::atomic_load( & state_) )
- {
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
-
- if ( get_system_time() >= abs_time) return false;
- }
-
- return true;
-}
-
-bool
-spin_manual_reset_event::try_wait()
-{
- {
- spin_mutex::scoped_lock lk( enter_mtx_);
- BOOST_ASSERT( lk);
- detail::atomic_fetch_add( & waiters_, 1);
- }
-
- bool result = static_cast< uint32_t >( SET) == detail::atomic_load( & state_);
-
- if ( 1 == detail::atomic_fetch_sub( & waiters_, 1) )
- enter_mtx_.unlock();
-
- return result;
-}
-
-}}
Deleted: sandbox/task/libs/task/src/spin_mutex.cpp
==============================================================================
--- sandbox/task/libs/task/src/spin_mutex.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,85 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/task/spin_mutex.hpp"
-
-#include <boost/thread.hpp>
-
-#include "boost/task/detail/atomic.hpp"
-#include "boost/task/utility.hpp"
-
-namespace boost {
-namespace task {
-
-spin_mutex::spin_mutex() :
- state_( 0)
-{}
-
-void
-spin_mutex::lock()
-{
- for (;;)
- {
- uint32_t expected = 0;
- if ( detail::atomic_compare_exchange_strong( & state_, & expected, 1) )
- break;
- else
- {
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
- }
- }
-}
-
-bool
-spin_mutex::try_lock()
-{
- uint32_t expected = 0;
- return detail::atomic_compare_exchange_strong( & state_, & expected, 1);
-}
-
-bool
-spin_mutex::timed_lock( system_time const& abs_time)
-{
- if ( abs_time.is_infinity() )
- {
- lock();
- return true;
- }
-
- if ( get_system_time() >= abs_time)
- return false;
-
- for (;;)
- {
- if ( try_lock() ) break;
-
- if ( get_system_time() >= abs_time)
- return false;
-
- this_thread::interruption_point();
- if ( this_task::runs_in_pool() )
- this_task::block();
- else
- this_thread::yield();
- this_thread::interruption_point();
- }
-
- return true;
-}
-
-void
-spin_mutex::unlock()
-{
- uint32_t expected = 1;
- detail::atomic_compare_exchange_strong( & state_, & expected, 0);
-}
-
-}}
Modified: sandbox/task/libs/task/src/stacksize.cpp
==============================================================================
--- sandbox/task/libs/task/src/stacksize.cpp (original)
+++ sandbox/task/libs/task/src/stacksize.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -9,7 +9,7 @@
#include <boost/task/exceptions.hpp>
namespace boost {
-namespace task {
+namespace tasks {
stacksize::stacksize( std::size_t value) :
value_( value)
Modified: sandbox/task/libs/task/src/watermark.cpp
==============================================================================
--- sandbox/task/libs/task/src/watermark.cpp (original)
+++ sandbox/task/libs/task/src/watermark.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -9,7 +9,7 @@
#include <boost/task/exceptions.hpp>
namespace boost {
-namespace task {
+namespace tasks {
high_watermark::high_watermark( std::size_t value) :
value_( value)
Modified: sandbox/task/libs/task/src/worker.cpp
==============================================================================
--- sandbox/task/libs/task/src/worker.cpp (original)
+++ sandbox/task/libs/task/src/worker.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -7,7 +7,7 @@
#include "boost/task/detail/worker.hpp"
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
thread_specific_ptr< worker > worker::tss_;
Modified: sandbox/task/libs/task/src/worker_group.cpp
==============================================================================
--- sandbox/task/libs/task/src/worker_group.cpp (original)
+++ sandbox/task/libs/task/src/worker_group.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -10,7 +10,7 @@
#include <boost/utility.hpp>
namespace boost {
-namespace task {
+namespace tasks {
namespace detail {
worker_group::worker_group() :
Modified: sandbox/task/libs/task/src/wsq.cpp
==============================================================================
--- sandbox/task/libs/task/src/wsq.cpp (original)
+++ sandbox/task/libs/task/src/wsq.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -10,7 +10,7 @@
#include <boost/task/detail/atomic.hpp>
-namespace boost { namespace task {
+namespace boost { namespace tasks {
namespace detail
{
Modified: sandbox/task/libs/task/test/Jamfile.v2
==============================================================================
--- sandbox/task/libs/task/test/Jamfile.v2 (original)
+++ sandbox/task/libs/task/test/Jamfile.v2 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -10,6 +10,7 @@
project boost/task/test
: requirements
<library>../../test/build//boost_unit_test_framework
+ <library>../../fiber/build//boost_fiber
<library>../../thread/build//boost_thread
<library>../../system/build//boost_system
<library>../build//boost_task
@@ -25,7 +26,6 @@
}
test-suite task :
- [ task-test test_futures ]
[ task-test test_task ]
[ task-test test_own_thread ]
[ task-test test_new_thread ]
@@ -34,14 +34,11 @@
[ task-test test_bounded_twolock_pool ]
[ task-test test_bounded_onelock_pool ]
[ task-test test_as_sub_task ]
- [ task-test test_semaphore ]
- [ task-test test_spin_mutex ]
- [ task-test test_spin_unique_lock ]
- [ task-test test_generic_locks ]
- [ task-test test_spin_condition ]
- [ task-test test_spin_condition_notify_all ]
- [ task-test test_spin_condition_notify_one ]
- [ task-test test_spin_condition_timed_wait_times_out ]
+ [ task-test test_spin::mutex ]
+ [ task-test test_spin::condition ]
+ [ task-test test_spin::condition_notify_all ]
+ [ task-test test_spin::condition_notify_one ]
+ [ task-test test_spin::condition_timed_wait_times_out ]
[ task-test test_spin_count_down_event ]
[ task-test test_spin_auto_reset_event ]
[ task-test test_spin_manual_reset_event ]
Modified: sandbox/task/libs/task/test/condition_test_common.hpp
==============================================================================
--- sandbox/task/libs/task/test/condition_test_common.hpp (original)
+++ sandbox/task/libs/task/test/condition_test_common.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -10,14 +10,14 @@
#include <boost/task.hpp>
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
unsigned const timeout_seconds=5;
struct wait_for_flag : private boost::noncopyable
{
- tsk::spin_mutex mutex;
- tsk::spin_condition cond_var;
+ tsk::spin::mutex mutex;
+ tsk::spin::condition cond_var;
bool flag;
unsigned woken;
@@ -44,7 +44,7 @@
void wait_without_predicate()
{
- tsk::spin_mutex::scoped_lock lock(mutex);
+ tsk::spin::mutex::scoped_lock lock(mutex);
while(!flag)
{
cond_var.wait(lock);
@@ -54,7 +54,7 @@
void wait_with_predicate()
{
- tsk::spin_mutex::scoped_lock lock(mutex);
+ tsk::spin::mutex::scoped_lock lock(mutex);
cond_var.wait(lock,check_flag(flag));
if(flag)
{
@@ -66,7 +66,7 @@
{
boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(timeout_seconds);
- tsk::spin_mutex::scoped_lock lock(mutex);
+ tsk::spin::mutex::scoped_lock lock(mutex);
while(!flag)
{
if(!cond_var.timed_wait(lock,timeout))
@@ -80,7 +80,7 @@
void timed_wait_with_predicate()
{
boost::system_time const timeout=boost::get_system_time()+boost::posix_time::seconds(timeout_seconds);
- tsk::spin_mutex::scoped_lock lock(mutex);
+ tsk::spin::mutex::scoped_lock lock(mutex);
if(cond_var.timed_wait(lock,timeout,check_flag(flag)) && flag)
{
++woken;
@@ -88,7 +88,7 @@
}
void relative_timed_wait_with_predicate()
{
- tsk::spin_mutex::scoped_lock lock(mutex);
+ tsk::spin::mutex::scoped_lock lock(mutex);
if(cond_var.timed_wait(lock,boost::posix_time::seconds(timeout_seconds),check_flag(flag)) && flag)
{
++woken;
Modified: sandbox/task/libs/task/test/test_as_sub_task.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_as_sub_task.cpp (original)
+++ sandbox/task/libs/task/test/test_as_sub_task.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -23,7 +23,7 @@
#include "test_functions.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
namespace {
Modified: sandbox/task/libs/task/test/test_bounded_buffer.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_bounded_buffer.cpp (original)
+++ sandbox/task/libs/task/test/test_bounded_buffer.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -22,7 +22,7 @@
#include <boost/task.hpp>
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
struct send_data
{
Modified: sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -25,7 +25,7 @@
#include "test_functions.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
// check size and move op
void test_case_1()
Modified: sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -25,7 +25,7 @@
#include "test_functions.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
// check size and move op
void test_case_1()
Modified: sandbox/task/libs/task/test/test_functions.hpp
==============================================================================
--- sandbox/task/libs/task/test/test_functions.hpp (original)
+++ sandbox/task/libs/task/test/test_functions.hpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -37,7 +37,7 @@
#include <boost/task.hpp>
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
void barrier_fn(
boost::barrier & b)
Deleted: sandbox/task/libs/task/test/test_futures.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_futures.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,758 +0,0 @@
-// (C) Copyright 2008 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)
-
-#include "boost/thread/thread.hpp"
-#include "boost/thread/mutex.hpp"
-#include "boost/thread/condition.hpp"
-#include "boost/task/future.hpp"
-#include <assert.h>
-#include <utility>
-#include <memory>
-#include <string>
-
-#ifdef BOOST_HAS_RVALUE_REFS
- template<typename T>
- typename boost::remove_reference<T>::type&& move(T&& t)
- {
- return t;
- }
-#else
- template<typename T>
- boost::detail::thread_move_t<T> move(T& t)
- {
- return boost::move(t);
- }
-#endif
-
-struct X
-{
-private:
-
- X(X& other);
-
-public:
-
- int i;
-
- X():
- i(42)
- {}
-#ifdef BOOST_HAS_RVALUE_REFS
- X(X&& other):
- i(other.i)
- {
- other.i=0;
- }
-#else
- X(boost::detail::thread_move_t<X> other):
- i(other->i)
- {
- other->i=0;
- }
- operator boost::detail::thread_move_t<X>()
- {
- return boost::detail::thread_move_t<X>(*this);
- }
-#endif
- ~X()
- {}
-};
-
-int make_int()
-{
- return 42;
-}
-
-int throw_runtime_error()
-{
- throw std::runtime_error("42");
-}
-
-void set_promise_thread(boost::promise<int>* p)
-{
- p->set_value(42);
-}
-
-struct my_exception
-{};
-
-void set_promise_exception_thread(boost::promise<int>* p)
-{
- p->set_exception(boost::copy_exception(my_exception()));
-}
-
-
-void test_store_value_from_thread()
-{
- boost::promise<int> pi2;
- boost::unique_future<int> fi2=pi2.get_future();
- boost::thread(set_promise_thread,&pi2);
- int j=fi2.get();
- assert(j==42);
- assert(fi2.is_ready());
- assert(fi2.has_value());
- assert(!fi2.has_exception());
- assert(fi2.get_state()==boost::future_state::ready);
-}
-
-
-void test_store_exception()
-{
- boost::promise<int> pi3;
- boost::unique_future<int> fi3=pi3.get_future();
- boost::thread(set_promise_exception_thread,&pi3);
- try
- {
- fi3.get();
- assert(false);
- }
- catch(my_exception)
- {
- assert(true);
- }
-
- assert(fi3.is_ready());
- assert(!fi3.has_value());
- assert(fi3.has_exception());
- assert(fi3.get_state()==boost::future_state::ready);
-}
-
-void test_initial_state()
-{
- boost::unique_future<int> fi;
- assert(!fi.is_ready());
- assert(!fi.has_value());
- assert(!fi.has_exception());
- assert(fi.get_state()==boost::future_state::uninitialized);
- int i;
- try
- {
- i=fi.get();
- assert(false);
- }
- catch(boost::future_uninitialized)
- {
- assert(true);
- }
-}
-
-void test_waiting_future()
-{
- boost::promise<int> pi;
- boost::unique_future<int> fi;
- fi=pi.get_future();
-
- int i=0;
- assert(!fi.is_ready());
- assert(!fi.has_value());
- assert(!fi.has_exception());
- assert(fi.get_state()==boost::future_state::waiting);
- assert(i==0);
-}
-
-void test_cannot_get_future_twice()
-{
- boost::promise<int> pi;
- pi.get_future();
-
- try
- {
- pi.get_future();
- assert(false);
- }
- catch(boost::future_already_retrieved&)
- {
- assert(true);
- }
-}
-
-void test_set_value_updates_future_state()
-{
- boost::promise<int> pi;
- boost::unique_future<int> fi;
- fi=pi.get_future();
-
- pi.set_value(42);
-
- assert(fi.is_ready());
- assert(fi.has_value());
- assert(!fi.has_exception());
- assert(fi.get_state()==boost::future_state::ready);
-}
-
-void test_set_value_can_be_retrieved()
-{
- boost::promise<int> pi;
- boost::unique_future<int> fi;
- fi=pi.get_future();
-
- pi.set_value(42);
-
- int i=0;
- assert(i=fi.get());
- assert(i==42);
- assert(fi.is_ready());
- assert(fi.has_value());
- assert(!fi.has_exception());
- assert(fi.get_state()==boost::future_state::ready);
-}
-
-void test_set_value_can_be_moved()
-{
-// boost::promise<int> pi;
-// boost::unique_future<int> fi;
-// fi=pi.get_future();
-
-// pi.set_value(42);
-
-// int i=0;
-// assert(i=fi.get());
-// assert(i==42);
-// assert(fi.is_ready());
-// assert(fi.has_value());
-// assert(!fi.has_exception());
-// assert(fi.get_state()==boost::future_state::ready);
-}
-
-void test_future_from_packaged_task_is_waiting()
-{
- boost::packaged_task<int> pt(make_int);
- boost::unique_future<int> fi=pt.get_future();
- int i=0;
- assert(!fi.is_ready());
- assert(!fi.has_value());
- assert(!fi.has_exception());
- assert(fi.get_state()==boost::future_state::waiting);
- assert(i==0);
-}
-
-void test_invoking_a_packaged_task_populates_future()
-{
- boost::packaged_task<int> pt(make_int);
- boost::unique_future<int> fi=pt.get_future();
-
- pt();
-
- int i=0;
- assert(fi.is_ready());
- assert(fi.has_value());
- assert(!fi.has_exception());
- assert(fi.get_state()==boost::future_state::ready);
- assert(i=fi.get());
- assert(i==42);
-}
-
-void test_invoking_a_packaged_task_twice_throws()
-{
- boost::packaged_task<int> pt(make_int);
-
- pt();
- try
- {
- pt();
- assert(false);
- }
- catch(boost::task_already_started)
- {
- assert(true);
- }
-}
-
-
-void test_cannot_get_future_twice_from_task()
-{
- boost::packaged_task<int> pt(make_int);
- pt.get_future();
- try
- {
- pt.get_future();
- assert(false);
- }
- catch(boost::future_already_retrieved)
- {
- assert(true);
- }
-}
-
-void test_task_stores_exception_if_function_throws()
-{
- boost::packaged_task<int> pt(throw_runtime_error);
- boost::unique_future<int> fi=pt.get_future();
-
- pt();
-
- int i=0;
- assert(fi.is_ready());
- assert(!fi.has_value());
- assert(fi.has_exception());
- assert(fi.get_state()==boost::future_state::ready);
- try
- {
- fi.get();
- assert(false);
- }
- catch(std::exception&)
- {
- assert(true);
- }
- catch(...)
- {
- assert(!"Unknown exception thrown");
- }
-
-}
-
-void test_void_promise()
-{
- boost::promise<void> p;
- boost::unique_future<void> f=p.get_future();
- p.set_value();
- assert(f.is_ready());
- assert(f.has_value());
- assert(!f.has_exception());
- assert(f.get_state()==boost::future_state::ready);
- f.get();
-}
-
-void test_reference_promise()
-{
- boost::promise<int&> p;
- boost::unique_future<int&> f=p.get_future();
- int i=42;
- p.set_value(i);
- assert(f.is_ready());
- assert(f.has_value());
- assert(!f.has_exception());
- assert(f.get_state()==boost::future_state::ready);
- assert(&f.get()==&i);
-}
-
-void do_nothing()
-{}
-
-void test_task_returning_void()
-{
- boost::packaged_task<void> pt(do_nothing);
- boost::unique_future<void> fi=pt.get_future();
-
- pt();
-
- assert(fi.is_ready());
- assert(fi.has_value());
- assert(!fi.has_exception());
- assert(fi.get_state()==boost::future_state::ready);
-}
-
-int global_ref_target=0;
-
-int& return_ref()
-{
- return global_ref_target;
-}
-
-void test_task_returning_reference()
-{
- boost::packaged_task<int&> pt(return_ref);
- boost::unique_future<int&> fi=pt.get_future();
-
- pt();
-
- assert(fi.is_ready());
- assert(fi.has_value());
- assert(!fi.has_exception());
- assert(fi.get_state()==boost::future_state::ready);
- int& i=fi.get();
- assert(&i==&global_ref_target);
-}
-
-void test_shared_future()
-{
- boost::packaged_task<int> pt(make_int);
- boost::unique_future<int> fi=pt.get_future();
-
- boost::shared_future<int> sf(boost::move(fi));
- assert(fi.get_state()==boost::future_state::uninitialized);
-
- pt();
-
- int i=0;
- assert(sf.is_ready());
- assert(sf.has_value());
- assert(!sf.has_exception());
- assert(sf.get_state()==boost::future_state::ready);
- assert(i=sf.get());
- assert(i==42);
-}
-
-void test_copies_of_shared_future_become_ready_together()
-{
- boost::packaged_task<int> pt(make_int);
- boost::unique_future<int> fi=pt.get_future();
-
- boost::shared_future<int> sf(boost::move(fi));
- boost::shared_future<int> sf2(sf);
- boost::shared_future<int> sf3;
- sf3=sf;
- assert(sf.get_state()==boost::future_state::waiting);
- assert(sf2.get_state()==boost::future_state::waiting);
- assert(sf3.get_state()==boost::future_state::waiting);
-
- pt();
-
- int i=0;
- assert(sf.is_ready());
- assert(sf.has_value());
- assert(!sf.has_exception());
- assert(sf.get_state()==boost::future_state::ready);
- assert(i=sf.get());
- assert(i==42);
- i=0;
- assert(sf2.is_ready());
- assert(sf2.has_value());
- assert(!sf2.has_exception());
- assert(sf2.get_state()==boost::future_state::ready);
- assert(i=sf2.get());
- assert(i==42);
- i=0;
- assert(sf3.is_ready());
- assert(sf3.has_value());
- assert(!sf3.has_exception());
- assert(sf3.get_state()==boost::future_state::ready);
- assert(i=sf3.get());
- assert(i==42);
-}
-
-void test_shared_future_can_be_move_assigned_from_unique_future()
-{
- boost::packaged_task<int> pt(make_int);
- boost::unique_future<int> fi=pt.get_future();
-
- boost::shared_future<int> sf;
- sf=boost::move(fi);
- assert(fi.get_state()==boost::future_state::uninitialized);
-
- int i=0;
- assert(!sf.is_ready());
- assert(!sf.has_value());
- assert(!sf.has_exception());
- assert(sf.get_state()==boost::future_state::waiting);
-}
-
-void test_shared_future_void()
-{
- boost::packaged_task<void> pt(do_nothing);
- boost::unique_future<void> fi=pt.get_future();
-
- boost::shared_future<void> sf(boost::move(fi));
- assert(fi.get_state()==boost::future_state::uninitialized);
-
- pt();
-
- assert(sf.is_ready());
- assert(sf.has_value());
- assert(!sf.has_exception());
- assert(sf.get_state()==boost::future_state::ready);
- sf.get();
-}
-
-void test_shared_future_ref()
-{
- boost::promise<int&> p;
- boost::shared_future<int&> f(p.get_future());
- int i=42;
- p.set_value(i);
- assert(f.is_ready());
- assert(f.has_value());
- assert(!f.has_exception());
- assert(f.get_state()==boost::future_state::ready);
- assert(&f.get()==&i);
-}
-
-void test_can_get_a_second_future_from_a_moved_promise()
-{
- boost::promise<int> pi;
- boost::unique_future<int> fi=pi.get_future();
-
- boost::promise<int> pi2(boost::move(pi));
- boost::unique_future<int> fi2=pi.get_future();
-
- pi2.set_value(3);
- assert(fi.is_ready());
- assert(!fi2.is_ready());
- assert(fi.get()==3);
- pi.set_value(42);
- assert(fi2.is_ready());
- assert(fi2.get()==42);
-}
-
-void test_can_get_a_second_future_from_a_moved_void_promise()
-{
- boost::promise<void> pi;
- boost::unique_future<void> fi=pi.get_future();
-
- boost::promise<void> pi2(boost::move(pi));
- boost::unique_future<void> fi2=pi.get_future();
-
- pi2.set_value();
- assert(fi.is_ready());
- assert(!fi2.is_ready());
- pi.set_value();
- assert(fi2.is_ready());
-}
-
-void test_unique_future_for_move_only_udt()
-{
- boost::promise<X> pt;
- boost::unique_future<X> fi=pt.get_future();
-
- pt.set_value(X());
- X res(fi.get());
- assert(res.i==42);
-}
-
-void test_unique_future_for_string()
-{
- boost::promise<std::string> pt;
- boost::unique_future<std::string> fi=pt.get_future();
-
- pt.set_value(std::string("hello"));
- std::string res(fi.get());
- assert(res=="hello");
-
- boost::promise<std::string> pt2;
- fi=pt2.get_future();
-
- std::string const s="goodbye";
-
- pt2.set_value(s);
- res=fi.get();
- assert(res=="goodbye");
-
- boost::promise<std::string> pt3;
- fi=pt3.get_future();
-
- std::string s2="foo";
-
- pt3.set_value(s2);
- res=fi.get();
- assert(res=="foo");
-}
-
-boost::mutex callback_mutex;
-unsigned callback_called=0;
-
-void wait_callback(boost::promise<int>& pi)
-{
- boost::lock_guard<boost::mutex> lk(callback_mutex);
- ++callback_called;
- try
- {
- pi.set_value(42);
- }
- catch(...)
- {
- }
-}
-
-void do_nothing_callback(boost::promise<int>& pi)
-{
- boost::lock_guard<boost::mutex> lk(callback_mutex);
- ++callback_called;
-}
-
-void test_wait_callback()
-{
- callback_called=0;
- boost::promise<int> pi;
- boost::unique_future<int> fi=pi.get_future();
- pi.set_wait_callback(wait_callback);
- fi.wait();
- assert(callback_called);
- assert(fi.get()==42);
- fi.wait();
- fi.wait();
- assert(callback_called==1);
-}
-
-void test_wait_callback_with_timed_wait()
-{
- callback_called=0;
- boost::promise<int> pi;
- boost::unique_future<int> fi=pi.get_future();
- pi.set_wait_callback(do_nothing_callback);
- bool success=fi.timed_wait(boost::posix_time::milliseconds(10));
- assert(callback_called);
- assert(!success);
- success=fi.timed_wait(boost::posix_time::milliseconds(10));
- assert(!success);
- success=fi.timed_wait(boost::posix_time::milliseconds(10));
- assert(!success);
- assert(callback_called==3);
- pi.set_value(42);
- success=fi.timed_wait(boost::posix_time::milliseconds(10));
- assert(success);
- assert(callback_called==3);
- assert(fi.get()==42);
- assert(callback_called==3);
-}
-
-void test_wait_callback_with_timed_wait_until()
-{
- callback_called=0;
- boost::promise<int> pi;
- boost::unique_future<int> fi=pi.get_future();
- pi.set_wait_callback(do_nothing_callback);
- bool success=fi.timed_wait_until(boost::get_system_time() + boost::posix_time::milliseconds(10));
- assert(callback_called);
- assert(!success);
- success=fi.timed_wait_until(boost::get_system_time() + boost::posix_time::milliseconds(10));
- assert(!success);
- success=fi.timed_wait_until(boost::get_system_time() + boost::posix_time::milliseconds(10));
- assert(!success);
- assert(callback_called==3);
- pi.set_value(42);
- success=fi.timed_wait_until(boost::get_system_time() + boost::posix_time::milliseconds(10));
- assert(success);
- assert(callback_called==3);
- assert(fi.get()==42);
- assert(callback_called==3);
-}
-
-
-void wait_callback_for_task(boost::packaged_task<int>& pt)
-{
- boost::lock_guard<boost::mutex> lk(callback_mutex);
- ++callback_called;
- try
- {
- pt();
- }
- catch(...)
- {
- }
-}
-
-
-void test_wait_callback_for_packaged_task()
-{
- callback_called=0;
- boost::packaged_task<int> pt(make_int);
- boost::unique_future<int> fi=pt.get_future();
- pt.set_wait_callback(wait_callback_for_task);
- fi.wait();
- assert(callback_called);
- assert(fi.get()==42);
- fi.wait();
- fi.wait();
- assert(callback_called==1);
-}
-
-void test_packaged_task_can_be_moved()
-{
- boost::packaged_task<int> pt(make_int);
-
- boost::unique_future<int> fi=pt.get_future();
-
- assert(!fi.is_ready());
-
- boost::packaged_task<int> pt2=boost::move(pt);
- assert(!fi.is_ready());
- try
- {
- pt();
- assert(!"Can invoke moved task!");
- }
- catch(boost::task_moved&)
- {
- }
-
- assert(!fi.is_ready());
-
- pt2();
-
- assert(fi.is_ready());
-}
-
-void test_destroying_a_promise_stores_broken_promise()
-{
- boost::unique_future<int> f;
-
- {
- boost::promise<int> p;
- f=p.get_future();
- }
- assert(f.is_ready());
- assert(f.has_exception());
- try
- {
- f.get();
- }
- catch(boost::broken_promise&)
- {
- }
-}
-
-void test_destroying_a_packaged_task_stores_broken_promise()
-{
- boost::unique_future<int> f;
-
- {
- boost::packaged_task<int> p(make_int);
- f=p.get_future();
- }
- assert(f.is_ready());
- assert(f.has_exception());
- try
- {
- f.get();
- }
- catch(boost::broken_promise&)
- {
- }
-}
-
-int make_int_slowly()
-{
- boost::this_thread::sleep(boost::posix_time::seconds(1));
- return 42;
-}
-
-int main()
-{
- test_initial_state();
- test_waiting_future();
- test_cannot_get_future_twice();
- test_set_value_updates_future_state();
- test_set_value_can_be_retrieved();
- test_set_value_can_be_moved();
- test_store_value_from_thread();
- test_store_exception();
- test_future_from_packaged_task_is_waiting();
- test_invoking_a_packaged_task_populates_future();
- test_invoking_a_packaged_task_twice_throws();
- test_cannot_get_future_twice_from_task();
- test_task_stores_exception_if_function_throws();
- test_void_promise();
- test_reference_promise();
- test_task_returning_void();
- test_task_returning_reference();
- test_shared_future();
- test_copies_of_shared_future_become_ready_together();
- test_shared_future_can_be_move_assigned_from_unique_future();
- test_shared_future_void();
- test_shared_future_ref();
- test_can_get_a_second_future_from_a_moved_promise();
- test_can_get_a_second_future_from_a_moved_void_promise();
- test_unique_future_for_move_only_udt();
- test_unique_future_for_string();
- test_wait_callback();
- test_wait_callback_with_timed_wait();
- test_wait_callback_with_timed_wait_until();
- test_wait_callback_for_packaged_task();
- test_packaged_task_can_be_moved();
- test_destroying_a_promise_stores_broken_promise();
- test_destroying_a_packaged_task_stores_broken_promise();
-}
Deleted: sandbox/task/libs/task/test/test_generic_locks.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_generic_locks.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,524 +0,0 @@
-// (C) Copyright 2008 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)
-
-#include <boost/thread.hpp>
-#include <boost/task.hpp>
-
-#include <boost/test/unit_test.hpp>
-
-namespace tsk = boost::task;
-
-void test_lock_two_uncontended()
-{
- tsk::spin_mutex m1,m2;
-
- tsk::spin_mutex::scoped_lock l1(m1,boost::defer_lock),
- l2(m2,boost::defer_lock);
-
- BOOST_CHECK(!l1.owns_lock());
- BOOST_CHECK(!l2.owns_lock());
-
- boost::lock(l1,l2);
-
- BOOST_CHECK(l1.owns_lock());
- BOOST_CHECK(l2.owns_lock());
-}
-
-struct wait_data
-{
- tsk::spin_mutex m;
- bool flag;
- tsk::spin_condition cond;
-
- wait_data():
- flag(false)
- {}
-
- void wait()
- {
- tsk::spin_mutex::scoped_lock l(m);
- while(!flag)
- {
- cond.wait(l);
- }
- }
-
- template<typename Duration>
- bool timed_wait(Duration d)
- {
- boost::system_time const target=boost::get_system_time()+d;
-
- tsk::spin_mutex::scoped_lock l(m);
- while(!flag)
- {
- if(!cond.timed_wait(l,target))
- {
- return flag;
- }
- }
- return true;
- }
-
- void signal()
- {
- tsk::spin_mutex::scoped_lock l(m);
- flag=true;
- cond.notify_all();
- }
-};
-
-
-void lock_mutexes_slowly(tsk::spin_mutex* m1,tsk::spin_mutex* m2,wait_data* locked,wait_data* quit)
-{
- boost::lock_guard<tsk::spin_mutex> l1(*m1);
- boost::this_thread::sleep(boost::posix_time::milliseconds(500));
- boost::lock_guard<tsk::spin_mutex> l2(*m2);
- locked->signal();
- quit->wait();
-}
-
-void lock_pair(tsk::spin_mutex* m1,tsk::spin_mutex* m2)
-{
- boost::lock(*m1,*m2);
- tsk::spin_mutex::scoped_lock l1(*m1,boost::adopt_lock),
- l2(*m2,boost::adopt_lock);
-}
-
-void test_lock_two_other_thread_locks_in_order()
-{
- tsk::spin_mutex m1,m2;
- wait_data locked;
- wait_data release;
-
- boost::thread t(lock_mutexes_slowly,&m1,&m2,&locked,&release);
- boost::this_thread::sleep(boost::posix_time::milliseconds(10));
-
- boost::thread t2(lock_pair,&m1,&m2);
- BOOST_CHECK(locked.timed_wait(boost::posix_time::seconds(1)));
-
- release.signal();
-
- BOOST_CHECK(t2.timed_join(boost::posix_time::seconds(1)));
-
- t.join();
-}
-
-void test_lock_two_other_thread_locks_in_opposite_order()
-{
- tsk::spin_mutex m1,m2;
- wait_data locked;
- wait_data release;
-
- boost::thread t(lock_mutexes_slowly,&m1,&m2,&locked,&release);
- boost::this_thread::sleep(boost::posix_time::milliseconds(10));
-
- boost::thread t2(lock_pair,&m2,&m1);
- BOOST_CHECK(locked.timed_wait(boost::posix_time::seconds(1)));
-
- release.signal();
-
- BOOST_CHECK(t2.timed_join(boost::posix_time::seconds(1)));
-
- t.join();
-}
-
-void test_lock_five_uncontended()
-{
- tsk::spin_mutex m1,m2,m3,m4,m5;
-
- tsk::spin_mutex::scoped_lock l1(m1,boost::defer_lock),
- l2(m2,boost::defer_lock),
- l3(m3,boost::defer_lock),
- l4(m4,boost::defer_lock),
- l5(m5,boost::defer_lock);
-
- BOOST_CHECK(!l1.owns_lock());
- BOOST_CHECK(!l2.owns_lock());
- BOOST_CHECK(!l3.owns_lock());
- BOOST_CHECK(!l4.owns_lock());
- BOOST_CHECK(!l5.owns_lock());
-
- boost::lock(l1,l2,l3,l4,l5);
-
- BOOST_CHECK(l1.owns_lock());
- BOOST_CHECK(l2.owns_lock());
- BOOST_CHECK(l3.owns_lock());
- BOOST_CHECK(l4.owns_lock());
- BOOST_CHECK(l5.owns_lock());
-}
-
-void lock_five_mutexes_slowly(tsk::spin_mutex* m1,tsk::spin_mutex* m2,tsk::spin_mutex* m3,tsk::spin_mutex* m4,tsk::spin_mutex* m5,
- wait_data* locked,wait_data* quit)
-{
- boost::lock_guard<tsk::spin_mutex> l1(*m1);
- boost::this_thread::sleep(boost::posix_time::milliseconds(500));
- boost::lock_guard<tsk::spin_mutex> l2(*m2);
- boost::this_thread::sleep(boost::posix_time::milliseconds(500));
- boost::lock_guard<tsk::spin_mutex> l3(*m3);
- boost::this_thread::sleep(boost::posix_time::milliseconds(500));
- boost::lock_guard<tsk::spin_mutex> l4(*m4);
- boost::this_thread::sleep(boost::posix_time::milliseconds(500));
- boost::lock_guard<tsk::spin_mutex> l5(*m5);
- locked->signal();
- quit->wait();
-}
-
-void lock_five(tsk::spin_mutex* m1,tsk::spin_mutex* m2,tsk::spin_mutex* m3,tsk::spin_mutex* m4,tsk::spin_mutex* m5)
-{
- boost::lock(*m1,*m2,*m3,*m4,*m5);
- m1->unlock();
- m2->unlock();
- m3->unlock();
- m4->unlock();
- m5->unlock();
-}
-
-void test_lock_five_other_thread_locks_in_order()
-{
- tsk::spin_mutex m1,m2,m3,m4,m5;
- wait_data locked;
- wait_data release;
-
- boost::thread t(lock_five_mutexes_slowly,&m1,&m2,&m3,&m4,&m5,&locked,&release);
- boost::this_thread::sleep(boost::posix_time::milliseconds(10));
-
- boost::thread t2(lock_five,&m1,&m2,&m3,&m4,&m5);
- BOOST_CHECK(locked.timed_wait(boost::posix_time::seconds(3)));
-
- release.signal();
-
- BOOST_CHECK(t2.timed_join(boost::posix_time::seconds(3)));
-
- t.join();
-}
-
-void test_lock_five_other_thread_locks_in_different_order()
-{
- tsk::spin_mutex m1,m2,m3,m4,m5;
- wait_data locked;
- wait_data release;
-
- boost::thread t(lock_five_mutexes_slowly,&m1,&m2,&m3,&m4,&m5,&locked,&release);
- boost::this_thread::sleep(boost::posix_time::milliseconds(10));
-
- boost::thread t2(lock_five,&m5,&m1,&m4,&m2,&m3);
- BOOST_CHECK(locked.timed_wait(boost::posix_time::seconds(3)));
-
- release.signal();
-
- BOOST_CHECK(t2.timed_join(boost::posix_time::seconds(3)));
-
- t.join();
-}
-
-void lock_n(tsk::spin_mutex* mutexes,unsigned count)
-{
- boost::lock(mutexes,mutexes+count);
- for(unsigned i=0;i<count;++i)
- {
- mutexes[i].unlock();
- }
-}
-
-
-void test_lock_ten_other_thread_locks_in_different_order()
-{
- unsigned const num_mutexes=10;
-
- tsk::spin_mutex mutexes[num_mutexes];
- wait_data locked;
- wait_data release;
-
- boost::thread t(lock_five_mutexes_slowly,&mutexes[6],&mutexes[3],&mutexes[8],&mutexes[0],&mutexes[2],&locked,&release);
- boost::this_thread::sleep(boost::posix_time::milliseconds(10));
-
- boost::thread t2(lock_n,mutexes,num_mutexes);
- BOOST_CHECK(locked.timed_wait(boost::posix_time::seconds(3)));
-
- release.signal();
-
- BOOST_CHECK(t2.timed_join(boost::posix_time::seconds(3)));
-
- t.join();
-}
-
-struct dummy_mutex
-{
- bool is_locked;
-
- dummy_mutex():
- is_locked(false)
- {}
-
- void lock()
- {
- is_locked=true;
- }
-
- bool try_lock()
- {
- if(is_locked)
- {
- return false;
- }
- is_locked=true;
- return true;
- }
-
- void unlock()
- {
- is_locked=false;
- }
-};
-
-namespace boost
-{
- template<>
- struct is_mutex_type<dummy_mutex>
- {
- BOOST_STATIC_CONSTANT(bool, value = true);
- };
-}
-
-
-
-void test_lock_five_in_range()
-{
- unsigned const num_mutexes=5;
- dummy_mutex mutexes[num_mutexes];
-
- boost::lock(mutexes,mutexes+num_mutexes);
-
- for(unsigned i=0;i<num_mutexes;++i)
- {
- BOOST_CHECK(mutexes[i].is_locked);
- }
-}
-
-void test_lock_ten_in_range()
-{
- unsigned const num_mutexes=10;
- dummy_mutex mutexes[num_mutexes];
-
- boost::lock(mutexes,mutexes+num_mutexes);
-
- for(unsigned i=0;i<num_mutexes;++i)
- {
- BOOST_CHECK(mutexes[i].is_locked);
- }
-}
-
-void test_try_lock_two_uncontended()
-{
- dummy_mutex m1,m2;
-
- int const res=boost::try_lock(m1,m2);
-
- BOOST_CHECK(res==-1);
- BOOST_CHECK(m1.is_locked);
- BOOST_CHECK(m2.is_locked);
-}
-void test_try_lock_two_first_locked()
-{
- dummy_mutex m1,m2;
- m1.lock();
-
- boost::unique_lock<dummy_mutex> l1(m1,boost::defer_lock),
- l2(m2,boost::defer_lock);
-
- int const res=boost::try_lock(l1,l2);
-
- BOOST_CHECK(res==0);
- BOOST_CHECK(m1.is_locked);
- BOOST_CHECK(!m2.is_locked);
- BOOST_CHECK(!l1.owns_lock());
- BOOST_CHECK(!l2.owns_lock());
-}
-void test_try_lock_two_second_locked()
-{
- dummy_mutex m1,m2;
- m2.lock();
-
- boost::unique_lock<dummy_mutex> l1(m1,boost::defer_lock),
- l2(m2,boost::defer_lock);
-
- int const res=boost::try_lock(l1,l2);
-
- BOOST_CHECK(res==1);
- BOOST_CHECK(!m1.is_locked);
- BOOST_CHECK(m2.is_locked);
- BOOST_CHECK(!l1.owns_lock());
- BOOST_CHECK(!l2.owns_lock());
-}
-
-void test_try_lock_three()
-{
- int const num_mutexes=3;
-
- for(int i=-1;i<num_mutexes;++i)
- {
- dummy_mutex mutexes[num_mutexes];
-
- if(i>=0)
- {
- mutexes[i].lock();
- }
- boost::unique_lock<dummy_mutex> l1(mutexes[0],boost::defer_lock),
- l2(mutexes[1],boost::defer_lock),
- l3(mutexes[2],boost::defer_lock);
-
- int const res=boost::try_lock(l1,l2,l3);
-
- BOOST_CHECK(res==i);
- for(int j=0;j<num_mutexes;++j)
- {
- if((i==j) || (i==-1))
- {
- BOOST_CHECK(mutexes[j].is_locked);
- }
- else
- {
- BOOST_CHECK(!mutexes[j].is_locked);
- }
- }
- if(i==-1)
- {
- BOOST_CHECK(l1.owns_lock());
- BOOST_CHECK(l2.owns_lock());
- BOOST_CHECK(l3.owns_lock());
- }
- else
- {
- BOOST_CHECK(!l1.owns_lock());
- BOOST_CHECK(!l2.owns_lock());
- BOOST_CHECK(!l3.owns_lock());
- }
- }
-}
-
-void test_try_lock_four()
-{
- int const num_mutexes=4;
-
- for(int i=-1;i<num_mutexes;++i)
- {
- dummy_mutex mutexes[num_mutexes];
-
- if(i>=0)
- {
- mutexes[i].lock();
- }
- boost::unique_lock<dummy_mutex> l1(mutexes[0],boost::defer_lock),
- l2(mutexes[1],boost::defer_lock),
- l3(mutexes[2],boost::defer_lock),
- l4(mutexes[3],boost::defer_lock);
-
- int const res=boost::try_lock(l1,l2,l3,l4);
-
- BOOST_CHECK(res==i);
- for(int j=0;j<num_mutexes;++j)
- {
- if((i==j) || (i==-1))
- {
- BOOST_CHECK(mutexes[j].is_locked);
- }
- else
- {
- BOOST_CHECK(!mutexes[j].is_locked);
- }
- }
- if(i==-1)
- {
- BOOST_CHECK(l1.owns_lock());
- BOOST_CHECK(l2.owns_lock());
- BOOST_CHECK(l3.owns_lock());
- BOOST_CHECK(l4.owns_lock());
- }
- else
- {
- BOOST_CHECK(!l1.owns_lock());
- BOOST_CHECK(!l2.owns_lock());
- BOOST_CHECK(!l3.owns_lock());
- BOOST_CHECK(!l4.owns_lock());
- }
- }
-}
-
-void test_try_lock_five()
-{
- int const num_mutexes=5;
-
- for(int i=-1;i<num_mutexes;++i)
- {
- dummy_mutex mutexes[num_mutexes];
-
- if(i>=0)
- {
- mutexes[i].lock();
- }
- boost::unique_lock<dummy_mutex> l1(mutexes[0],boost::defer_lock),
- l2(mutexes[1],boost::defer_lock),
- l3(mutexes[2],boost::defer_lock),
- l4(mutexes[3],boost::defer_lock),
- l5(mutexes[4],boost::defer_lock);
-
- int const res=boost::try_lock(l1,l2,l3,l4,l5);
-
- BOOST_CHECK(res==i);
- for(int j=0;j<num_mutexes;++j)
- {
- if((i==j) || (i==-1))
- {
- BOOST_CHECK(mutexes[j].is_locked);
- }
- else
- {
- BOOST_CHECK(!mutexes[j].is_locked);
- }
- }
- if(i==-1)
- {
- BOOST_CHECK(l1.owns_lock());
- BOOST_CHECK(l2.owns_lock());
- BOOST_CHECK(l3.owns_lock());
- BOOST_CHECK(l4.owns_lock());
- BOOST_CHECK(l5.owns_lock());
- }
- else
- {
- BOOST_CHECK(!l1.owns_lock());
- BOOST_CHECK(!l2.owns_lock());
- BOOST_CHECK(!l3.owns_lock());
- BOOST_CHECK(!l4.owns_lock());
- BOOST_CHECK(!l5.owns_lock());
- }
- }
-}
-
-
-
-boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
-{
- boost::unit_test_framework::test_suite* test =
- BOOST_TEST_SUITE("Boost.Task: generic locks test suite");
-
- test->add(BOOST_TEST_CASE(&test_lock_two_uncontended));
- test->add(BOOST_TEST_CASE(&test_lock_two_other_thread_locks_in_order));
- test->add(BOOST_TEST_CASE(&test_lock_two_other_thread_locks_in_opposite_order));
- test->add(BOOST_TEST_CASE(&test_lock_five_uncontended));
- test->add(BOOST_TEST_CASE(&test_lock_five_other_thread_locks_in_order));
- test->add(BOOST_TEST_CASE(&test_lock_five_other_thread_locks_in_different_order));
- test->add(BOOST_TEST_CASE(&test_lock_five_in_range));
- test->add(BOOST_TEST_CASE(&test_lock_ten_in_range));
- test->add(BOOST_TEST_CASE(&test_lock_ten_other_thread_locks_in_different_order));
- test->add(BOOST_TEST_CASE(&test_try_lock_two_uncontended));
- test->add(BOOST_TEST_CASE(&test_try_lock_two_first_locked));
- test->add(BOOST_TEST_CASE(&test_try_lock_two_second_locked));
- test->add(BOOST_TEST_CASE(&test_try_lock_three));
- test->add(BOOST_TEST_CASE(&test_try_lock_four));
- test->add(BOOST_TEST_CASE(&test_try_lock_five));
-
- return test;
-}
Modified: sandbox/task/libs/task/test/test_new_thread.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_new_thread.cpp (original)
+++ sandbox/task/libs/task/test/test_new_thread.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -23,7 +23,7 @@
#include "test_functions.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
// check assignment
void test_case_1()
Modified: sandbox/task/libs/task/test/test_own_thread.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_own_thread.cpp (original)
+++ sandbox/task/libs/task/test/test_own_thread.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -23,7 +23,7 @@
#include "test_functions.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
// check assignment
void test_case_1()
Deleted: sandbox/task/libs/task/test/test_semaphore.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_semaphore.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,179 +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/cstdint.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/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::task;
-
-boost::uint32_t wait_fn( boost::uint32_t n, tsk::semaphore & sem)
-{
- sem.wait();
- return n;
-}
-
-// check wait in new thread
-void test_case_1()
-{
- boost::uint32_t n = 3;
- tsk::semaphore sem( 0);
-
- tsk::handle< boost::uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- tsk::new_thread() ) );
- tsk::handle< boost::uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- tsk::new_thread() ) );
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( ! h1.is_ready() );
- BOOST_CHECK( ! h2.is_ready() );
-
- sem.post();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() || h2.is_ready() );
- if ( h1.is_ready() )
- {
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK( ! h2.is_ready() );
-
- sem.post();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- }
- else
- {
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- BOOST_CHECK( ! h1.is_ready() );
-
- sem.post();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
-
- }
-}
-
-// check wait in pool
-void test_case_2()
-{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
-
- boost::uint32_t n = 3;
- tsk::semaphore sem( 0);
-
- tsk::handle< boost::uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- pool) );
- tsk::handle< boost::uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( ! h1.is_ready() );
- BOOST_CHECK( ! h2.is_ready() );
-
- sem.post();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() || h2.is_ready() );
- if ( h1.is_ready() )
- {
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK( ! h2.is_ready() );
-
- sem.post();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- }
- else
- {
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- BOOST_CHECK( ! h1.is_ready() );
-
- sem.post();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
-
- }
-}
-
-void test_case_3()
-{
- boost::uint32_t n = 3;
- tsk::semaphore sem( 2);
-
- tsk::handle< boost::uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- tsk::new_thread() ) );
- tsk::handle< boost::uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- tsk::new_thread() ) );
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK_EQUAL( h2.get(), n);
-}
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test =
- BOOST_TEST_SUITE("Boost.Task: semaphore 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) );
-
- return test;
-}
Modified: sandbox/task/libs/task/test/test_spin_auto_reset_event.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_auto_reset_event.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_auto_reset_event.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -22,7 +22,7 @@
#include <boost/task.hpp>
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
boost::uint32_t wait_fn( boost::uint32_t n, tsk::spin_auto_reset_event & ev)
{
Modified: sandbox/task/libs/task/test/test_spin_condition.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_condition.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_condition.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -13,22 +13,22 @@
#include <libs/task/test/util.ipp>
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
namespace pt = boost::posix_time;
struct condition_test_data
{
condition_test_data() : notified(0), awoken(0) { }
- tsk::spin_mutex mutex;
- tsk::spin_condition condition;
+ tsk::spin::mutex mutex;
+ tsk::spin::condition condition;
int notified;
int awoken;
};
void condition_test_thread(condition_test_data* data)
{
- tsk::spin_mutex::scoped_lock lock(data->mutex);
+ tsk::spin::mutex::scoped_lock lock(data->mutex);
BOOST_CHECK(lock ? true : false);
while (!(data->notified > 0))
data->condition.wait(lock);
@@ -51,7 +51,7 @@
void condition_test_waits(condition_test_data* data)
{
- tsk::spin_mutex::scoped_lock lock(data->mutex);
+ tsk::spin::mutex::scoped_lock lock(data->mutex);
BOOST_CHECK(lock ? true : false);
// Test wait.
@@ -105,7 +105,7 @@
boost::thread thread(bind(&condition_test_waits, &data));
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
BOOST_CHECK(lock ? true : false);
boost::this_thread::sleep(pt::seconds(1));
Modified: sandbox/task/libs/task/test/test_spin_condition_notify_all.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_condition_notify_all.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_condition_notify_all.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -14,7 +14,7 @@
#include "condition_test_common.hpp"
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
unsigned const number_of_test_threads=5;
@@ -32,7 +32,7 @@
}
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
data.flag=true;
data.cond_var.notify_all();
}
@@ -61,7 +61,7 @@
}
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
data.flag=true;
data.cond_var.notify_all();
}
@@ -90,7 +90,7 @@
}
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
data.flag=true;
data.cond_var.notify_all();
}
@@ -119,7 +119,7 @@
}
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
data.flag=true;
data.cond_var.notify_all();
}
@@ -148,7 +148,7 @@
}
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
data.flag=true;
data.cond_var.notify_all();
}
@@ -165,13 +165,13 @@
namespace
{
- tsk::spin_mutex multiple_wake_mutex;
- tsk::spin_condition multiple_wake_cond;
+ tsk::spin::mutex multiple_wake_mutex;
+ tsk::spin::condition multiple_wake_cond;
unsigned multiple_wake_count=0;
void wait_for_condvar_and_increase_count()
{
- tsk::spin_mutex::scoped_lock lk(multiple_wake_mutex);
+ tsk::spin::mutex::scoped_lock lk(multiple_wake_mutex);
multiple_wake_cond.wait(lk);
++multiple_wake_count;
}
@@ -194,7 +194,7 @@
boost::this_thread::sleep(boost::posix_time::milliseconds(200));
{
- tsk::spin_mutex::scoped_lock lk(multiple_wake_mutex);
+ tsk::spin::mutex::scoped_lock lk(multiple_wake_mutex);
BOOST_CHECK(multiple_wake_count==3);
}
Modified: sandbox/task/libs/task/test/test_spin_condition_notify_one.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_condition_notify_one.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_condition_notify_one.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -14,7 +14,7 @@
#include "condition_test_common.hpp"
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
void do_test_condition_notify_one_wakes_from_wait()
{
@@ -23,7 +23,7 @@
boost::thread thread(boost::bind(&wait_for_flag::wait_without_predicate, boost::ref(data)));
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
data.flag=true;
data.cond_var.notify_one();
}
@@ -39,7 +39,7 @@
boost::thread thread(boost::bind(&wait_for_flag::wait_with_predicate, boost::ref(data)));
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
data.flag=true;
data.cond_var.notify_one();
}
@@ -55,7 +55,7 @@
boost::thread thread(boost::bind(&wait_for_flag::timed_wait_without_predicate, boost::ref(data)));
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
data.flag=true;
data.cond_var.notify_one();
}
@@ -71,7 +71,7 @@
boost::thread thread(boost::bind(&wait_for_flag::timed_wait_with_predicate, boost::ref(data)));
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
data.flag=true;
data.cond_var.notify_one();
}
@@ -87,7 +87,7 @@
boost::thread thread(boost::bind(&wait_for_flag::relative_timed_wait_with_predicate, boost::ref( data)));
{
- tsk::spin_mutex::scoped_lock lock(data.mutex);
+ tsk::spin::mutex::scoped_lock lock(data.mutex);
data.flag=true;
data.cond_var.notify_one();
}
@@ -98,13 +98,13 @@
namespace
{
- tsk::spin_mutex multiple_wake_mutex;
- tsk::spin_condition multiple_wake_cond;
+ tsk::spin::mutex multiple_wake_mutex;
+ tsk::spin::condition multiple_wake_cond;
unsigned multiple_wake_count=0;
void wait_for_condvar_and_increase_count()
{
- tsk::spin_mutex::scoped_lock lk(multiple_wake_mutex);
+ tsk::spin::mutex::scoped_lock lk(multiple_wake_mutex);
multiple_wake_cond.wait(lk);
++multiple_wake_count;
}
@@ -128,7 +128,7 @@
boost::this_thread::sleep(boost::posix_time::milliseconds(200));
{
- tsk::spin_mutex::scoped_lock lk(multiple_wake_mutex);
+ tsk::spin::mutex::scoped_lock lk(multiple_wake_mutex);
BOOST_CHECK(multiple_wake_count==3);
}
Modified: sandbox/task/libs/task/test/test_spin_condition_timed_wait_times_out.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_condition_timed_wait_times_out.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_condition_timed_wait_times_out.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -11,7 +11,7 @@
#include <libs/task/test/util.ipp>
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
bool fake_predicate()
{
@@ -25,11 +25,11 @@
void do_test_timed_wait_times_out()
{
- tsk::spin_condition cond;
- tsk::spin_mutex m;
+ tsk::spin::condition cond;
+ tsk::spin::mutex m;
boost::posix_time::seconds const delay(timeout_seconds);
- tsk::spin_mutex::scoped_lock lock(m);
+ tsk::spin::mutex::scoped_lock lock(m);
boost::system_time const start=boost::get_system_time();
boost::system_time const timeout=start+delay;
@@ -41,11 +41,11 @@
void do_test_timed_wait_with_predicate_times_out()
{
- tsk::spin_condition cond;
- tsk::spin_mutex m;
+ tsk::spin::condition cond;
+ tsk::spin::mutex m;
boost::posix_time::seconds const delay(timeout_seconds);
- tsk::spin_mutex::scoped_lock lock(m);
+ tsk::spin::mutex::scoped_lock lock(m);
boost::system_time const start=boost::get_system_time();
boost::system_time const timeout=start+delay;
@@ -58,11 +58,11 @@
void do_test_relative_timed_wait_with_predicate_times_out()
{
- tsk::spin_condition cond;
- tsk::spin_mutex m;
+ tsk::spin::condition cond;
+ tsk::spin::mutex m;
boost::posix_time::seconds const delay(timeout_seconds);
- tsk::spin_mutex::scoped_lock lock(m);
+ tsk::spin::mutex::scoped_lock lock(m);
boost::system_time const start=boost::get_system_time();
bool const res=cond.timed_wait(lock,delay,fake_predicate);
@@ -74,11 +74,11 @@
void do_test_timed_wait_relative_times_out()
{
- tsk::spin_condition cond;
- tsk::spin_mutex m;
+ tsk::spin::condition cond;
+ tsk::spin::mutex m;
boost::posix_time::seconds const delay(timeout_seconds);
- tsk::spin_mutex::scoped_lock lock(m);
+ tsk::spin::mutex::scoped_lock lock(m);
boost::system_time const start=boost::get_system_time();
while(cond.timed_wait(lock,delay));
@@ -89,11 +89,11 @@
void do_test_cv_any_timed_wait_times_out()
{
- tsk::spin_condition cond;
- tsk::spin_mutex m;
+ tsk::spin::condition cond;
+ tsk::spin::mutex m;
boost::posix_time::seconds const delay(timeout_seconds);
- tsk::spin_mutex::scoped_lock lock(m);
+ tsk::spin::mutex::scoped_lock lock(m);
boost::system_time const start=boost::get_system_time();
boost::system_time const timeout=start+delay;
@@ -105,11 +105,11 @@
void do_test_cv_any_timed_wait_with_predicate_times_out()
{
- tsk::spin_condition cond;
- tsk::spin_mutex m;
+ tsk::spin::condition cond;
+ tsk::spin::mutex m;
boost::posix_time::seconds const delay(timeout_seconds);
- tsk::spin_mutex::scoped_lock lock(m);
+ tsk::spin::mutex::scoped_lock lock(m);
boost::system_time const start=boost::get_system_time();
boost::system_time const timeout=start+delay;
@@ -122,11 +122,11 @@
void do_test_cv_any_relative_timed_wait_with_predicate_times_out()
{
- tsk::spin_condition cond;
- tsk::spin_mutex m;
+ tsk::spin::condition cond;
+ tsk::spin::mutex m;
boost::posix_time::seconds const delay(timeout_seconds);
- tsk::spin_mutex::scoped_lock lock(m);
+ tsk::spin::mutex::scoped_lock lock(m);
boost::system_time const start=boost::get_system_time();
bool const res=cond.timed_wait(lock,delay,fake_predicate);
@@ -138,11 +138,11 @@
void do_test_cv_any_timed_wait_relative_times_out()
{
- tsk::spin_condition cond;
- tsk::spin_mutex m;
+ tsk::spin::condition cond;
+ tsk::spin::mutex m;
boost::posix_time::seconds const delay(timeout_seconds);
- tsk::spin_mutex::scoped_lock lock(m);
+ tsk::spin::mutex::scoped_lock lock(m);
boost::system_time const start=boost::get_system_time();
while(cond.timed_wait(lock,delay));
Modified: sandbox/task/libs/task/test/test_spin_count_down_event.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_count_down_event.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_count_down_event.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -22,7 +22,7 @@
#include <boost/task.hpp>
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
boost::uint32_t wait_fn( boost::uint32_t n, tsk::spin_count_down_event & ev)
{
Modified: sandbox/task/libs/task/test/test_spin_manual_reset_event.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_manual_reset_event.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_manual_reset_event.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -22,7 +22,7 @@
#include <boost/task.hpp>
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
boost::uint32_t wait_fn( boost::uint32_t n, tsk::spin_manual_reset_event & ev)
{
Modified: sandbox/task/libs/task/test/test_spin_mutex.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_mutex.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_mutex.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -25,7 +25,7 @@
#include <libs/task/test/util.ipp>
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
template< typename M >
struct test_lock
@@ -36,7 +36,7 @@
void operator()()
{
mutex_type mutex;
- tsk::spin_condition condition;
+ tsk::spin::condition condition;
// Test the lock's constructors.
{
@@ -65,7 +65,7 @@
void do_test_mutex()
{
- test_lock< tsk::spin_mutex >()();
+ test_lock< tsk::spin::mutex >()();
}
void test_mutex()
Deleted: sandbox/task/libs/task/test/test_spin_unique_lock.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_unique_lock.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
+++ (empty file)
@@ -1,205 +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)
-//
-// This test is based on the tests of Boost.Thread
-
-#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/utility.hpp>
-
-#include <boost/task.hpp>
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::task;
-
-struct dummy_mutex
-{
- bool is_locked;
-
- dummy_mutex() :
- is_locked( false)
- {}
-
- void lock()
- { is_locked = true; }
-
- bool try_lock()
- {
- if ( is_locked)
- return false;
- is_locked = true;
- return true;
- }
-
- void unlock()
- { is_locked = false; }
-};
-
-void test_lock()
-{
- tsk::spin_mutex mtx;
- tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx);
-
- BOOST_CHECK( lk);
- BOOST_CHECK( lk.owns_lock() );
-
- lk.unlock();
-
- BOOST_CHECK( ! lk);
- BOOST_CHECK( ! lk.owns_lock() );
-}
-
-void test_defer_lock()
-{
- tsk::spin_mutex mtx;
- tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx, boost::defer_lock);
-
- BOOST_CHECK( ! lk);
- BOOST_CHECK( ! lk.owns_lock() );
-
- lk.lock();
-
- BOOST_CHECK( lk);
- BOOST_CHECK( lk.owns_lock() );
-}
-
-void test_adopt_lock()
-{
- tsk::spin_mutex mtx;
- mtx.lock();
- tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx, boost::adopt_lock);
-
- BOOST_CHECK( lk);
- BOOST_CHECK( lk.owns_lock() );
-}
-
-void test_try_lock()
-{
- tsk::spin_mutex mtx;
- tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx, boost::defer_lock);
-
- BOOST_CHECK( ! lk);
- BOOST_CHECK( ! lk.owns_lock() );
-
- lk.try_lock();
-
- BOOST_CHECK( lk);
- BOOST_CHECK( lk.owns_lock() );
-}
-
-void test_lock_twice()
-{
- tsk::spin_mutex mtx;
- tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx);
-
- BOOST_CHECK_THROW( lk.lock(), tsk::lock_error);
-}
-
-void test_try_lock_twice()
-{
- tsk::spin_mutex mtx;
- tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx);
-
- BOOST_CHECK_THROW( lk.try_lock(), tsk::lock_error);
-}
-
-void test_unlock_twice()
-{
- tsk::spin_mutex mtx;
- tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx);
- lk.unlock();
-
- BOOST_CHECK_THROW( lk.unlock(), tsk::lock_error);
-}
-
-void test_default_ctor()
-{
- tsk::spin_unique_lock< tsk::spin_mutex > lk;
-
- BOOST_CHECK( ! lk);
- BOOST_CHECK( ! lk.owns_lock() );
-}
-
-void test_lock_concept()
-{
- tsk::spin_mutex mtx1, mtx2, mtx3;
-
- tsk::spin_mutex::scoped_lock lk1( mtx1, boost::defer_lock),
- lk2( mtx2, boost::defer_lock),
- lk3( mtx3, boost::defer_lock);
-
- BOOST_CHECK( ! lk1.owns_lock() );
- BOOST_CHECK( ! lk2.owns_lock() );
- BOOST_CHECK( ! lk3.owns_lock() );
-
- boost::lock( lk1, lk2, lk3);
-
- BOOST_CHECK( lk1.owns_lock() );
- BOOST_CHECK( lk2.owns_lock() );
- BOOST_CHECK( lk3.owns_lock() );
-}
-
-void test_try_lock_concept()
-{
- dummy_mutex mtx1, mtx2;
- mtx2.lock();
-
- tsk::spin_unique_lock< dummy_mutex > lk1( mtx1, boost::defer_lock),
- lk2( mtx2, boost::defer_lock);
-
- int res = boost::try_lock( lk1, lk2);
-
- BOOST_CHECK( res == 1);
- BOOST_CHECK( ! mtx1.is_locked);
- BOOST_CHECK( mtx2.is_locked);
- BOOST_CHECK( ! lk1.owns_lock() );
- BOOST_CHECK( ! lk2.owns_lock() );
-}
-
-void test_swap()
-{
- tsk::spin_mutex mtx1, mtx2;
-
- tsk::spin_unique_lock< tsk::spin_mutex > lk1( mtx1), lk2( mtx2);
-
- BOOST_CHECK_EQUAL( lk1.mutex(), & mtx1);
- BOOST_CHECK_EQUAL( lk2.mutex(), & mtx2);
-
- lk1.swap( lk2);
-
- BOOST_CHECK_EQUAL( lk1.mutex(), & mtx2);
- BOOST_CHECK_EQUAL( lk2.mutex(), & mtx1);
-}
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test_framework::test_suite * test =
- BOOST_TEST_SUITE("Boost.Task: spin-lock test suite");
-
- test->add( BOOST_TEST_CASE( & test_lock) );
- test->add( BOOST_TEST_CASE( & test_defer_lock) );
- test->add( BOOST_TEST_CASE( & test_adopt_lock) );
- test->add( BOOST_TEST_CASE( & test_try_lock) );
- test->add( BOOST_TEST_CASE( & test_lock_twice) );
- test->add( BOOST_TEST_CASE( & test_try_lock_twice) );
- test->add( BOOST_TEST_CASE( & test_unlock_twice) );
- test->add( BOOST_TEST_CASE( & test_default_ctor) );
- test->add( BOOST_TEST_CASE( & test_lock_concept) );
- test->add( BOOST_TEST_CASE( & test_try_lock_concept) );
- test->add( BOOST_TEST_CASE( & test_swap) );
-
- return test;
-}
Modified: sandbox/task/libs/task/test/test_task.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_task.cpp (original)
+++ sandbox/task/libs/task/test/test_task.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -23,7 +23,7 @@
#include "test_functions.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
void zero_args_fn() {}
int one_arg_fn( int i) { return i; }
Modified: sandbox/task/libs/task/test/test_unbounded_buffer.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_unbounded_buffer.cpp (original)
+++ sandbox/task/libs/task/test/test_unbounded_buffer.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -22,7 +22,7 @@
#include <boost/task.hpp>
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
struct send_data
{
Modified: sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -25,7 +25,7 @@
#include "test_functions.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
// check size and move op
void test_case_1()
Modified: sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp 2009-12-26 17:00:51 EST (Sat, 26 Dec 2009)
@@ -25,7 +25,7 @@
#include "test_functions.hpp"
namespace pt = boost::posix_time;
-namespace tsk = boost::task;
+namespace tsk = boost::tasks;
// check size and move op
void test_case_1()
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