|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52527 - in sandbox/task: boost/task boost/task/detail libs/task/src
From: oliver.kowalke_at_[hidden]
Date: 2009-04-21 14:03:53
Author: olli
Date: 2009-04-21 14:03:50 EDT (Tue, 21 Apr 2009)
New Revision: 52527
URL: http://svn.boost.org/trac/boost/changeset/52527
Log:
* interrupter doesn't block in wait() forever if task is not executed
Text files modified:
sandbox/task/boost/task/detail/interrupter.hpp | 1 +
sandbox/task/boost/task/exceptions.hpp | 8 ++++++++
sandbox/task/boost/task/task.hpp | 6 ++++--
sandbox/task/libs/task/src/interrupter.cpp | 13 +++++++++----
4 files changed, 22 insertions(+), 6 deletions(-)
Modified: sandbox/task/boost/task/detail/interrupter.hpp
==============================================================================
--- sandbox/task/boost/task/detail/interrupter.hpp (original)
+++ sandbox/task/boost/task/detail/interrupter.hpp 2009-04-21 14:03:50 EDT (Tue, 21 Apr 2009)
@@ -30,6 +30,7 @@
{
private:
bool interruption_requested_;
+ bool done_;
condition_variable cond_;
mutex mtx_;
shared_ptr< thread > thrd_;
Modified: sandbox/task/boost/task/exceptions.hpp
==============================================================================
--- sandbox/task/boost/task/exceptions.hpp (original)
+++ sandbox/task/boost/task/exceptions.hpp 2009-04-21 14:03:50 EDT (Tue, 21 Apr 2009)
@@ -44,6 +44,14 @@
{}
};
+class task_already_executed : public std::logic_error
+{
+public:
+ task_already_executed()
+ : std::logic_error("task already executed")
+ {}
+};
+
class broken_task : public std::logic_error
{
public:
Modified: sandbox/task/boost/task/task.hpp
==============================================================================
--- sandbox/task/boost/task/task.hpp (original)
+++ sandbox/task/boost/task/task.hpp 2009-04-21 14:03:50 EDT (Tue, 21 Apr 2009)
@@ -54,7 +54,8 @@
intr()
{}
- virtual ~impl() {}
+ virtual ~impl()
+ { intr.reset(); }
virtual void operator()() = 0;
};
@@ -158,7 +159,8 @@
intr()
{}
- virtual ~impl() {}
+ virtual ~impl()
+ { intr.reset(); }
virtual void operator()() = 0;
};
Modified: sandbox/task/libs/task/src/interrupter.cpp
==============================================================================
--- sandbox/task/libs/task/src/interrupter.cpp (original)
+++ sandbox/task/libs/task/src/interrupter.cpp 2009-04-21 14:03:50 EDT (Tue, 21 Apr 2009)
@@ -15,7 +15,7 @@
void
interrupter::impl::interrupt_()
{
- if ( ! interruption_requested_)
+ if ( ! interruption_requested_ && ! done_)
{
interruption_requested_ = true;
if ( thrd_) thrd_->interrupt();
@@ -25,6 +25,7 @@
interrupter::impl::impl()
:
interruption_requested_( false),
+done_( false),
cond_(),
mtx_(),
thrd_()
@@ -37,7 +38,8 @@
unique_lock< mutex > lk( mtx_);
thrd_ = thrd;
BOOST_ASSERT( thrd_);
- if ( interruption_requested_) thrd_->interrupt();
+ if ( interruption_requested_)
+ thrd_->interrupt();
}
void
@@ -51,6 +53,7 @@
catch ( thread_interrupted const&)
{}
BOOST_ASSERT( ! this_thread::interruption_requested() );
+ done_ = true;
cond_.notify_all();
}
@@ -66,7 +69,8 @@
{
unique_lock< mutex > lk( mtx_);
interrupt_();
- cond_.wait( lk);
+ while ( ! done_)
+ cond_.wait( lk);
}
void
@@ -74,7 +78,8 @@
{
unique_lock< mutex > lk( mtx_);
interrupt_();
- cond_.timed_wait( lk, abs_time);
+ while ( ! done_)
+ cond_.timed_wait( lk, abs_time);
}
bool
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