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 6, 2024
1 parent 70b86ff commit 4468bcf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 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 @@ -72,13 +73,14 @@ struct App {
ImFont *fontIconsSolidBig;
ImFont *fontIconsSolidLarge;
std::chrono::seconds editPaneCloseDelay{ 15 };
// The thread limit here is mainly for emscripten
std::shared_ptr<gr::thread_pool::BasicThreadPool> schedulerThreadPool = std::make_shared<gr::thread_pool::BasicThreadPool>("scheduler-pool", gr::thread_pool::CPU_BOUND, 2, 4);

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

m_scheduler.emplace<Scheduler>(std::forward<Graph>(graph), schedulerThreadPool);
}

private:
Expand All @@ -97,24 +99,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 4468bcf

Please sign in to comment.