Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
f5186193
Commit
f5186193
authored
6 years ago
by
Philippe Gorley
Browse files
Options
Downloads
Patches
Plain Diff
thread: wait until condition is fulfilled
Change-Id: I3a8f56aa4d93f73bd1290534e682f7d5f5025c5a
parent
945eec50
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/threadloop.h
+11
-0
11 additions, 0 deletions
src/threadloop.h
with
11 additions
and
0 deletions
src/threadloop.h
+
11
−
0
View file @
f5186193
...
...
@@ -114,6 +114,17 @@ public:
return
cv_
.
wait_for
(
lk
,
rel_time
,
[
this
,
pred
]{
return
isStopping
()
||
pred
();
});
}
template
<
typename
Pred
>
void
wait
(
Pred
&&
pred
)
{
if
(
std
::
this_thread
::
get_id
()
!=
get_id
())
throw
std
::
runtime_error
(
"Can not call wait outside thread context"
);
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutex_
);
cv_
.
wait
(
lk
,
[
this
,
p
=
std
::
move
(
pred
)]{
return
isStopping
()
||
p
();
});
}
private
:
std
::
mutex
mutex_
;
std
::
condition_variable
cv_
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment