Skip to content

Commit b8df3da

Browse files
Re-inline IOController scheduler wiring.
Undo SonarCloud duplication refactor: delete IOController_Common.ipp and restore inline bump reactions, shutdown control, and poll loop registration in the platform .ipp files. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 62617d2 commit b8df3da

5 files changed

Lines changed: 42 additions & 99 deletions

File tree

src/extension/IOController.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@
2525
#else
2626
#include "IOController_Posix.ipp"
2727
#endif // _WIN32
28-
29-
#include "IOController_Common.ipp"

src/extension/IOController.hpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "../util/platform.hpp"
2929

3030
#include <atomic>
31-
#include <functional>
3231

3332
namespace NUClear {
3433
namespace extension {
@@ -127,25 +126,6 @@ namespace extension {
127126
*/
128127
void bump() const;
129128

130-
/// Inline bump reactions that wake the poll task from the emitting thread.
131-
void register_inline_bump_reactions();
132-
133-
/// HIGH-priority shutdown handler on the IO pool.
134-
void register_shutdown_control();
135-
136-
/**
137-
* Registers the self-resubmitting poll task.
138-
*
139-
* @param wait_and_process platform-specific blocking wait and event dispatch
140-
*/
141-
void register_poll_loop(std::function<void()> wait_and_process);
142-
143-
/// Returns false when the poll loop should exit without blocking.
144-
bool prepare_poll_iteration();
145-
146-
/// Resubmits the poll reaction after one blocking iteration.
147-
void resubmit_poll_task();
148-
149129
public:
150130
explicit IOController(std::unique_ptr<NUClear::Environment> environment);
151131

src/extension/IOController_Common.ipp

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/extension/IOController_Posix.ipp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "IOController.hpp"
2424

25+
#include "../threading/ReactionTask.hpp"
26+
2527
namespace NUClear {
2628
namespace extension {
2729

@@ -176,6 +178,7 @@ namespace extension {
176178
std::sort(tasks.begin(), tasks.end());
177179
dirty.store(true, std::memory_order_release);
178180
});
181+
on<Trigger<dsl::word::IOConfiguration>, Inline::ALWAYS>().then("Configure IO bump", [this] { bump(); });
179182

180183
on<Trigger<dsl::word::IOFinished>, Pool<IOPool>, Priority::HIGH, Inline::NEVER>().then("IO Finished", [this](const dsl::word::IOFinished& event) {
181184
auto task = std::find_if(tasks.begin(), tasks.end(), [&event](const Task& t) {
@@ -201,6 +204,7 @@ namespace extension {
201204
}
202205
}
203206
});
207+
on<Trigger<dsl::word::IOFinished>, Inline::ALWAYS>().then("IO Finished bump", [this] { bump(); });
204208

205209
on<Trigger<dsl::operation::Unbind<IO>>, Pool<IOPool>, Priority::HIGH, Inline::NEVER>().then(
206210
"Unbind IO Reaction",
@@ -215,10 +219,22 @@ namespace extension {
215219

216220
dirty.store(true, std::memory_order_release);
217221
});
222+
on<Trigger<dsl::operation::Unbind<IO>>, Inline::ALWAYS>().then("Unbind IO bump", [this] { bump(); });
223+
224+
on<Shutdown, Pool<IOPool>, Priority::HIGH, Inline::NEVER>().then("Shutdown IO Controller", [this] {
225+
running.store(false, std::memory_order_release);
226+
});
227+
on<Shutdown, Inline::ALWAYS>().then("Shutdown IO bump", [this] { bump(); });
228+
229+
on<Startup, Pool<IOPool>, Priority::NORMAL, Inline::NEVER>().then("IO Poll", [this] {
230+
if (!running.load(std::memory_order_acquire)) {
231+
return;
232+
}
233+
234+
if (dirty.load(std::memory_order_acquire)) {
235+
rebuild_list();
236+
}
218237

219-
register_shutdown_control();
220-
register_inline_bump_reactions();
221-
register_poll_loop([this] {
222238
if (::poll(watches.data(), nfds_t(watches.size()), -1) < 0) {
223239
throw std::system_error(network_errno,
224240
std::system_category(),
@@ -230,6 +246,8 @@ namespace extension {
230246
process_event(fd);
231247
}
232248
}
249+
250+
powerplant.submit(threading::ReactionTask::get_current_task()->parent->get_task());
233251
});
234252
}
235253

src/extension/IOController_Windows.ipp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "IOController.hpp"
2424

25+
#include "../threading/ReactionTask.hpp"
26+
2527
namespace NUClear {
2628
namespace extension {
2729

@@ -161,6 +163,7 @@ namespace extension {
161163
tasks.insert(std::make_pair(event, Task{config.fd, config.events, config.reaction}));
162164
dirty.store(true, std::memory_order_release);
163165
});
166+
on<Trigger<dsl::word::IOConfiguration>, Inline::ALWAYS>().then("Configure IO bump", [this] { bump(); });
164167

165168
on<Trigger<dsl::word::IOFinished>, Pool<IOPool>, Priority::HIGH, Inline::NEVER>().then("IO Finished", [this](const dsl::word::IOFinished& event) {
166169
auto it = std::find_if(tasks.begin(), tasks.end(), [&event](const std::pair<WSAEVENT, Task>& t) {
@@ -179,6 +182,7 @@ namespace extension {
179182
}
180183
}
181184
});
185+
on<Trigger<dsl::word::IOFinished>, Inline::ALWAYS>().then("IO Finished bump", [this] { bump(); });
182186

183187
on<Trigger<dsl::operation::Unbind<IO>>, Pool<IOPool>, Priority::HIGH, Inline::NEVER>().then(
184188
"Unbind IO Reaction",
@@ -193,10 +197,22 @@ namespace extension {
193197

194198
dirty.store(true, std::memory_order_release);
195199
});
200+
on<Trigger<dsl::operation::Unbind<IO>>, Inline::ALWAYS>().then("Unbind IO bump", [this] { bump(); });
201+
202+
on<Shutdown, Pool<IOPool>, Priority::HIGH, Inline::NEVER>().then("Shutdown IO Controller", [this] {
203+
running.store(false, std::memory_order_release);
204+
});
205+
on<Shutdown, Inline::ALWAYS>().then("Shutdown IO bump", [this] { bump(); });
206+
207+
on<Startup, Pool<IOPool>, Priority::NORMAL, Inline::NEVER>().then("IO Poll", [this] {
208+
if (!running.load(std::memory_order_acquire)) {
209+
return;
210+
}
211+
212+
if (dirty.load(std::memory_order_acquire)) {
213+
rebuild_list();
214+
}
196215

197-
register_shutdown_control();
198-
register_inline_bump_reactions();
199-
register_poll_loop([this] {
200216
const DWORD event_index = WSAWaitForMultipleEvents(static_cast<DWORD>(watches.size()),
201217
watches.data(),
202218
false,
@@ -207,6 +223,8 @@ namespace extension {
207223
auto& event = watches[event_index - WSA_WAIT_EVENT_0];
208224
process_event(event);
209225
}
226+
227+
powerplant.submit(threading::ReactionTask::get_current_task()->parent->get_task());
210228
});
211229
}
212230

0 commit comments

Comments
 (0)