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
90951670
Commit
90951670
authored
May 07, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
thread/*Cond: add wait_for() overload with predicate
parent
ad4ca0c4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
5 deletions
+27
-5
Blocking.hxx
src/lib/nfs/Blocking.hxx
+1
-5
PosixCond.hxx
src/thread/PosixCond.hxx
+13
-0
WindowsCond.hxx
src/thread/WindowsCond.hxx
+13
-0
No files found.
src/lib/nfs/Blocking.hxx
View file @
90951670
...
...
@@ -60,11 +60,7 @@ public:
private
:
bool
LockWaitFinished
()
noexcept
{
std
::
unique_lock
<
Mutex
>
lock
(
mutex
);
while
(
!
finished
)
if
(
!
cond
.
wait_for
(
lock
,
timeout
))
return
false
;
return
true
;
return
cond
.
wait_for
(
lock
,
timeout
,
[
this
]{
return
finished
;
});
}
/**
...
...
src/thread/PosixCond.hxx
View file @
90951670
...
...
@@ -105,6 +105,19 @@ public:
return
wait_for
(
lock
,
timeout_us
);
}
template
<
typename
M
,
typename
P
>
bool
wait_for
(
std
::
unique_lock
<
M
>
&
lock
,
std
::
chrono
::
steady_clock
::
duration
timeout
,
P
&&
predicate
)
noexcept
{
while
(
!
predicate
())
{
// TODO: without wait_until(), this multiplies the timeout
if
(
!
wait_for
(
lock
,
timeout
))
return
predicate
();
}
return
true
;
}
};
#endif
src/thread/WindowsCond.hxx
View file @
90951670
...
...
@@ -70,6 +70,19 @@ public:
&
lock
.
mutex
()
->
critical_section
,
timeout_ms
);
}
template
<
typename
M
,
typename
P
>
bool
wait_for
(
std
::
unique_lock
<
M
>
&
lock
,
std
::
chrono
::
steady_clock
::
duration
timeout
,
P
&&
predicate
)
noexcept
{
while
(
!
predicate
())
{
// TODO: without wait_until(), this multiplies the timeout
if
(
!
wait_for
(
lock
,
timeout
))
return
predicate
();
}
return
true
;
}
};
#endif
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