acme
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages Concepts
task_keep.h
1// Created by camilo on 2022-06-09 14:31 BRT <3ThomasBorregaardSorensen!! and Mummi and bilbo!!
2#pragma once
3
4
5#include "acme/platform/keep.h"
6
7
8#define __keep_current_thread(...) auto COUNTER_TOKEN(__keep_current_thread) = keep(__VA_ARGS__, ::get_task())
9
10
11template < >
12inline ::task* default_keep_value < ::task* >()
13{
14
15 return ::get_task();
16
17}
18
19#define __task_guard_ret(flag, ret) \
20 \
21synchronous_lock synchronouslock(this->synchronization()); \
22 \
23if (flag) \
24{ \
25\
26 ret; \
27\
28} \
29\
30auto COUNTER_TOKEN(__task_guard_task_ret) = keep(flag); \
31\
32synchronouslock.unlock()
33
34#define __task_guard(flag) __task_guard_ret(flag, return)
35
36
37#define __guard_wait_ret(flag, ret) \
38 \
39synchronous_lock synchronouslock(this->synchronization()); \
40 \
41while (flag) \
42{ \
43\
44 \
45 synchronouslock.unlock(); \
46 \
47 if (!task_sleep(100_ms)) \
48 {\
49 \
50 ret; \
51 \
52 } \
53 \
54 synchronouslock.lock(); \
55 \
56 \
57} \
58\
59auto COUNTER_TOKEN(__guard_wait_ret) = keep(&flag); \
60\
61synchronouslock.unlock()
62
63#define __guard_wait(flag) __task_guard_ret(flag, return)
64
65