提交 f47fefa2 编写于 作者: C codinghuang

complete the create coroutine

上级 167a891d
......@@ -5,7 +5,7 @@
typedef void* fcontext_t;
intptr_t jump_fcontext(fcontext_t *ofc, fcontext_t nfc, intptr_t vp, bool preserve_fpu = false);
fcontext_t make_fcontext(void *sp, size_t size, void (*fn)(intptr_t));
extern intptr_t jump_fcontext(fcontext_t *ofc, fcontext_t nfc, intptr_t vp, bool preserve_fpu = false) asm("jump_fcontext");
extern fcontext_t make_fcontext(void *sp, size_t size, void (*fn)(intptr_t)) asm("make_fcontext");
#endif /* ASM_CONTEXT_H */
\ No newline at end of file
......@@ -12,7 +12,6 @@ class Context
{
public:
Context(size_t stack_size, coroutine_func_t fn, void* private_data);
~Context();
bool swap_in();
bool swap_out();
static void context_func(void* arg); // coroutine entry function
......
......@@ -4,6 +4,8 @@
#include "context.h"
#include <unordered_map>
#define DEFAULT_C_STACK_SIZE (2 *1024 * 1024)
namespace Study
{
class Coroutine
......
#include "context.h"
#include "study.h"
using Study::Context;
using namespace Study;
Context::Context(size_t stack_size, coroutine_func_t fn, void* private_data) :
fn_(fn), stack_size_(stack_size), private_data_(private_data)
{
#ifdef SW_CONTEXT_PROTECT_STACK_PAGE
protect_page_ = 0;
#endif
end_ = false;
swap_ctx_ = nullptr;
......
......@@ -5,6 +5,7 @@ using Study::Coroutine;
Coroutine* Coroutine::current = nullptr;
long Coroutine::last_cid = 0;
std::unordered_map<long, Coroutine*> Coroutine::coroutines;
size_t Coroutine::stack_size = DEFAULT_C_STACK_SIZE;
void* Coroutine::get_current_task()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册