Skip to content

Commit

Permalink
UI: Use multithreaded scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
frankosterfeld committed Feb 2, 2024
1 parent ca67593 commit 384f485
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/ui/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include "common.h"
#include "dashboard.h"
#include "dashboardpage.h"
#include "flowgraph.h"
#include "flowgraphitem.h"
#include "opendashboardpage.h"

#include <gnuradio-4.0/Scheduler.hpp>

struct ImFont;

namespace DigitizerUi {
Expand Down Expand Up @@ -73,11 +74,9 @@ struct App {
ImFont *fontIconsSolidLarge;
std::chrono::seconds editPaneCloseDelay{ 15 };

template<typename Scheduler, typename Graph>
template<typename Graph>
void assignScheduler(Graph &&graph) {
if (m_scheduler) {
m_garbageSchedulers.push_back(std::move(m_scheduler));
}
using Scheduler = gr::scheduler::Simple<gr::scheduler::multiThreaded>;
m_scheduler.emplace<Scheduler>(std::forward<Graph>(graph));
}

Expand All @@ -97,24 +96,30 @@ struct App {
struct HandlerImpl : Handler {
T data;
std::thread thread;
std::atomic<bool> stopRequested = false;

template<typename... Args>
explicit HandlerImpl(Args &&...args)
: data(std::forward<Args>(args)...) {
thread = std::thread([this]() {
data.init();
data.runAndWait();
data.start();
while (!stopRequested && data.isProcessing()) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
data.stop();
});
}
~HandlerImpl() {
stopRequested = true;
thread.join();
}
};

std::unique_ptr<Handler> handler;
};

SchedWrapper m_scheduler;
std::vector<SchedWrapper> m_garbageSchedulers; // TODO: Cleaning up schedulers needs support in opencmw to return unsubscription confirmation
SchedWrapper m_scheduler;

App();

Expand Down
2 changes: 1 addition & 1 deletion src/ui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static void main_loop(void *arg) {
if (app->dashboard->localFlowGraph.graphChanged()) {
// create the graph and the scheduler
auto graph = app->dashboard->localFlowGraph.createGraph();
app->assignScheduler<gr::scheduler::Simple<gr::scheduler::singleThreaded>>(std::move(graph));
app->assignScheduler(std::move(graph));
}

// Poll and handle events (inputs, window resize, etc.)
Expand Down

0 comments on commit 384f485

Please sign in to comment.