-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
51 lines (42 loc) · 3.3 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
YurCO - Yurial's coroutines.
Little epoll-reactor based on libc coroutines.
class Stack // single stack for coroutine
{
Stack(size_t size, bool protect=true); // size - size of stack without size of stack protect-pages,
// protect - create two protect-pages (at begin and at end of stack area).
char* data() const noexcept; // address of begin stack area
size_t size() const noexcept; // size of stack area
};
class StackPool // pool of stacks
{
StackPool(const size_t stack_size, bool protect=true); // arguments passed to Stack() contructor
Stack pop(); // pop one Stack from pool or create new
void push(Stack&& stack); // push Stack to pool;
};
class Coroutine // single coroutine
{
template <class Func, class... Args, typename = typename std::enable_if<std::is_invocable_r_v<void, Func, Coroutine&, Args&...>>::type>
Coroutine(Stack&& stack, Func&& func, Args&&... args) noexcept; // create a new Coroutine
bool is_completed() const noexcept; // true when the coroutine is completely completed
bool is_running() const noexcept; // coroutine now in progress
void yield(); // switch to called thread
void operator() (); // switch to coroutine
void operator() (const std::nothrow_t&) noexcept; // --//--
void set_exception(const std::exception_ptr& e) noexcept; // set exception to send to or from coroutine
// exception raised at end of operator() or yield() call
const std::exception_ptr& get_exception() const noexcept; // inspect current exception
void rethrow(); // throw exception, if possible
Stack&& take_away_stack() noexcept; // take stack from coroutine.
// used to store stack in pool, before coroutine deleted.
};
class Reactor // epoll reactor
{
Reactor(const size_t stack_size, bool protect_stack=true) noexcept; // arguments passed to StackPool
void coroutine(Func&& func, Args&&... args) noexcept; // create new coroutine, arguments passed to Coroutine()
void run(const size_t batch_size=16, const size_t events_at_once=32*1024) noexcept; // run reactor, execute coroutines
void terminate() noexcept; // terminate coroutines and exit from run()
void suspend(Coroutine& coro, yurco::fd& fd, int events); // suspend coroutine while events on fd not occour
// this method useful for epoll-handled filr descriptors
void close(unistd::fd::native_type fd); // remove file descriptor from epoll and close
int close(unistd::fd::native_type fd, const std::nothrow_t&) noexcept; // --//--
};