diff options
author | Max Kellermann <max@duempel.org> | 2014-01-05 01:40:50 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-05 02:14:31 +0100 |
commit | 626895577840f25c1b0b1f3208310a82c4202d58 (patch) | |
tree | 71329824b174eb19564604c8c9e5bc899b937425 /src/event/Loop.cxx | |
parent | 4ddfc6e9a2930ede249556548bae370b68af0fbc (diff) | |
download | mpd-626895577840f25c1b0b1f3208310a82c4202d58.tar.gz mpd-626895577840f25c1b0b1f3208310a82c4202d58.tar.xz mpd-626895577840f25c1b0b1f3208310a82c4202d58.zip |
event/Loop: add thread-safety assertions
Diffstat (limited to 'src/event/Loop.cxx')
-rw-r--r-- | src/event/Loop.cxx | 16 |
1 files changed, 16 insertions, 0 deletions
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(); |