Skip to content

Commit 63cc07b

Browse files
committed
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.
1 parent b2bf950 commit 63cc07b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/event/Loop.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ void
269269
EventLoop::Run() noexcept
270270
{
271271
#ifdef HAVE_THREADED_EVENT_LOOP
272-
if (thread.IsNull())
273-
thread = ThreadId::GetCurrent();
272+
assert(!thread.IsNull());
274273
#endif
275274

276275
assert(IsInside());

src/event/Loop.hxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ public:
147147
explicit EventLoop(ThreadId _thread);
148148

149149
EventLoop():EventLoop(ThreadId::GetCurrent()) {}
150+
151+
void SetThread(ThreadId _thread) noexcept {
152+
assert(thread.IsNull());
153+
154+
thread = _thread;
155+
}
150156
#else
151157
EventLoop();
152158
#endif

src/event/Thread.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ EventThread::Run() noexcept
3939
{
4040
SetThreadName(realtime ? "rtio" : "io");
4141

42+
event_loop.SetThread(ThreadId::GetCurrent());
43+
4244
if (realtime) {
4345
SetThreadTimerSlack(std::chrono::microseconds(10));
4446

0 commit comments

Comments
 (0)