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
40118998
Commit
40118998
authored
Dec 27, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
system/PeriodClock: use std::chrono::steady_clock
parent
28e743ba
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
25 deletions
+27
-25
Volume.cxx
src/mixer/Volume.cxx
+1
-1
OutputControl.cxx
src/output/OutputControl.cxx
+2
-2
PeriodClock.hxx
src/system/PeriodClock.hxx
+24
-22
No files found.
src/mixer/Volume.cxx
View file @
40118998
...
...
@@ -52,7 +52,7 @@ int
volume_level_get
(
const
MultipleOutputs
&
outputs
)
{
if
(
last_hardware_volume
>=
0
&&
!
hardware_volume_clock
.
CheckUpdate
(
1000
))
!
hardware_volume_clock
.
CheckUpdate
(
std
::
chrono
::
seconds
(
1
)
))
/* throttle access to hardware mixers */
return
last_hardware_volume
;
...
...
src/output/OutputControl.cxx
View file @
40118998
...
...
@@ -30,9 +30,9 @@
#include <assert.h>
/** after a failure, wait this
number of seconds
before
/** after a failure, wait this
duration
before
automatically reopening the device */
static
constexpr
unsigned
REOPEN_AFTER
=
10
;
static
constexpr
PeriodClock
::
Duration
REOPEN_AFTER
=
std
::
chrono
::
seconds
(
10
)
;
struct
notify
audio_output_client_notify
;
...
...
src/system/PeriodClock.hxx
View file @
40118998
...
...
@@ -20,15 +20,17 @@
#ifndef MPD_PERIOD_CLOCK_HXX
#define MPD_PERIOD_CLOCK_HXX
#include
"Clock.hxx"
#include
<chrono>
/**
* This is a stopwatch which saves the timestamp of an event, and can
* check whether a specified time span has passed since then.
*/
class
PeriodClock
{
protected
:
typedef
unsigned
Stamp
;
public
:
typedef
std
::
chrono
::
steady_clock
::
duration
Duration
;
typedef
Duration
Delta
;
typedef
std
::
chrono
::
steady_clock
::
time_point
Stamp
;
private
:
Stamp
last
;
...
...
@@ -41,20 +43,20 @@ public:
* object.
*/
constexpr
PeriodClock
()
:
last
(
0
)
{}
PeriodClock
()
:
last
()
{}
protected
:
static
Stamp
GetNow
()
{
return
MonotonicClockMS
();
return
std
::
chrono
::
steady_clock
::
now
();
}
constexpr
int
Elapsed
(
Stamp
now
)
const
{
return
last
==
0
?
-
1
:
now
-
last
;
constexpr
Delta
Elapsed
(
Stamp
now
)
const
{
return
last
==
Stamp
()
?
Delta
(
-
1
)
:
Delta
(
now
-
last
)
;
}
constexpr
bool
Check
(
Stamp
now
,
unsigned
duration
)
const
{
constexpr
bool
Check
(
Stamp
now
,
Duration
duration
)
const
{
return
now
>=
last
+
duration
;
}
...
...
@@ -64,30 +66,30 @@ protected:
public
:
constexpr
bool
IsDefined
()
const
{
return
last
!=
0
;
return
last
>
Stamp
()
;
}
/**
* Resets the clock.
*/
void
Reset
()
{
last
=
0
;
last
=
Stamp
()
;
}
/**
* Returns the
number of milliseconds elapsed since the last
*
update(). Returns -1
if update() was never called.
* Returns the
time elapsed since the last update(). Returns
*
a negative value
if update() was never called.
*/
int
Elapsed
()
const
{
Delta
Elapsed
()
const
{
return
Elapsed
(
GetNow
());
}
/**
* Combines a call to Elapsed() and Update().
*/
int
ElapsedUpdate
()
{
Delta
ElapsedUpdate
()
{
const
auto
now
=
GetNow
();
int
result
=
Elapsed
(
now
);
const
auto
result
=
Elapsed
(
now
);
Update
(
now
);
return
result
;
}
...
...
@@ -96,9 +98,9 @@ public:
* Checks whether the specified duration has passed since the last
* update.
*
* @param duration the duration
in milliseconds
* @param duration the duration
*/
bool
Check
(
unsigned
duration
)
const
{
bool
Check
(
Duration
duration
)
const
{
return
Check
(
GetNow
(),
duration
);
}
...
...
@@ -113,7 +115,7 @@ public:
* Updates the time stamp, setting it to the current clock plus the
* specified offset.
*/
void
UpdateWithOffset
(
int
offset
)
{
void
UpdateWithOffset
(
Delta
offset
)
{
Update
(
GetNow
()
+
offset
);
}
...
...
@@ -123,7 +125,7 @@ public:
*
* @param duration the duration in milliseconds
*/
bool
CheckUpdate
(
unsigned
duration
)
{
bool
CheckUpdate
(
Duration
duration
)
{
Stamp
now
=
GetNow
();
if
(
Check
(
now
,
duration
))
{
Update
(
now
);
...
...
@@ -138,7 +140,7 @@ public:
*
* @param duration the duration in milliseconds
*/
bool
CheckAlwaysUpdate
(
unsigned
duration
)
{
bool
CheckAlwaysUpdate
(
Duration
duration
)
{
Stamp
now
=
GetNow
();
bool
ret
=
Check
(
now
,
duration
);
Update
(
now
);
...
...
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