| 1 | /* @title: IO waiting primitives */ |
| 2 | #include <stdbool.h> |
| 3 | #include <structures/list.h> |
| 4 | #include <thread/thread_types.h> |
| 5 | |
| 6 | struct io_wait_token { |
| 7 | struct list_head list; |
| 8 | struct thread *owner; |
| 9 | void *wait_object; |
| 10 | bool active; |
| 11 | size_t magic; |
| 12 | }; |
| 13 | |
| 14 | enum io_wait_end_action { |
| 15 | IO_WAIT_END_YIELD, |
| 16 | IO_WAIT_END_NO_OP, |
| 17 | }; |
| 18 | |
| 19 | #define IO_WAIT_TOKEN_EMPTY \ |
| 20 | (struct io_wait_token){ \ |
| 21 | .owner = NULL, .wait_object = NULL, .active = false, .magic = 0} |
| 22 | |
| 23 | void io_wait_begin(struct io_wait_token *out, void *io_object); |
| 24 | void io_wait_end(struct io_wait_token *t, enum io_wait_end_action act); |
| 25 | static inline bool io_wait_token_active(struct io_wait_token *t) { |
| 26 | return t->active; |
| 27 | } |
| 28 | |