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
14986b15
Commit
14986b15
authored
Feb 09, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
event/Loop: use std::lock_guard
parent
9e503b21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
32 deletions
+32
-32
Loop.cxx
src/event/Loop.cxx
+32
-32
No files found.
src/event/Loop.cxx
View file @
14986b15
...
...
@@ -181,17 +181,17 @@ EventLoop::Run()
/* try to handle DeferredMonitors without WakeFD
overhead */
mutex
.
lock
();
HandleDeferred
(
);
busy
=
false
;
const
bool
_again
=
again
;
mutex
.
unlock
();
if
(
_again
)
/* re-evaluate timers because one of the
IdleMonitors may have added a new
timeout */
continue
;
{
const
std
::
lock_guard
<
Mutex
>
lock
(
mutex
);
HandleDeferred
()
;
busy
=
false
;
if
(
again
)
/* re-evaluate timers because one of
the IdleMonitors may have added a
new timeout */
continue
;
}
/* wait for new event */
...
...
@@ -199,9 +199,10 @@ EventLoop::Run()
now
=
std
::
chrono
::
steady_clock
::
now
();
mutex
.
lock
();
busy
=
true
;
mutex
.
unlock
();
{
const
std
::
lock_guard
<
Mutex
>
lock
(
mutex
);
busy
=
true
;
}
/* invoke sockets */
for
(
int
i
=
0
;
i
<
poll_result
.
GetSize
();
++
i
)
{
...
...
@@ -230,23 +231,24 @@ EventLoop::Run()
void
EventLoop
::
AddDeferred
(
DeferredMonitor
&
d
)
{
mutex
.
lock
();
if
(
d
.
pending
)
{
mutex
.
unlock
();
return
;
}
bool
must_wake
;
{
const
std
::
lock_guard
<
Mutex
>
lock
(
mutex
);
if
(
d
.
pending
)
return
;
assert
(
std
::
find
(
deferred
.
begin
(),
deferred
.
end
(),
&
d
)
==
deferred
.
end
());
assert
(
std
::
find
(
deferred
.
begin
(),
deferred
.
end
(),
&
d
)
==
deferred
.
end
());
/* we don't need to wake up the EventLoop if another
DeferredMonitor has already done it */
const
bool
must_wake
=
!
busy
&&
deferred
.
empty
();
/* we don't need to wake up the EventLoop if another
DeferredMonitor has already done it */
must_wake
=
!
busy
&&
deferred
.
empty
();
d
.
pending
=
true
;
deferred
.
push_back
(
&
d
);
again
=
true
;
mutex
.
unlock
();
d
.
pending
=
true
;
deferred
.
push_back
(
&
d
);
again
=
true
;
}
if
(
must_wake
)
wake_fd
.
Write
();
...
...
@@ -281,9 +283,8 @@ EventLoop::HandleDeferred()
deferred
.
pop_front
();
m
.
pending
=
false
;
mutex
.
unlock
(
);
const
ScopeUnlock
unlock
(
mutex
);
m
.
RunDeferred
();
mutex
.
lock
();
}
}
...
...
@@ -294,9 +295,8 @@ EventLoop::OnSocketReady(gcc_unused unsigned flags)
wake_fd
.
Read
();
mutex
.
lock
(
);
const
std
::
lock_guard
<
Mutex
>
lock
(
mutex
);
HandleDeferred
();
mutex
.
unlock
();
return
true
;
}
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