diff --git a/libs/dmf-node/src/node_runner.cpp b/libs/dmf-node/src/node_runner.cpp index 974eda6..44f6ef2 100644 --- a/libs/dmf-node/src/node_runner.cpp +++ b/libs/dmf-node/src/node_runner.cpp @@ -170,20 +170,19 @@ int NodeRunner::exec(std::unique_ptr node) { running_ = true; spdlog::info("Node '{}' entering process loop", node_id_); - while (g_running && running_) { - control_server->poll(1); - node->process(); - - static int status_counter = 0; - if (++status_counter % 100 == 0) { - nlohmann::json status_event; - status_event["event"] = "status"; - status_event["node_id"] = node_id_; - status_event["data"] = node->status(); - control_server->send_event(status_event); + std::thread process_thread([&]() { + while (g_running && running_) { + node->process(); } + }); + + while (g_running && running_) { + control_server->poll(10); } + running_ = false; + process_thread.join(); + spdlog::info("Node '{}' shutting down", node_id_); mxlDestroyInstance(mxl_instance_); return 0; diff --git a/nodes/passthrough/src/passthrough_node.cpp b/nodes/passthrough/src/passthrough_node.cpp index 244c049..eebaf4a 100644 --- a/nodes/passthrough/src/passthrough_node.cpp +++ b/nodes/passthrough/src/passthrough_node.cpp @@ -51,13 +51,12 @@ void PassthroughNode::on_remove_reader(const std::string& port_id) { void PassthroughNode::process() { if (!reader_ || !writer_ || !aligned_) { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); return; } - auto ns_until = mxlGetNsUntilIndex(read_index_, &grain_rate_); - if (ns_until > 2000000ULL) { - return; - } + auto deadline = mxlIndexToTimestamp(&grain_rate_, read_index_ + 1); + mxlSleepUntil(deadline); mxlGrainInfo grain_info{}; uint8_t* payload = nullptr; diff --git a/nodes/passthrough/src/passthrough_node.hpp b/nodes/passthrough/src/passthrough_node.hpp index c4e519a..2b1b753 100644 --- a/nodes/passthrough/src/passthrough_node.hpp +++ b/nodes/passthrough/src/passthrough_node.hpp @@ -5,6 +5,7 @@ #include #include +#include namespace dmf_node {