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
871ba5a4
Commit
871ba5a4
authored
Dec 28, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
thread/Cond: add timed_wait() overload with std::chrono support
parent
249e8d59
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
PosixCond.hxx
src/thread/PosixCond.hxx
+13
-0
WindowsCond.hxx
src/thread/WindowsCond.hxx
+8
-0
No files found.
src/thread/PosixCond.hxx
View file @
871ba5a4
...
...
@@ -32,6 +32,8 @@
#include "PosixMutex.hxx"
#include <chrono>
#include <sys/time.h>
/**
...
...
@@ -87,6 +89,17 @@ public:
return
pthread_cond_timedwait
(
&
cond
,
&
mutex
.
mutex
,
&
ts
)
==
0
;
}
bool
timed_wait
(
PosixMutex
&
mutex
,
std
::
chrono
::
steady_clock
::
duration
timeout
)
{
auto
timeout_ms
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
timeout
).
count
();
if
(
timeout_ms
<
0
)
timeout_ms
=
0
;
else
if
(
timeout_ms
>
std
::
numeric_limits
<
unsigned
>::
max
())
timeout_ms
=
std
::
numeric_limits
<
unsigned
>::
max
();
return
timed_wait
(
mutex
,
timeout_ms
);
}
};
#endif
src/thread/WindowsCond.hxx
View file @
871ba5a4
...
...
@@ -32,6 +32,8 @@
#include "CriticalSection.hxx"
#include <chrono>
/**
* Wrapper for a CONDITION_VARIABLE, backend for the Cond class.
*/
...
...
@@ -59,6 +61,12 @@ public:
timeout_ms
);
}
bool
timed_wait
(
CriticalSection
&
mutex
,
std
::
chrono
::
steady_clock
::
duration
timeout
)
{
auto
timeout_ms
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
timeout
).
count
();
return
timed_wait
(
mutex
,
timeout_ms
);
}
void
wait
(
CriticalSection
&
mutex
)
{
timed_wait
(
mutex
,
INFINITE
);
}
...
...
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