From 570916ddc376b09205125eaaab517561dfead9f0 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:31:50 +0200 Subject: 6.3 --- zen/thread.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'zen/thread.h') diff --git a/zen/thread.h b/zen/thread.h index 5c6eecc5..95cdf074 100644 --- a/zen/thread.h +++ b/zen/thread.h @@ -4,8 +4,8 @@ // * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * // ************************************************************************** -#ifndef BOOST_THREAD_WRAP_H -#define BOOST_THREAD_WRAP_H +#ifndef BOOST_THREAD_WRAP_H_78963234 +#define BOOST_THREAD_WRAP_H_78963234 //temporary solution until C++11 thread becomes fully available (considering std::thread's non-interruptibility and std::async craziness, this may be NEVER) #include @@ -57,10 +57,10 @@ bool wait_for_all_timed(InputIterator first, InputIterator last, const Duration& //wait until first job is successful or all failed template -class RunUntilFirstHit +class GetFirstResult { public: - RunUntilFirstHit(); + GetFirstResult(); template void addJob(Fun f); //f must return a std::unique_ptr containing a value if successful @@ -118,7 +118,7 @@ bool wait_for_all_timed(InputIterator first, InputIterator last, const Duration& template -class RunUntilFirstHit::AsyncResult +class GetFirstResult::AsyncResult { public: AsyncResult() : @@ -164,6 +164,7 @@ public: private: bool jobDone(size_t jobsTotal) const { return result_ || (jobsFinished >= jobsTotal); } //call while locked! + #ifndef NDEBUG bool returnedResult; #endif @@ -177,14 +178,14 @@ private: template inline -RunUntilFirstHit::RunUntilFirstHit() : result(std::make_shared()), jobsTotal(0) {} +GetFirstResult::GetFirstResult() : result(std::make_shared()), jobsTotal(0) {} template template inline -void RunUntilFirstHit::addJob(Fun f) //f must return a std::unique_ptr containing a value on success +void GetFirstResult::addJob(Fun f) //f must return a std::unique_ptr containing a value on success { - auto result2 = result; //MSVC 2010: this is ridiculous!!! + auto result2 = result; //capture member variable, not "this"! boost::thread t([result2, f] { result2->reportFinished(f()); }); ++jobsTotal; t.detach(); //we have to be explicit since C++11: [thread.thread.destr] ~thread() calls std::terminate() if joinable()!!! @@ -193,11 +194,11 @@ void RunUntilFirstHit::addJob(Fun f) //f must return a std::unique_ptr con template template inline -bool RunUntilFirstHit::timedWait(const Duration& duration) const { return result->waitForResult(jobsTotal, duration); } +bool GetFirstResult::timedWait(const Duration& duration) const { return result->waitForResult(jobsTotal, duration); } template inline -std::unique_ptr RunUntilFirstHit::get() const { return result->getResult(jobsTotal); } +std::unique_ptr GetFirstResult::get() const { return result->getResult(jobsTotal); } } -#endif //BOOST_THREAD_WRAP_H +#endif //BOOST_THREAD_WRAP_H_78963234 -- cgit