|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55287 - in sandbox/task: boost boost/task boost/task/detail libs/task/build libs/task/doc libs/task/src
From: oliver.kowalke_at_[hidden]
Date: 2009-07-30 14:45:29
Author: olli
Date: 2009-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
New Revision: 55287
URL: http://svn.boost.org/trac/boost/changeset/55287
Log:
* fiber
Added:
sandbox/task/boost/task/stacksize.hpp (contents, props changed)
sandbox/task/libs/task/src/stacksize.cpp (contents, props changed)
Text files modified:
sandbox/task/boost/task.hpp | 1
sandbox/task/boost/task/detail/pool_base.hpp | 35 ++++++++++++++++---------
sandbox/task/boost/task/detail/worker.hpp | 55 +++++++++++++++++++++++++++++++++++----
sandbox/task/boost/task/exceptions.hpp | 8 +++++
sandbox/task/boost/task/static_pool.hpp | 21 +++++++++-----
sandbox/task/libs/task/build/Jamfile.v2 | 2 +
sandbox/task/libs/task/doc/ref_utility.qbk | 17 +++++++++++
sandbox/task/libs/task/src/semaphore_posix.cpp | 13 ++++-----
sandbox/task/libs/task/src/semaphore_windows.cpp | 10 ++++--
9 files changed, 123 insertions(+), 39 deletions(-)
Modified: sandbox/task/boost/task.hpp
==============================================================================
--- sandbox/task/boost/task.hpp (original)
+++ sandbox/task/boost/task.hpp 2009-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -23,6 +23,7 @@
#include <boost/task/priority.hpp>
#include <boost/task/scanns.hpp>
#include <boost/task/semaphore.hpp>
+#include <boost/task/stacksize.hpp>
#include <boost/task/static_pool.hpp>
#include <boost/task/smart.hpp>
#include <boost/task/task.hpp>
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-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -29,6 +29,7 @@
#include <boost/task/handle.hpp>
#include <boost/task/poolsize.hpp>
#include <boost/task/scanns.hpp>
+#include <boost/task/stacksize.hpp>
#include <boost/task/task.hpp>
#include <boost/task/watermark.hpp>
@@ -71,7 +72,8 @@
void create_worker_(
poolsize const& psize,
posix_time::time_duration const& asleep,
- scanns const& max_scns)
+ scanns const& max_scns,
+ stacksize const& stack_size)
{
wg_.insert(
worker(
@@ -79,6 +81,7 @@
psize,
asleep,
max_scns,
+ stack_size,
boost::bind(
& pool_base::worker_entry_,
this) ) );
@@ -95,6 +98,7 @@
poolsize const& psize,
posix_time::time_duration const& asleep,
scanns const& max_scns,
+ stacksize const& stack_size,
std::size_t n)
{
wg_.insert(
@@ -103,6 +107,7 @@
psize,
asleep,
max_scns,
+ stack_size,
boost::bind(
& pool_base::worker_entry_,
this,
@@ -128,8 +133,9 @@
public:
explicit pool_base(
poolsize const& psize,
- posix_time::time_duration const& asleep = posix_time::microseconds( 10),
- scanns const& max_scns = scanns( 20) )
+ posix_time::time_duration const& asleep,
+ scanns const& max_scns,
+ stacksize const& stack_size)
:
wg_(),
mtx_wg_(),
@@ -143,15 +149,16 @@
channel_.activate();
lock_guard< shared_mutex > lk( mtx_wg_);
for ( std::size_t i( 0); i < psize; ++i)
- create_worker_( psize, asleep, max_scns);
+ create_worker_( psize, asleep, max_scns, stack_size);
}
explicit pool_base(
poolsize const& psize,
high_watermark const& hwm,
low_watermark const& lwm,
- posix_time::time_duration const& asleep = posix_time::microseconds( 100),
- scanns const& max_scns = scanns( 20) )
+ posix_time::time_duration const& asleep,
+ scanns const& max_scns,
+ stacksize const& stack_size)
:
wg_(),
mtx_wg_(),
@@ -167,13 +174,14 @@
channel_.activate();
lock_guard< shared_mutex > lk( mtx_wg_);
for ( std::size_t i( 0); i < psize; ++i)
- create_worker_( psize, asleep, max_scns);
+ create_worker_( psize, asleep, max_scns, stack_size);
}
# if defined(BOOST_HAS_PROCESSOR_BINDINGS)
explicit pool_base(
- posix_time::time_duration const& asleep = posix_time::microseconds( 10),
- scanns const& max_scns = scanns( 20) )
+ posix_time::time_duration const& asleep,
+ scanns const& max_scns,
+ stacksize const& stack_size)
:
wg_(),
mtx_wg_(),
@@ -189,14 +197,15 @@
channel_.activate();
lock_guard< shared_mutex > lk( mtx_wg_);
for ( std::size_t i( 0); i < psize; ++i)
- create_worker_( psize, asleep, max_scns, i);
+ create_worker_( psize, asleep, max_scns, stack_size, i);
}
explicit pool_base(
high_watermark const& hwm,
low_watermark const& lwm,
- posix_time::time_duration const& asleep = posix_time::microseconds( 100),
- scanns const& max_scns = scanns( 20) )
+ posix_time::time_duration const& asleep,
+ scanns const& max_scns,
+ stacksize const& stack_size)
:
wg_(),
mtx_wg_(),
@@ -214,7 +223,7 @@
channel_.activate();
lock_guard< shared_mutex > lk( mtx_wg_);
for ( std::size_t i( 0); i < psize; ++i)
- create_worker_( psize, asleep, max_scns, i);
+ create_worker_( psize, asleep, max_scns, stack_size, i);
}
# endif
Modified: sandbox/task/boost/task/detail/worker.hpp
==============================================================================
--- sandbox/task/boost/task/detail/worker.hpp (original)
+++ sandbox/task/boost/task/detail/worker.hpp 2009-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -8,6 +8,7 @@
#define BOOST_TASK_DETAIL_WORKER_H
#include <cstddef>
+#include <list>
#include <utility>
#include <boost/assert.hpp>
@@ -25,6 +26,7 @@
#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>
@@ -90,16 +92,22 @@
{ return die_(); }
};
+ typedef shared_ptr< fiber > fiber_t;
+ typedef shared_ptr< thread > thread_t;
+
Pool & pool_;
- shared_ptr< thread > thrd_;
- shared_ptr< fiber > fib_;
- wsq wsq_;
+ thread_t thrd_;
+ fiber_t fib_;
+ wsq wsq_;
+ std::list< fiber_t > blocked_fibers_;
+ std::list< fiber_t > runnable_fiber_lst;
semaphore shtdwn_sem_;
semaphore shtdwn_now_sem_;
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)
@@ -114,6 +122,11 @@
BOOST_ASSERT( ca.empty() );
}
+ void try_blocked_fibers_()
+ {
+ td::list< fiber_t >
+ }
+
bool take_global_callable_(
callable & ca,
posix_time::time_duration const& asleep)
@@ -144,6 +157,7 @@
callable ca;
while ( ! shutdown_() )
{
+ try_runnable_fibers_();
if ( try_take_local_callable_( ca) ||
try_take_global_callable_( ca) ||
try_steal_other_callable_( ca) )
@@ -203,18 +217,22 @@
poolsize const& psize,
posix_time::time_duration const& asleep,
scanns const& max_scns,
+ stacksize const& stack_size,
function< void() > const& fn)
:
pool_( pool),
thrd_( new thread( fn) ),
fib_(),
wsq_(),
+ blocked_fibers_(),
+ runnable_fiber_lst(),
shtdwn_sem_( 0),
shtdwn_now_sem_( 0),
shtdwn_( false),
asleep_( asleep),
max_scns_( max_scns),
scns_( 0),
+ stack_size_( stack_size),
rnd_idx_( psize)
{ BOOST_ASSERT( ! fn.empty() ); }
@@ -251,12 +269,13 @@
BOOST_ASSERT( get_id() == this_thread::get_id() );
fiber::convert_thread_to_fiber();
- shared_ptr< fiber > fib(
+
+ fiber_t fib(
new fiber(
bind(
& worker_object::run_,
this),
- 64000) );
+ stack_size_) );
fib_.swap( fib);
fib_->run();
BOOST_ASSERT( fib_->exited() );
@@ -290,7 +309,29 @@
}
bool block()
- { return ! shutdown_(); }
+ {
+ blocked_fibers_.push_back( fib_);
+ fiber_t fib;
+ if ( runnable_fibers_.empty() )
+ {
+ fib.reset(
+ new fiber(
+ bind(
+ & worker_object::run_,
+ this),
+ stack_size_) );
+ }
+ else
+ {
+ fib = runnable_fibers_.front();
+ runnable_fibers_.pop_front();
+ }
+ fib_.swap( fib);
+ fib_->run();
+ runnable_fibers_.push_back( fib);
+
+ return ! shutdown_();
+ }
};
class BOOST_TASK_DECL worker
@@ -307,6 +348,7 @@
poolsize const& psize,
posix_time::time_duration const& asleep,
scanns const& max_scns,
+ stacksize const& stack_size,
function< void() > const& fn)
:
impl_(
@@ -315,6 +357,7 @@
psize,
asleep,
max_scns,
+ stack_size,
fn) )
{}
Modified: sandbox/task/boost/task/exceptions.hpp
==============================================================================
--- sandbox/task/boost/task/exceptions.hpp (original)
+++ sandbox/task/boost/task/exceptions.hpp 2009-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -30,6 +30,14 @@
{}
};
+class invalid_stacksize : public std::invalid_argument
+{
+public:
+ invalid_stacksize()
+ : std::invalid_argument("stacksize must be greater than zero")
+ {}
+};
+
class invalid_timeduration : public std::invalid_argument
{
public:
Added: sandbox/task/boost/task/stacksize.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/stacksize.hpp 2009-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -0,0 +1,41 @@
+
+// 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_STACKSIZE_H
+#define BOOST_TASK_STACKSIZE_H
+
+#include <cstddef>
+
+#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 stacksize
+{
+private:
+ std::size_t value_;
+
+public:
+ explicit stacksize( std::size_t value);
+
+ operator std::size_t () const;
+};
+} }
+
+# if defined(BOOST_MSVC)
+# pragma warning(pop)
+# endif
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif // BOOST_TASK_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-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -21,6 +21,7 @@
#include <boost/task/handle.hpp>
#include <boost/task/poolsize.hpp>
#include <boost/task/scanns.hpp>
+#include <boost/task/stacksize.hpp>
#include <boost/task/task.hpp>
#include <boost/task/watermark.hpp>
@@ -55,8 +56,9 @@
explicit static_pool(
poolsize const& psize,
posix_time::time_duration const& asleep = posix_time::microseconds( 10),
- scanns const& max_scns = scanns( 20) )
- : pool_( new detail::pool_base< Channel >( psize, asleep, max_scns) )
+ scanns const& max_scns = scanns( 20),
+ stacksize const& stack_size = stacksize( 64000) )
+ : pool_( new detail::pool_base< Channel >( psize, asleep, max_scns, stack_size) )
{}
explicit static_pool(
@@ -64,16 +66,18 @@
high_watermark const& hwm,
low_watermark const& lwm,
posix_time::time_duration const& asleep = posix_time::microseconds( 100),
- scanns const& max_scns = scanns( 20) )
- : pool_( new detail::pool_base< Channel >( psize, hwm, lwm, asleep, max_scns) )
+ scanns const& max_scns = scanns( 20),
+ stacksize const& stack_size = stacksize( 64000) )
+ : pool_( new detail::pool_base< Channel >( psize, hwm, lwm, asleep, max_scns, stack_size) )
{}
# if defined(BOOST_HAS_PROCESSOR_BINDINGS)
explicit static_pool(
tag_bind_to_processors,
posix_time::time_duration const& asleep = posix_time::microseconds( 10),
- scanns const& max_scns = scanns( 20) )
- : pool_( new detail::pool_base< Channel >( asleep, max_scns) )
+ scanns const& max_scns = scanns( 20),
+ stacksize const& stack_size = stacksize( 64000) )
+ : pool_( new detail::pool_base< Channel >( asleep, max_scns, stack_size) )
{}
explicit static_pool(
@@ -81,8 +85,9 @@
high_watermark const& hwm,
low_watermark const& lwm,
posix_time::time_duration const& asleep = posix_time::microseconds( 100),
- scanns const& max_scns = scanns( 20) )
- : pool_( new detail::pool_base< Channel >( hwm, lwm, asleep, max_scns) )
+ scanns const& max_scns = scanns( 20),
+ stacksize const& stack_size = stacksize( 64000) )
+ : pool_( new detail::pool_base< Channel >( hwm, lwm, asleep, max_scns, stack_size) )
{}
static tag_bind_to_processors bind_to_processors()
Modified: sandbox/task/libs/task/build/Jamfile.v2
==============================================================================
--- sandbox/task/libs/task/build/Jamfile.v2 (original)
+++ sandbox/task/libs/task/build/Jamfile.v2 2009-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -41,6 +41,7 @@
poolsize.cpp
scanns.cpp
semaphore_windows.cpp
+ stacksize.cpp
watermark.cpp
worker.cpp
worker_group.cpp
@@ -57,6 +58,7 @@
poolsize.cpp
scanns.cpp
semaphore_posix.cpp
+ stacksize.cpp
watermark.cpp
worker.cpp
worker_group.cpp
Modified: sandbox/task/libs/task/doc/ref_utility.qbk
==============================================================================
--- sandbox/task/libs/task/doc/ref_utility.qbk (original)
+++ sandbox/task/libs/task/doc/ref_utility.qbk 2009-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -50,7 +50,22 @@
``
[variablelist
-[[Effects:] [returns returns the thread-id of the worker-thread]]
+[[Effects:] [returns the thread-id of the worker-thread]]
+[[Throws:] [nothing]]
+[[Note:] [this function resides in namespace `boost::this_task`]]
+]
+
+
+[section:worker_id Non-member function `block()`]
+
+``
+ #include <boost/task/utility.hpp>
+
+ bool block()
+``
+
+[variablelist
+[[Effects:] [blocks current context of execution and returns true if threadpool was shutdown]]
[[Throws:] [nothing]]
[[Note:] [this function resides in namespace `boost::this_task`]]
]
Modified: sandbox/task/libs/task/src/semaphore_posix.cpp
==============================================================================
--- sandbox/task/libs/task/src/semaphore_posix.cpp (original)
+++ sandbox/task/libs/task/src/semaphore_posix.cpp 2009-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -11,6 +11,7 @@
#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
@@ -39,13 +40,11 @@
int ret( -1);
if ( this_task::runs_in_pool() )
{
- // TODO: use semaphore::try_wait(), create a fiber and do a reschedule until
- // semaphore::try_wait() returns true
- do
- { ret = ::sem_wait( & handle_); }
- while ( ret == -1 && errno == EINTR);
- if ( ret == -1)
- throw system::system_error( errno, system::system_category);
+ while ( ! try_wait() )
+ {
+ if ( ! this_task::block() )
+ throw task_interrupted();
+ }
}
else
{
Modified: sandbox/task/libs/task/src/semaphore_windows.cpp
==============================================================================
--- sandbox/task/libs/task/src/semaphore_windows.cpp (original)
+++ sandbox/task/libs/task/src/semaphore_windows.cpp 2009-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -12,6 +12,7 @@
#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
@@ -39,10 +40,11 @@
{
if ( this_task::runs_in_pool() )
{
- // TODO: use semaphore::try_wait(), create a fiber and do a reschedule until
- // semaphore::try_wait() returns true
- if ( ::WaitForSingleObject( handle_, INFINITE) != WAIT_OBJECT_0)
- throw system::system_error( ::GetLastError(), system::system_category);
+ while ( ! try_wait() )
+ {
+ if ( ! this_task::block() )
+ throw task_interrupted();
+ }
}
else
{
Added: sandbox/task/libs/task/src/stacksize.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/src/stacksize.cpp 2009-07-30 12:10:30 EDT (Thu, 30 Jul 2009)
@@ -0,0 +1,21 @@
+
+// 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/stacksize.hpp"
+
+#include <boost/task/exceptions.hpp>
+
+namespace boost { namespace task
+{
+
+stacksize::stacksize( std::size_t value)
+: value_( value)
+{ if ( value <= 0) throw invalid_stacksize(); }
+
+stacksize::operator std::size_t () const
+{ return value_; }
+
+}}
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