Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
62689557
Commit
62689557
authored
Jan 05, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/Loop: add thread-safety assertions
parent
4ddfc6e9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
1 deletion
+30
-1
IdleMonitor.cxx
src/event/IdleMonitor.cxx
+1
-1
Loop.cxx
src/event/Loop.cxx
+16
-0
Loop.hxx
src/event/Loop.hxx
+13
-0
No files found.
src/event/IdleMonitor.cxx
View file @
62689557
...
...
@@ -26,7 +26,7 @@
void
IdleMonitor
::
Cancel
()
{
assert
(
loop
.
IsInside
());
assert
(
loop
.
IsInside
OrNull
());
if
(
!
IsActive
())
return
;
...
...
src/event/Loop.cxx
View file @
62689557
...
...
@@ -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
();
...
...
src/event/Loop.hxx
View file @
62689557
...
...
@@ -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 */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment