47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#ifdef USE_BOOST
|
|
#include <a8/awaiter.h>
|
|
#include <boost/coroutine2/all.hpp>
|
|
|
|
namespace f8
|
|
{
|
|
|
|
class Coroutine : public a8::Awaiter
|
|
{
|
|
public:
|
|
|
|
virtual ~Coroutine() override;
|
|
|
|
void CoSuspend();
|
|
void CoResume();
|
|
void CoYield();
|
|
std::shared_ptr<a8::Results> CoAwait(std::shared_ptr<a8::Awaiter> awaiter);
|
|
std::shared_ptr<a8::Awaiter> Sleep(long long time);
|
|
|
|
private:
|
|
Coroutine(std::function<void(Coroutine*)> cb);
|
|
|
|
bool Exec();
|
|
void Attach();
|
|
void Deatch();
|
|
void CallEnter(boost::coroutines2::coroutine<void>::push_type& sink);
|
|
void CallExit(boost::coroutines2::coroutine<void>::push_type& sink);
|
|
virtual void DoAwait() override {};
|
|
virtual void DoResume() override;
|
|
|
|
private:
|
|
list_head co_entry_;
|
|
list_head exec_entry_;
|
|
std::shared_ptr<Coroutine> hold_self_;
|
|
std::shared_ptr<boost::coroutines2::coroutine<void>::pull_type> source_;
|
|
std::function<void(Coroutine* co)> cb_;
|
|
boost::coroutines2::coroutine<void>::push_type* sink_ = nullptr;
|
|
|
|
friend class CoMgr;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|