event/Loop: add method SetThread()

Require to call it before calling Run(); remove the setter from Run().
This gives class EventThread more control over when it is initialized.
This commit is contained in:
Max Kellermann
2025-02-01 19:18:57 +01:00
parent b2bf95009b
commit 63cc07b8a7
3 changed files with 9 additions and 2 deletions

@ -269,8 +269,7 @@ void
EventLoop::Run() noexcept EventLoop::Run() noexcept
{ {
#ifdef HAVE_THREADED_EVENT_LOOP #ifdef HAVE_THREADED_EVENT_LOOP
if (thread.IsNull()) assert(!thread.IsNull());
thread = ThreadId::GetCurrent();
#endif #endif
assert(IsInside()); assert(IsInside());

@ -147,6 +147,12 @@ public:
explicit EventLoop(ThreadId _thread); explicit EventLoop(ThreadId _thread);
EventLoop():EventLoop(ThreadId::GetCurrent()) {} EventLoop():EventLoop(ThreadId::GetCurrent()) {}
void SetThread(ThreadId _thread) noexcept {
assert(thread.IsNull());
thread = _thread;
}
#else #else
EventLoop(); EventLoop();
#endif #endif

@ -39,6 +39,8 @@ EventThread::Run() noexcept
{ {
SetThreadName(realtime ? "rtio" : "io"); SetThreadName(realtime ? "rtio" : "io");
event_loop.SetThread(ThreadId::GetCurrent());
if (realtime) { if (realtime) {
SetThreadTimerSlack(std::chrono::microseconds(10)); SetThreadTimerSlack(std::chrono::microseconds(10));