提交 f47fefa2 编写于 作者: C codinghuang

complete the create coroutine

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