diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/event/IdleMonitor.cxx | 2 | ||||
-rw-r--r-- | src/event/Loop.cxx | 16 | ||||
-rw-r--r-- | src/event/Loop.hxx | 13 |
3 files changed, 30 insertions, 1 deletions
diff --git a/src/event/IdleMonitor.cxx b/src/event/IdleMonitor.cxx index 6e500aa7b..e791559a1 100644 --- a/src/event/IdleMonitor.cxx +++ b/src/event/IdleMonitor.cxx @@ -26,7 +26,7 @@ void IdleMonitor::Cancel() { - assert(loop.IsInside()); + assert(loop.IsInsideOrNull()); if (!IsActive()) return; diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index 7a05ea6b6..e32ba5582 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -57,6 +57,8 @@ EventLoop::Break() bool EventLoop::Abandon(int _fd, SocketMonitor &m) { + assert(IsInside()); + poll_result.Clear(&m); return poll_group.Abandon(_fd); } @@ -64,6 +66,8 @@ EventLoop::Abandon(int _fd, SocketMonitor &m) bool EventLoop::RemoveFD(int _fd, SocketMonitor &m) { + assert(IsInsideOrNull()); + poll_result.Clear(&m); return poll_group.Remove(_fd); } @@ -71,6 +75,7 @@ EventLoop::RemoveFD(int _fd, SocketMonitor &m) void EventLoop::AddIdle(IdleMonitor &i) { + assert(IsInside()); assert(std::find(idle.begin(), idle.end(), &i) == idle.end()); idle.push_back(&i); @@ -79,6 +84,8 @@ EventLoop::AddIdle(IdleMonitor &i) void EventLoop::RemoveIdle(IdleMonitor &i) { + assert(IsInside()); + auto it = std::find(idle.begin(), idle.end(), &i); assert(it != idle.end()); @@ -88,12 +95,16 @@ EventLoop::RemoveIdle(IdleMonitor &i) void EventLoop::AddTimer(TimeoutMonitor &t, unsigned ms) { + assert(IsInside()); + timers.insert(TimerRecord(t, now_ms + ms)); } void EventLoop::CancelTimer(TimeoutMonitor &t) { + assert(IsInsideOrNull()); + for (auto i = timers.begin(), end = timers.end(); i != end; ++i) { if (&i->timer == &t) { timers.erase(i); @@ -176,7 +187,10 @@ EventLoop::Run() } while (!quit); +#ifndef NDEBUG assert(thread.IsInside()); + thread = ThreadId::Null(); +#endif } void @@ -236,6 +250,8 @@ EventLoop::HandleDeferred() bool EventLoop::OnSocketReady(gcc_unused unsigned flags) { + assert(IsInside()); + wake_fd.Read(); mutex.lock(); diff --git a/src/event/Loop.hxx b/src/event/Loop.hxx index b8d090eb5..e8c737e1e 100644 --- a/src/event/Loop.hxx +++ b/src/event/Loop.hxx @@ -102,6 +102,8 @@ public: * A caching wrapper for MonotonicClockMS(). */ unsigned GetTimeMS() const { + assert(IsInside()); + return now_ms; } @@ -113,10 +115,14 @@ public: void Break(); bool AddFD(int _fd, unsigned flags, SocketMonitor &m) { + assert(thread.IsNull() || thread.IsInside()); + return poll_group.Add(_fd, flags, &m); } bool ModifyFD(int _fd, unsigned flags, SocketMonitor &m) { + assert(IsInside()); + return poll_group.Modify(_fd, flags, &m); } @@ -177,6 +183,13 @@ public: return thread.IsInside(); } + +#ifndef NDEBUG + gcc_pure + bool IsInsideOrNull() const { + return thread.IsNull() || thread.IsInside(); + } +#endif }; #endif /* MAIN_NOTIFY_H */ |