Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
8514ba31
Commit
8514ba31
authored
Oct 25, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(PassiveTimer): перешёл на ещё более "глубокое" использование std::chrono
(убрал сравнение timeout_t и std::chrono::milliseconds).
parent
ac4ee7d1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
4 deletions
+16
-4
PassiveTimer.h
include/PassiveTimer.h
+8
-2
PassiveTimer.cc
src/Timers/PassiveTimer.cc
+7
-1
test_passivetimer.cc
tests/test_passivetimer.cc
+1
-1
No files found.
include/PassiveTimer.h
View file @
8514ba31
...
...
@@ -99,7 +99,6 @@ class PassiveTimer:
PassiveTimer
(
timeout_t
msec
);
/*!< установить таймер */
virtual
~
PassiveTimer
();
virtual
bool
checkTime
()
const
;
/*!< проверка наступления заданного времени */
virtual
timeout_t
setTiming
(
timeout_t
msec
);
/*!< установить таймер и запустить. timeMS = 0 вызовет немедленное срабатывание */
virtual
void
reset
();
/*!< перезапустить таймер */
...
...
@@ -113,8 +112,15 @@ class PassiveTimer:
virtual
void
terminate
();
/*!< прервать работу таймера */
protected
:
timeout_t
t_msec
=
{
0
};
/*!< интервал таймера, в милисекундах */
timeout_t
t_msec
=
{
0
};
/*!< интервал таймера, в милисекундах (для "пользователей") */
// Т.к. НЕ ВЕСЬ КОД переведён на использование std::chrono
// везде используется timeout_t (и WaitUpTime)
// отделяем внутреннее (теперь уже стандартное >= c++11)
// представление для работы со временем (std::chrono)
// и тип (t_msec) для "пользователей"
std
::
chrono
::
high_resolution_clock
::
time_point
t_start
;
/*!< время установки таймера (сброса) */
std
::
chrono
::
milliseconds
t_inner_msec
;
/*!< время установки таймера, мсек (в единицах std::chrono) */
private
:
};
...
...
src/Timers/PassiveTimer.cc
View file @
8514ba31
...
...
@@ -53,7 +53,7 @@ bool PassiveTimer::checkTime() const
if
(
t_msec
==
0
)
return
true
;
return
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
high_resolution_clock
::
now
()
-
t_start
).
count
()
>=
t_
msec
);
return
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
high_resolution_clock
::
now
()
-
t_start
).
count
()
>=
t_
inner_msec
.
count
()
);
}
//------------------------------------------------------------------------------
...
...
@@ -61,6 +61,12 @@ bool PassiveTimer::checkTime() const
timeout_t
PassiveTimer
::
setTiming
(
timeout_t
msec
)
{
t_msec
=
msec
;
// не знаю как по другому
// приходиться делать это через промежуточную переменную
std
::
chrono
::
milliseconds
ms
(
msec
);
t_inner_msec
=
std
::
move
(
ms
);
PassiveTimer
::
reset
();
return
getInterval
();
}
...
...
tests/test_passivetimer.cc
View file @
8514ba31
...
...
@@ -50,7 +50,7 @@ TEST_CASE("PassiveTimer", "[PassiveTimer]" )
SECTION
(
"Check working"
)
{
PassiveTimer
pt
(
100
);
msleep
(
120
);
// т.к. точность +-10 мсек.. делаем паузу
60.. а проверяем 50
msleep
(
120
);
// т.к. точность +-10 мсек.. делаем паузу
больше чем задана..
REQUIRE
(
pt
.
getCurrent
()
>=
110
);
CHECK
(
pt
.
checkTime
()
);
INFO
(
"Check reset"
);
...
...
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