Add JobCoro destructor completion assert

Make JobCoro non copyable
This commit is contained in:
Miguel Portilla
2016-02-25 17:55:19 -05:00
committed by Vinnie Falco
parent 2323ea4493
commit 172356d299
2 changed files with 19 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ struct JobCoro_create_t { };
} // detail
/** Coroutines must run to completion. */
class JobCoro : public std::enable_shared_from_this<JobCoro>
{
private:
@@ -52,6 +53,9 @@ private:
std::condition_variable cv_;
boost::coroutines::asymmetric_coroutine<void>::pull_type coro_;
boost::coroutines::asymmetric_coroutine<void>::push_type* yield_;
#ifndef NDEBUG
bool finished_ = false;
#endif
public:
// Private: Used in the implementation
@@ -59,6 +63,12 @@ public:
JobCoro(detail::JobCoro_create_t, JobQueue&, JobType,
std::string const&, F&&);
// Not copy-constructible or assignable
JobCoro(JobCoro const&) = delete;
JobCoro& operator= (JobCoro const&) = delete;
~JobCoro();
/** Suspend coroutine execution.
Effects:
The coroutine's stack is saved.

View File

@@ -36,10 +36,19 @@ JobCoro::JobCoro(detail::JobCoro_create_t, JobQueue& jq, JobType type,
yield_ = &do_yield;
yield();
fn(shared_from_this());
#ifndef NDEBUG
finished_ = true;
#endif
}, boost::coroutines::attributes (1024 * 1024))
{
}
inline
JobCoro::~JobCoro()
{
assert(finished_);
}
inline
void
JobCoro::yield() const