tinyrpc/includes/coroutine/coroutine.hpp

28 lines
728 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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 {};
};
}