From eb5d3e5df99de2c3d8da2e8bc7b12ed427465dba Mon Sep 17 00:00:00 2001 From: B Stack Date: Sun, 9 Sep 2018 18:53:23 -0400 Subject: pull in latest 10.4 from upstream --- zen/thread.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'zen/thread.h') diff --git a/zen/thread.h b/zen/thread.h index 5828d07a..7f3d216c 100755 --- a/zen/thread.h +++ b/zen/thread.h @@ -11,7 +11,6 @@ #include #include "scope_guard.h" #include "ring_buffer.h" -#include "optional.h" #include "string_tools.h" @@ -97,13 +96,13 @@ public: GetFirstResult(); template - void addJob(Fun&& f); //f must return a zen::Opt containing a value if successful + void addJob(Fun&& f); //f must return a std::optional containing a value if successful template bool timedWait(const Duration& duration) const; //true: "get()" is ready, false: time elapsed //return first value or none if all jobs failed; blocks until result is ready! - Opt get() const; //may be called only once! + std::optional get() const; //may be called only once! private: class AsyncResult; @@ -323,7 +322,7 @@ class GetFirstResult::AsyncResult { public: //context: worker threads - void reportFinished(Opt&& result) + void reportFinished(std::optional&& result) { { std::lock_guard dummy(lockResult_); @@ -342,7 +341,7 @@ public: return conditionJobDone_.wait_for(dummy, duration, [&] { return this->jobDone(jobsTotal); }); } - Opt getResult(size_t jobsTotal) + std::optional getResult(size_t jobsTotal) { std::unique_lock dummy(lockResult_); conditionJobDone_.wait(dummy, [&] { return this->jobDone(jobsTotal); }); @@ -355,7 +354,7 @@ private: std::mutex lockResult_; size_t jobsFinished_ = 0; // - Opt result_; //our condition is: "have result" or "jobsFinished_ == jobsTotal" + std::optional result_; //our condition is: "have result" or "jobsFinished_ == jobsTotal" std::condition_variable conditionJobDone_; }; @@ -367,7 +366,7 @@ GetFirstResult::GetFirstResult() : asyncResult_(std::make_shared template template inline -void GetFirstResult::addJob(Fun&& f) //f must return a zen::Opt containing a value on success +void GetFirstResult::addJob(Fun&& f) //f must return a std::optional containing a value on success { std::thread t([asyncResult = this->asyncResult_, f = std::forward(f)] { asyncResult->reportFinished(f()); }); ++jobsTotal_; @@ -381,7 +380,7 @@ bool GetFirstResult::timedWait(const Duration& duration) const { return async template inline -Opt GetFirstResult::get() const { return asyncResult_->getResult(jobsTotal_); } +std::optional GetFirstResult::get() const { return asyncResult_->getResult(jobsTotal_); } //------------------------------------------------------------------------------------------ -- cgit