forked from luncliff/coroutine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_event_signal.cpp
38 lines (30 loc) · 805 Bytes
/
linux_event_signal.cpp
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
/**
* @author github.com/luncliff (luncliff@gmail.com)
*/
#include <array>
#include <coroutine/linux.h>
#include <coroutine/return.h>
using namespace std;
using namespace coro;
auto mark_after_resume(epoll_owner& ep, event& event, //
bool& resumed) -> frame_t {
co_await wait_in(ep, event);
resumed = true;
}
int main(int, char*[]) {
epoll_owner ep{};
event e1{};
bool resumed = false;
mark_after_resume(ep, e1, resumed);
e1.set();
array<epoll_event, 1> events{};
auto count = ep.wait(1000, events);
if (count == 0)
return __LINE__;
auto coro = coroutine_handle<void>::from_address(events[0].data.ptr);
coro.resume();
if (resumed == false)
return __LINE__;
coro.destroy();
return EXIT_SUCCESS;
}