coroutine.cc 603 字节
Newer Older
1 2
#include "coroutine.h"

C
update  
codinghuang 已提交
3
using Study::Coroutine;
4

C
codinghuang 已提交
5
Coroutine* Coroutine::current = nullptr;
C
codinghuang 已提交
6 7
long Coroutine::last_cid = 0;
std::unordered_map<long, Coroutine*> Coroutine::coroutines;
C
codinghuang 已提交
8
size_t Coroutine::stack_size = DEFAULT_C_STACK_SIZE;
C
codinghuang 已提交
9

10 11
void* Coroutine::get_current_task()
{
C
codinghuang 已提交
12
    return current ? current->get_task() : nullptr;
13 14 15 16 17
}

void* Coroutine::get_task()
{
    return task;
C
codinghuang 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
}

Coroutine* Coroutine::get_current()
{
    return current;
}

void Coroutine::set_task(void *_task)
{
    task = _task;
}

long Coroutine::create(coroutine_func_t fn, void* args)
{
    return (new Coroutine(fn, args))->run();
33
}