acme
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages Concepts
keep.h
1// Created by camilo on 2022-06-09 12:34 BRT <3ThomasBorregaardSorensen!! Mummi and bilbo!!
2#pragma once
3
4
5template < typename TYPE >
6inline TYPE default_keep_value()
7{
8
9 return (TYPE) nullptr;
10
11}
12
13
14template < >
15inline bool default_keep_value < bool >()
16{
17
18 return true;
19
20}
21
22
23template < typename TYPE >
24class ___keep
25{
26public:
27
28
29 TYPE m_keepValue;
30 TYPE m_keepAwayValue;
31 TYPE* m_pKept;
32 bool m_bKept;
33
34
35 ___keep(___keep&& keep);
36
37 template < typename TYPE_KEEP, typename TYPE_KEEP_AWAY >
38 ___keep(TYPE& kept, const TYPE_KEEP& keepValue, const TYPE_KEEP_AWAY& keepAwayValue, bool bStartKept = true);
39
40 template < typename TYPE_KEEP >
41 ___keep(TYPE& kept, const TYPE_KEEP& keepValue = ::default_keep_value < TYPE >());
42
43 virtual ~___keep();
44
45 void Keep();
46 void KeepAway();
47
48
49};
50
51
52template < typename TYPE >
53template < typename TYPE_KEEP, typename TYPE_KEEP_AWAY >
54___keep < TYPE > ::___keep(TYPE& kept, const TYPE_KEEP& keepValue, const TYPE_KEEP_AWAY& keepAwayValue, bool bStartKept) :
55 m_keepValue(keepValue),
56 m_keepAwayValue(keepAwayValue),
57 m_pKept(&kept)
58{
59 if (bStartKept)
60 {
61 m_bKept = false;
62 Keep();
63 }
64 else
65 {
66 m_bKept = true;
67 KeepAway();
68 }
69
70}
71
72
73template < typename TYPE >
74template < typename TYPE_KEEP >
75___keep < TYPE > ::___keep(TYPE& kept, const TYPE_KEEP& keepValue) :
76 m_keepValue(keepValue),
77 m_keepAwayValue(kept),
78 m_pKept(&kept)
79{
80 m_bKept = false;
81 Keep();
82}
83
84
85template < typename TYPE >
86___keep < TYPE > ::___keep(___keep&& keep) :
87 m_keepValue(keep.m_keepValue),
88 m_keepAwayValue(keep.m_keepAwayValue),
89 m_pKept(keep.m_pKept),
90 m_bKept(keep.m_bKept)
91{
92 keep.m_pKept = nullptr;
93}
94
95
96template < typename TYPE >
97___keep<TYPE>::~___keep()
98{
99 if (m_bKept)
100 {
101 KeepAway();
102 }
103}
104
105
106template < typename TYPE >
107void ___keep<TYPE>::Keep()
108{
109 if (m_pKept)
110 {
111 *m_pKept = m_keepValue;
112 m_bKept = true;
113 }
114}
115
116
117template <class TYPE>
118void ___keep<TYPE>::KeepAway()
119{
120 if (m_pKept)
121 {
122 *m_pKept = m_keepAwayValue;
123 m_bKept = false;
124 }
125}
126
127
128template < typename TYPE >
129___keep < TYPE > keep(TYPE& kept)
130{
131
132 return ___keep < TYPE >(kept, ::default_keep_value < TYPE >());
133
134}
135
136
137template < typename TYPE, typename TYPE_KEEP >
138___keep < TYPE > keep(TYPE& kept, const TYPE_KEEP& keepValue)
139{
140
141 return ___keep < TYPE >(kept, keepValue);
142
143}
144
145
146template < typename TYPE, typename TYPE_KEEP, typename TYPE_KEEP_AWAY >
147___keep < TYPE > keep(TYPE& kept, const TYPE_KEEP& keepValue, const TYPE_KEEP_AWAY& keepAwayValue, bool bStartKept = true)
148{
149
150 return ___keep < TYPE >(kept, keepValue, keepAwayValue, bStartKept);
151
152}
153
154
156
157
158#define KEEP(...) auto COUNTER_TOKEN(KEEP) = keep(__VA_ARGS__)
159#define __keep_true(...) auto COUNTER_TOKEN(__keep_true) = keep(__VA_ARGS__, true)
160#define __keep_false(...) auto COUNTER_TOKEN(__keep_false) = keep(__VA_ARGS__, false)
161#define __keep_task_payload(...) auto COUNTER_TOKEN(__keep_task_payload) = keep_task_payload(__VA_ARGS__)
162#define __keep_current_thread(...) auto COUNTER_TOKEN(__keep_current_thread) = keep(__VA_ARGS__, ::get_task())
163
164
166
167#define KEEP(...) auto COUNTER_TOKEN(KEEP) = keep(__VA_ARGS__)
168#define __keep_true(...) auto COUNTER_TOKEN(__keep_true) = keep(__VA_ARGS__, true)
169#define __keep_false(...) auto COUNTER_TOKEN(__keep_false) = keep(__VA_ARGS__, false)
170#define __keep_task_payload(...) auto COUNTER_TOKEN(__keep_task_payload) = keep_task_payload(__VA_ARGS__)
171#define __keep_current_thread(...) auto COUNTER_TOKEN(__keep_current_thread) = keep(__VA_ARGS__, ::get_task())
172
173
174#define __task_guard_ret(flag, ret) \
175 \
176synchronous_lock synchronouslock(this->synchronization()); \
177 \
178if (flag) \
179{ \
180\
181 ret; \
182\
183} \
184\
185auto COUNTER_TOKEN(__task_guard_task_ret) = keep(flag); \
186\
187synchronouslock.unlock()
188
189#define __task_guard(flag) __task_guard_ret(flag, return)
190
191
192#define __guard_wait_ret(flag, ret) \
193 \
194synchronous_lock synchronouslock(this->synchronization()); \
195 \
196while (flag) \
197{ \
198\
199 \
200 synchronouslock.unlock(); \
201 \
202 if (!task_sleep(100_ms)) \
203 {\
204 \
205 ret; \
206 \
207 } \
208 \
209 synchronouslock.lock(); \
210 \
211 \
212} \
213\
214auto COUNTER_TOKEN(__guard_wait_ret) = keep(&flag); \
215\
216synchronouslock.unlock()
217
218#define __guard_wait(flag) __task_guard_ret(flag, return)
219
220
221
222template <class TYPE>
223class ___keep_on
224{
225public:
226
227
228 TYPE m_keepValue;
229 bool m_bWasSet;
230 TYPE* m_pKept;
231 bool m_bKept;
232
233 template < typename TYPE_KEEP>
234 ___keep_on(TYPE* pKept, TYPE_KEEP keep, bool bStartKept = true);
235 ___keep_on(___keep_on&& on) :
236 m_keepValue(on.m_keepValue),
237 m_bWasSet(on.m_bWasSet),
238 m_pKept(on.m_pKept),
239 m_bKept(on.m_bKept)
240 {
241 on.m_pKept = nullptr;
242 }
243 virtual ~___keep_on();
244
245 void Keep();
246 void KeepAway();
247
248
249};
250
251
252
253template < typename TYPE >
254template < typename TYPE_KEEP >
255___keep_on<TYPE>::___keep_on(TYPE* pKept, TYPE_KEEP keepValue, bool bStartKept) :
256 m_keepValue(keepValue),
257 m_pKept(pKept)
258{
259 if (bStartKept)
260 {
261 m_bKept = false;
262 Keep();
263 }
264 else
265 {
266 m_bKept = true;
267 KeepAway();
268 }
269
270}
271template <class TYPE>
272___keep_on<TYPE>::~___keep_on()
273{
274 if (m_bKept)
275 {
276 KeepAway();
277 }
278}
279
280template <class TYPE>
281void ___keep_on<TYPE>::Keep()
282{
283 if (m_pKept)
284 {
285 *m_pKept |= m_keepValue;
286 m_bKept = true;
287 }
288}
289
290template <class TYPE>
291void ___keep_on<TYPE>::KeepAway()
292{
293 if (m_pKept && !m_bWasSet)
294 {
295 *m_pKept &= ~m_keepValue;
296 m_bKept = false;
297 }
298}
299
300
301template < typename TYPE, typename TYPE_KEEP >
302___keep_on < TYPE > keep_on(TYPE& kept, TYPE_KEEP keepValue, bool bStartKept = true)
303{
304
305 return ___keep_on < TYPE >(&kept, keepValue, bStartKept);
306
307}
308
309
310template < typename TYPE, typename TYPE_KEEP >
311___keep_on < TYPE > keep_on(TYPE* pKept, TYPE_KEEP keepValue, bool bStartKept = true)
312{
313
314 return ___keep_on < TYPE >(pKept, keepValue, bStartKept);
315
316}
317
318#define __keep_on(...) auto COUNTER_TOKEN(__keep_on) = keep_on(__VA_ARGS__)
319
320
321
322template < typename FLAG >
323class ___keep_flag_on
324{
325public:
326
327
328 enumeration < FLAG >& m_eflagVariable;
329 enumeration < FLAG > m_eflag;
330
331
332 ___keep_flag_on(enumeration < FLAG >& eflagVariable, FLAG iFlag) :
333 m_eflagVariable(eflagVariable),
334 m_eflag(iFlag)
335 {
336
337 m_eflagVariable |= m_eflag;
338
339 }
340
341 ___keep_flag_on(const ___keep_flag_on& on) :
342 m_eflagVariable(on.m_eflagVariable),
343 m_eflag(on.m_eflag)
344 {
345
346 }
347
348
349 ~___keep_flag_on()
350 {
351
352 m_eflagVariable -= m_eflag;
353
354 }
355
356
357};
358
359template < typename FLAG >
360inline ___keep_flag_on < FLAG > keep_flag_on(enumeration < FLAG >& eflagVariable, FLAG eflag)
361{
362
363 return ___keep_flag_on < FLAG >(eflagVariable, eflag);
364
365}
366
367
368#define __keep_flag_on(...) auto COUNTER_TOKEN(__keep_flag_on) = keep_flag_on(__VA_ARGS__)
369
370
371
372#define KEEP(...) auto COUNTER_TOKEN(KEEP) = keep(__VA_ARGS__)
373#define __keep_true(...) auto COUNTER_TOKEN(__keep_true) = keep(__VA_ARGS__, true)
374#define __keep_false(...) auto COUNTER_TOKEN(__keep_false) = keep(__VA_ARGS__, false)
375#define __keep_task_flag(...) auto COUNTER_TOKEN(__keep_task_flag) = keep_task_flag(__VA_ARGS__)
376#define __keep_current_thread(...) auto COUNTER_TOKEN(__keep_current_thread) = keep(__VA_ARGS__, ::get_task())
377
378
379#define __task_guard_ret(flag, ret) \
380 \
381synchronous_lock synchronouslock(this->synchronization()); \
382 \
383if (flag) \
384{ \
385\
386 ret; \
387\
388} \
389\
390auto COUNTER_TOKEN(__task_guard_task_ret) = keep(flag); \
391\
392synchronouslock.unlock()
393
394#define __task_guard(flag) __task_guard_ret(flag, return)
395
396
397#define __guard_wait_ret(flag, ret) \
398 \
399synchronous_lock synchronouslock(this->synchronization()); \
400 \
401while (flag) \
402{ \
403\
404 \
405 synchronouslock.unlock(); \
406 \
407 if (!task_sleep(100_ms)) \
408 {\
409 \
410 ret; \
411 \
412 } \
413 \
414 synchronouslock.lock(); \
415 \
416 \
417} \
418\
419auto COUNTER_TOKEN(__guard_wait_ret) = keep(&flag); \
420\
421synchronouslock.unlock()
422
423#define __guard_wait(flag) __task_guard_ret(flag, return)
424
425
426
427//template <class TYPE>
428//class ___keep_on
429//{
430//public:
431//
432//
433// TYPE m_keepValue;
434// bool m_bWasSet;
435// TYPE * m_pKept;
436// bool m_bKept;
437//
438// template < typename TYPE_KEEP>
439// ___keep_on(TYPE * pKept, TYPE_KEEP keep, bool bStartKept = true);
440// ___keep_on(___keep_on && on):
441// m_keepValue(on.m_keepValue),
442// m_bWasSet(on.m_bWasSet),
443// m_pKept(on.m_pKept),
444// m_bKept(on.m_bKept)
445// {
446// on.m_pKept = nullptr;
447// }
448// virtual ~___keep_on();
449//
450// void Keep();
451// void KeepAway();
452//
453//
454//};
455
456
457
458//template < typename TYPE >
459//template < typename TYPE_KEEP >
460//___keep_on<TYPE>::___keep_on(TYPE * pKept, TYPE_KEEP keepValue, bool bStartKept) :
461// m_keepValue(keepValue),
462// m_pKept(pKept)
463//{
464// if (bStartKept)
465// {
466// m_bKept = false;
467// Keep();
468// }
469// else
470// {
471// m_bKept = true;
472// KeepAway();
473// }
474//
475//}
476//template <class TYPE>
477//___keep_on<TYPE>::~___keep_on()
478//{
479// if (m_bKept)
480// {
481// KeepAway();
482// }
483//}
484
485//#pragma once
486
487
488
489
490//template < typename TYPE >
491//inline TYPE default_keep_value()
492//{
493//
494// return (TYPE) nullptr;
495//
496//}
497
498
499//template < >
500//inline bool default_keep_value < bool >()
501//{
502//
503// return true;
504//
505//}
506
507//template < >
508//inline ::thread * default_keep_value < ::thread * >()
509//{
510//
511// return ::get_task();
512//
513//}
514
515//
516//template < typename TYPE >
517//class ___keep
518//{
519//public:
520//
521//
522// TYPE m_keepValue;
523// TYPE m_keepAwayValue;
524// TYPE* m_pKept;
525// bool m_bKept;
526//
527//
528// ___keep(___keep&& keep);
529//
530// template < typename TYPE_KEEP, typename TYPE_KEEP_AWAY >
531// ___keep(TYPE& kept, const TYPE_KEEP& keepValue, const TYPE_KEEP_AWAY& keepAwayValue, bool bStartKept = true);
532//
533// template < typename TYPE_KEEP >
534// ___keep(TYPE& kept, const TYPE_KEEP& keepValue = ::default_keep_value < TYPE >());
535//
536// virtual ~___keep();
537//
538// void Keep();
539// void KeepAway();
540//
541//
542//};
543
544
545//template < typename TYPE >
546//class ___keep_pointer
547//{
548//public:
549//
550//
551// TYPE * m_keepValue;
552// TYPE * m_keepAwayValue;
553// ::pointer<TYPE>* m_pKept;
554// bool m_bKept;
555//
556//
557// template < typename TYPE_KEEP, typename TYPE_KEEP_AWAY >
558// ___keep_pointer(::pointer<TYPE> pKept, TYPE_KEEP * keepValue, TYPE_KEEP_AWAY * keepAwayValue, bool bStartKept = true);
559//
560// template < typename TYPE_KEEP >
561// ___keep_pointer(::pointer<TYPE> pKept, TYPE_KEEP * keepValue = ::default_keep_value < TYPE * >());
562//
563// ___keep_pointer(___keep_pointer&& keep);
564//
565// virtual ~___keep_pointer();
566//
567// void Keep();
568// void KeepAway();
569//
570//
571//};
572//
573//
574
575//template < typename TYPE >
576//template < typename TYPE_KEEP, typename TYPE_KEEP_AWAY >
577//___keep < TYPE > ::___keep(TYPE & kept, const TYPE_KEEP & keepValue, const TYPE_KEEP_AWAY & keepAwayValue, bool bStartKept) :
578// m_keepValue(keepValue),
579// m_keepAwayValue(keepAwayValue),
580// m_pKept(&kept)
581//{
582// if (bStartKept)
583// {
584// m_bKept = false;
585// Keep();
586// }
587// else
588// {
589// m_bKept = true;
590// KeepAway();
591// }
592//
593//}
594//
595//template < typename TYPE >
596//template < typename TYPE_KEEP >
597//___keep < TYPE > ::___keep(TYPE & kept, const TYPE_KEEP & keepValue) :
598// m_keepValue(keepValue),
599// m_keepAwayValue(kept),
600// m_pKept(&kept)
601//{
602// m_bKept = false;
603// Keep();
604//}
605//
606//
607//template < typename TYPE >
608//___keep < TYPE > ::___keep(___keep && keep) :
609// m_keepValue(keep.m_keepValue),
610// m_keepAwayValue(keep.m_keepAwayValue),
611// m_pKept(keep.m_pKept),
612// m_bKept(keep.m_bKept)
613//{
614// keep.m_pKept = nullptr;
615//}
616//
617//
618//template < typename TYPE >
619//___keep<TYPE>::~___keep()
620//{
621// if (m_bKept)
622// {
623// KeepAway();
624// }
625//}
626//
627//template < typename TYPE >
628//void ___keep<TYPE>::Keep()
629//{
630// if (m_pKept)
631// {
632// *m_pKept = m_keepValue;
633// m_bKept = true;
634// }
635//}
636//
637//template <class TYPE>
638//void ___keep<TYPE>::KeepAway()
639//{
640// if (m_pKept)
641// {
642// *m_pKept = m_keepAwayValue;
643// m_bKept = false;
644// }
645//}
646
647//template < typename TYPE >
648//template < typename TYPE_KEEP, typename TYPE_KEEP_AWAY >
649//___keep_pointer < TYPE > ::___keep_pointer(::pointer<TYPE> pKept, TYPE_KEEP * keepValue, TYPE_KEEP_AWAY * keepAwayValue, bool bStartKept) :
650// m_keepValue(keepValue),
651// m_keepAwayValue(keepAwayValue),
652// m_pKept(pKept)
653//{
654// if (bStartKept)
655// {
656// m_bKept = false;
657// Keep();
658// }
659// else
660// {
661// m_bKept = true;
662// KeepAway();
663// }
664//
665//}
666//
667//template < typename TYPE >
668//template < typename TYPE_KEEP >
669//___keep_pointer < TYPE > ::___keep_pointer(::pointer<TYPE> pKept, TYPE_KEEP * keepValue) :
670// m_keepValue(keepValue),
671// m_keepAwayValue(*pKept),
672// m_pKept(pKept)
673//{
674// m_bKept = false;
675// Keep();
676//}
677//
678//
679//template < typename TYPE >
680//___keep_pointer < TYPE > ::___keep_pointer(___keep_pointer&& keep) :
681// m_keepValue(keep.m_keepValue),
682// m_keepAwayValue(keep.m_keepAwayValue),
683// m_pKept(keep.m_pKept),
684// m_bKept(keep.m_bKept)
685//{
686// keep.m_pKept = nullptr;
687//}
688//
689//
690//template < typename TYPE >
691//___keep_pointer<TYPE>::~___keep_pointer()
692//{
693// if (m_bKept)
694// {
695// KeepAway();
696// }
697//}
698//
699//template < typename TYPE >
700//void ___keep_pointer<TYPE>::Keep()
701//{
702// if (m_pKept)
703// {
704// *m_pKept = m_keepValue;
705// m_bKept = true;
706// }
707//}
708//
709//template <class TYPE>
710//void ___keep_pointer<TYPE>::KeepAway()
711//{
712// if (m_pKept)
713// {
714// *m_pKept = m_keepAwayValue;
715// m_bKept = false;
716// }
717//}
718//
719
720//template < typename TYPE >
721//___keep < TYPE > keep(TYPE * pKept)
722//{
723//
724// return ___keep < TYPE >(pKept, ::default_keep_value < TYPE >());
725//
726//}
727
728
729//template < typename TYPE, typename TYPE_KEEP >
730//___keep < TYPE > keep(TYPE * pKept, TYPE_KEEP * keepValue)
731//{
732//
733// return ___keep < TYPE >(pKept, keepValue);
734//
735//}
736
737
738//template < typename TYPE, typename TYPE_KEEP, typename TYPE_KEEP_AWAY >
739//___keep < TYPE > keep(TYPE * pKept, TYPE_KEEP * keepValue, TYPE_KEEP_AWAY * keepAwayValue, bool bStartKept = true)
740//{
741//
742// return ___keep < TYPE >(pKept, keepValue, keepAwayValue, bStartKept);
743//
744//}
745//
746
747//template < typename TYPE >
748//___keep < TYPE > keep(TYPE & kept)
749//{
750//
751// return ___keep < TYPE >(kept, ::default_keep_value < TYPE >());
752//
753//}
754
755//template < typename TYPE, typename TYPE_KEEP >
756//___keep_pointer < TYPE > keep(::pointer<TYPE> pKept, TYPE_KEEP * keepValue)
757//{
758//
759// return ___keep_pointer < TYPE >(pKept, keepValue);
760//
761//}
762
763
764//template < typename TYPE >
765//___keep_pointer < TYPE > keep(::pointer<TYPE> kept)
766//{
767//
768// return ___keep_pointer < TYPE >(&kept, ::default_keep_value < TYPE >());
769//
770//}
771
772
773//template < typename TYPE, typename TYPE_KEEP >
774//___keep < TYPE > keep(TYPE & kept, const TYPE_KEEP & keepValue)
775//{
776//
777// return ___keep < TYPE >(kept, keepValue);
778//
779//}
780
781
782//template < typename TYPE, typename TYPE_KEEP, typename TYPE_KEEP_AWAY >
783//___keep < TYPE > keep(TYPE & kept, const TYPE_KEEP & keepValue, const TYPE_KEEP_AWAY & keepAwayValue, bool bStartKept = true)
784//{
785//
786// return ___keep < TYPE >(kept, keepValue, keepAwayValue, bStartKept);
787//
788//}
790
791//#define KEEP(...) auto COUNTER_TOKEN(KEEP) = keep(__VA_ARGS__)
792//#define __keep_true(...) auto COUNTER_TOKEN(__keep_true) = keep(__VA_ARGS__, true)
793//#define __keep_false(...) auto COUNTER_TOKEN(__keep_false) = keep(__VA_ARGS__, false)
794//#define __keep_task_flag(...) auto COUNTER_TOKEN(__keep_task_flag) = keep_thread_flag(__VA_ARGS__)
795#define __keep_current_thread(...) auto COUNTER_TOKEN(__keep_current_thread) = keep(__VA_ARGS__, ::get_task())
796
797
798#define __task_guard_ret(flag, ret) \
799 \
800synchronous_lock synchronouslock(this->synchronization()); \
801 \
802if (flag) \
803{ \
804\
805 ret; \
806\
807} \
808\
809auto COUNTER_TOKEN(__task_guard_task_ret) = keep(flag); \
810\
811synchronouslock.unlock()
812
813#define __task_guard(flag) __task_guard_ret(flag, return)
814
815
816#define __guard_wait_ret(flag, ret) \
817 \
818synchronous_lock synchronouslock(this->synchronization()); \
819 \
820while (flag) \
821{ \
822\
823 \
824 synchronouslock.unlock(); \
825 \
826 if (!task_sleep(100_ms)) \
827 {\
828 \
829 ret; \
830 \
831 } \
832 \
833 synchronouslock.lock(); \
834 \
835 \
836} \
837\
838auto COUNTER_TOKEN(__guard_wait_ret) = keep(&flag); \
839\
840synchronouslock.unlock()
841
842#define __guard_wait(flag) __task_guard_ret(flag, return)
843
844
845
846
847
848
849
850#define __task_guard_ret(flag, ret) \
851 \
852synchronous_lock synchronouslock(this->synchronization()); \
853 \
854if (flag) \
855{ \
856\
857 ret; \
858\
859} \
860\
861auto COUNTER_TOKEN(__task_guard_task_ret) = keep(flag); \
862\
863synchronouslock.unlock()
864
865#define __task_guard(flag) __task_guard_ret(flag, return)
866
867
868#define __guard_wait_ret(flag, ret) \
869 \
870synchronous_lock synchronouslock(this->synchronization()); \
871 \
872while (flag) \
873{ \
874\
875 \
876 synchronouslock.unlock(); \
877 \
878 if (!task_sleep(100_ms)) \
879 {\
880 \
881 ret; \
882 \
883 } \
884 \
885 synchronouslock.lock(); \
886 \
887 \
888} \
889\
890auto COUNTER_TOKEN(__guard_wait_ret) = keep(&flag); \
891\
892synchronouslock.unlock()
893
894#define __guard_wait(flag) __task_guard_ret(flag, return)
895
897
898#define KEEP(...) auto COUNTER_TOKEN(KEEP) = keep(__VA_ARGS__)
899#define KEEP_TRUE(...) auto COUNTER_TOKEN(__keep_true) = keep(__VA_ARGS__, true)
900#define KEEP_FALSE(...) auto COUNTER_TOKEN(__keep_false) = keep(__VA_ARGS__, false)
901#define KEEP_CURRENT_THREAD(...) auto COUNTER_TOKEN(__keep_current_thread) = keep(__VA_ARGS__, ::get_task())
902
903
904#define __task_guard_ret(flag, ret) \
905 \
906synchronous_lock synchronouslock(this->synchronization()); \
907 \
908if (flag) \
909{ \
910\
911 ret; \
912\
913} \
914\
915auto COUNTER_TOKEN(__task_guard_task_ret) = keep(flag); \
916\
917synchronouslock.unlock()
918
919#define __task_guard(flag) __task_guard_ret(flag, return)
920
921
922#define __guard_wait_ret(flag, ret) \
923 \
924synchronous_lock synchronouslock(this->synchronization()); \
925 \
926while (flag) \
927{ \
928\
929 \
930 synchronouslock.unlock(); \
931 \
932 if (!task_sleep(100_ms)) \
933 {\
934 \
935 ret; \
936 \
937 } \
938 \
939 synchronouslock.lock(); \
940 \
941 \
942} \
943\
944auto COUNTER_TOKEN(__guard_wait_ret) = keep(&flag); \
945\
946synchronouslock.unlock()
947
948#define __guard_wait(flag) __task_guard_ret(flag, return)
949
950
951#define __keep_current_thread(...) auto COUNTER_TOKEN(__keep_current_thread) = keep(__VA_ARGS__, ::get_task())
952
953
954#define __guard_wait_ret(flag, ret) \
955 \
956synchronous_lock synchronouslock(this->synchronization()); \
957 \
958while (flag) \
959{ \
960\
961 \
962 synchronouslock.unlock(); \
963 \
964 if (!task_sleep(100_ms)) \
965 {\
966 \
967 ret; \
968 \
969 } \
970 \
971 synchronouslock.lock(); \
972 \
973 \
974} \
975\
976auto COUNTER_TOKEN(__guard_wait_ret) = keep(&flag); \
977\
978synchronouslock.unlock()
979
980#define __guard_wait(flag) __task_guard_ret(flag, return)
981
982
Definition keep.h:25