|
|
@@ -49,6 +49,39 @@ namespace sophiar {
|
|
|
return std::move(worker);
|
|
|
}
|
|
|
|
|
|
+ template<typename SmallObjType>
|
|
|
+ inline coro_worker::pointer variable_validity_watcher_func(const nlohmann::json &config) {
|
|
|
+ enum class status_type {
|
|
|
+ UNKNOWN,
|
|
|
+ VALID,
|
|
|
+ INVALID
|
|
|
+ };
|
|
|
+ std::string var_name;
|
|
|
+ auto var_index = LOAD_VARIABLE_INDEX_WITH_NAME(SmallObjType, "variable_name", var_name);
|
|
|
+ auto worker = make_infinite_coro_worker(
|
|
|
+ [=,
|
|
|
+ status = status_type{},
|
|
|
+ var_helper = VARIABLE_MANUAL_DELEGATE(SmallObjType, var_index)]() mutable
|
|
|
+ -> awaitable<bool> {
|
|
|
+ if (status != status_type::UNKNOWN) {
|
|
|
+ co_await var_helper.coro_wait_update();
|
|
|
+ } else {
|
|
|
+ var_helper.manual_sync();
|
|
|
+ }
|
|
|
+ if (var_helper.empty()) {
|
|
|
+ if (status == status_type::INVALID)[[likely]] co_return true;
|
|
|
+ SPDLOG_DEBUG("{} becomes invalid.", var_name);
|
|
|
+ status = status_type::INVALID;
|
|
|
+ } else {
|
|
|
+ if (status == status_type::VALID)[[likely]] co_return true;
|
|
|
+ SPDLOG_DEBUG("{} becomes valid.", var_name);
|
|
|
+ status = status_type::VALID;
|
|
|
+ }
|
|
|
+ co_return true;
|
|
|
+ });
|
|
|
+ return std::move(worker);
|
|
|
+ }
|
|
|
+
|
|
|
template<typename SmallObjType>
|
|
|
inline coro_worker::pointer variable_recorder_func(const nlohmann::json &config) {
|
|
|
auto var_index = LOAD_VARIABLE_INDEX(SmallObjType, "variable_name");
|
|
|
@@ -113,6 +146,9 @@ namespace sophiar {
|
|
|
template<typename SmallObjType>
|
|
|
using variable_debug_watcher = simple_tristate_obj_wrapper<variable_debug_watcher_func<SmallObjType>>;
|
|
|
|
|
|
+ template<typename SmallObjType>
|
|
|
+ using variable_validity_watcher = simple_tristate_obj_wrapper<variable_validity_watcher_func<SmallObjType>>;
|
|
|
+
|
|
|
template<typename SmallObjType>
|
|
|
using variable_recorder = simple_tristate_obj_wrapper<variable_recorder_func<SmallObjType>>;
|
|
|
|