33#ifndef DVD_CONDITIONAL_WAIT_H_
34#define DVD_CONDITIONAL_WAIT_H_
42template<
typename T,
typename U>
45 static_assert(std::is_same<U, T>::value,
"value type not satisfied");
48#define WAIT_FOR_CONDITION_2_ARGS(condition, yld) \
50 assert_type<bool>(yld); \
52 if (yld) [[likely]] { \
53 while (!(condition)) { \
54 PlatformContextIdleCall(); \
55 std::this_thread::yield(); \
58 while(!(condition)) {} \
62#define WAIT_FOR_CONDITION_1_ARGS(condition) WAIT_FOR_CONDITION_2_ARGS(condition, true)
64#define ___DETAIL_WAIT_FOR_CONDITION(...) EXP(GET_3RD_ARG(__VA_ARGS__, WAIT_FOR_CONDITION_2_ARGS, WAIT_FOR_CONDITION_1_ARGS, ))
65#define WAIT_FOR_CONDITION(...) EXP(___DETAIL_WAIT_FOR_CONDITION(__VA_ARGS__)(__VA_ARGS__)); static_assert(true, "")
67#define WAIT_FOR_CONDITION_TIMEOUT_3_ARGS(condition, timeoutMS, yld) \
69 assert_type<bool>(yld); \
70 assert_type<D64>(timeoutMS); \
72 if (timeoutMS >= 0.0) { \
73 const D64 start = Time::App::ElapsedMilliseconds(); \
75 while (!(condition)) { \
76 PlatformContextIdleCall(); \
77 if (Time::App::ElapsedMilliseconds() - start >= timeoutMS) \
82 if (yld) [[likely]] { \
83 std::this_thread::yield(); \
87 WAIT_FOR_CONDITION(condition, yld); \
91#define WAIT_FOR_CONDITION_TIMEOUT_2_ARGS(condition, timeoutMS) WAIT_FOR_CONDITION_TIMEOUT_3_ARGS(condition, timeoutMS, true)
92#define WAIT_FOR_CONDITION_TIMEOUT_1_ARGS(condition) WAIT_FOR_CONDITION_TIMEOUT_3_ARGS(condition, 1.0, true)
94#define ___DETAIL_WAIT_FOR_CONDITION_TIMEOUT(...) EXP(GET_4TH_ARG(__VA_ARGS__, WAIT_FOR_CONDITION_TIMEOUT_3_ARGS, WAIT_FOR_CONDITION_TIMEOUT_2_ARGS, WAIT_FOR_CONDITION_TIMEOUT_1_ARGS, ))
95#define WAIT_FOR_CONDITION_TIMEOUT(...) EXP(___DETAIL_WAIT_FOR_CONDITION_TIMEOUT(__VA_ARGS__)(__VA_ARGS__)); static_assert(true, "")
97#define WAIT_FOR_CONDITION_CALLBACK_4_ARGS(condition, cbk, param, yld) \
99 assert_type<bool>(yld); \
101 while (!(condition)) { \
103 PlatformContextIdleCall(); \
104 if (yld) [[likely]] { \
105 std::this_thread::yield(); \
110#define WAIT_FOR_CONDITION_CALLBACK_3_ARGS(condition, cbk, param) WAIT_FOR_CONDITION_CALLBACK_4_ARGS(condition, cbk, param, true)
111#define WAIT_FOR_CONDITION_CALLBACK_2_ARGS(condition, cbk) WAIT_FOR_CONDITION_CALLBACK_3_ARGS(condition, cbk, void, true)
112#define WAIT_FOR_CONDITION_CALLBACK_1_ARGS(condition) WAIT_FOR_CONDITION(condition)
114#define ___DETAIL_WAIT_FOR_CONDITION_CALLBACK(...) EXP(GET_4TH_ARG(__VA_ARGS__, WAIT_FOR_CONDITION_CALLBACK_3_ARGS, WAIT_FOR_CONDITION_CALLBACK_2_ARGS, WAIT_FOR_CONDITION_CALLBACK_1_ARGS, ))
115#define WAIT_FOR_CONDITION_CALLBACK(...) EXP(___DETAIL_WAIT_FOR_CONDITION_CALLBACK(__VA_ARGS__)(__VA_ARGS__)); static_assert(true, "")
117#define WAIT_FOR_CONDITION_CALLBACK_TIMEOUT_5_ARGS(condition, cbk, param, timeoutMS, yld) \
119 assert_type<bool>(yld); \
120 assert_type<D64>(timeoutMS); \
122 if ((timeoutMS) >= 0.0) { \
123 const D64 start = Time::ElapsedMilliseconds(true); \
125 while (!(condition)) { \
127 PlatformContextIdleCall(); \
129 if (Time::ElapsedMilliseconds(true) - start >= (timeoutMS)) { \
133 if (yld) [[likely]] { \
134 std::this_thread::yield(); \
138 WAIT_FOR_CONDITION_CALLBACK(condition, cbk, param, yld); \
142#define WAIT_FOR_CONDITION_CALLBACK_TIMEOUT_4_ARGS(condition, cbk, param, timeoutMS) WAIT_FOR_CONDITION_CALLBACK_TIMEOUT_5_ARGS(condition, cbk, param, timeoutMS, true)
143#define WAIT_FOR_CONDITION_CALLBACK_TIMEOUT_3_ARGS(condition, cbk, param) WAIT_FOR_CONDITION_CALLBACK(condition, cbk, param)
144#define WAIT_FOR_CONDITION_CALLBACK_TIMEOUT_2_ARGS(condition, cbk) WAIT_FOR_CONDITION_CALLBACK(condition, cbk)
145#define WAIT_FOR_CONDITION_CALLBACK_TIMEOUT_1_ARGS(condition) WAIT_FOR_CONDITION(condition)
147#define ___DETAIL_WAIT_FOR_CONDITION_CALLBACK_TIMEOUT(...) EXP(GET_5TH_ARG(__VA_ARGS__, WAIT_FOR_CONDITION_CALLBACK_TIMEOUT_4_ARGS, WAIT_FOR_CONDITION_CALLBACK_TIMEOUT_3_ARGS, WAIT_FOR_CONDITION_CALLBACK_TIMEOUT_2_ARGS, WAIT_FOR_CONDITION_CALLBACK_TIMEOUT_1_ARGS, ))
148#define WAIT_FOR_CONDITION_CALLBACK_TIMEOUT(...) EXP(___DETAIL_WAIT_FOR_CONDITION_CALLBACK_TIMEOUT(__VA_ARGS__)(__VA_ARGS__)); static_assert(true, "")
Handle console commands that start with a forward slash.
void PlatformContextIdleCall()
constexpr void assert_type(const U &)
void InitConditionalWait(PlatformContext &context) noexcept