28 lines
728 B
C++
28 lines
728 B
C++
|
#pragma once
|
|||
|
#include "coctx.h"
|
|||
|
#include <functional>
|
|||
|
namespace tinyrpc {
|
|||
|
|
|||
|
|
|||
|
class Coroutine {
|
|||
|
private:
|
|||
|
Coroutine();
|
|||
|
public:
|
|||
|
Coroutine(std::size_t stack_size, void* stack_sp);
|
|||
|
Coroutine(std::size_t stack_size, void* stack_sp, std::function<void()> cb);
|
|||
|
|
|||
|
int getCorID() const {return m_cor_id;}
|
|||
|
|
|||
|
private:
|
|||
|
coctx m_ctx {}; // 这个协程的上下文信息
|
|||
|
int m_cor_id {0}; // 这个协程的 id
|
|||
|
char* m_stack_sp {nullptr}; // 这个协程的栈空间指针
|
|||
|
std::size_t m_stack_size {0};
|
|||
|
bool m_is_in_cofunc {true}; // 调用 CoFunction 时为真,CoFunction 完成时为假。
|
|||
|
std::function<void()> m_callback {};
|
|||
|
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
}
|