mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add JobCoro destructor completion assert
Make JobCoro non copyable
This commit is contained in:
committed by
Vinnie Falco
parent
2323ea4493
commit
172356d299
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user