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:
src/event
@ -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));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user