Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
f715487d
Commit
f715487d
authored
Dec 09, 2014
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix timer implementation in thread
parent
fc6a2e9e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
26 deletions
+21
-26
libcaf_core/caf/thread.hpp
libcaf_core/caf/thread.hpp
+1
-15
libcaf_core/src/thread.cpp
libcaf_core/src/thread.cpp
+20
-11
No files found.
libcaf_core/caf/thread.hpp
View file @
f715487d
...
@@ -120,21 +120,7 @@ namespace this_thread {
...
@@ -120,21 +120,7 @@ namespace this_thread {
sleep_for
(
ns
);
sleep_for
(
ns
);
}
}
}
}
template
<
class
Clock
,
class
Period
>
void
sleep_until
(
const
time_point
&
sleep_time
);
void
sleep_until
(
const
std
::
chrono
::
time_point
<
Clock
,
Period
>&
sleep_time
)
{
using
namespace
std
::
chrono
;
mutex
mtx
;
condition_variable
cv
;
unique_lock
<
mutex
>
lk
(
mtx
);
while
(
now
()
<
sleep_time
)
{
cv
.
wait_until
(
lk
,
sleep_time
);
}
}
template
<
class
Period
>
inline
void
sleep_until
(
const
std
::
chrono
::
time_point
<
std
::
chrono
::
steady_clock
,
Period
>&
sleep_time
)
{
sleep_for
(
sleep_time
-
now
());
}
}
// namespace this_thread
}
// namespace this_thread
class
thread
{
class
thread
{
...
...
libcaf_core/src/thread.cpp
View file @
f715487d
...
@@ -73,22 +73,31 @@ void sleep_for(const chrono::nanoseconds& ns) {
...
@@ -73,22 +73,31 @@ void sleep_for(const chrono::nanoseconds& ns) {
using
namespace
chrono
;
using
namespace
chrono
;
if
(
ns
>
nanoseconds
::
zero
())
{
if
(
ns
>
nanoseconds
::
zero
())
{
seconds
s
=
duration_cast
<
seconds
>
(
ns
);
seconds
s
=
duration_cast
<
seconds
>
(
ns
);
timespec
ts
;
microseconds
ms
=
duration_cast
<
microseconds
>
(
ns
);
using
ts_sec
=
decltype
(
ts
.
tv_sec
);
timex_t
reltime
;
constexpr
ts_sec
ts_sec_max
=
numeric_limits
<
ts_sec
>::
max
();
constexpr
uint32_t
uint32_max
=
numeric_limits
<
uint32_t
>::
max
();
if
(
s
.
count
()
<
ts_sec_max
)
{
if
(
s
.
count
()
<
uint32_max
)
{
ts
.
tv_sec
=
static_cast
<
ts_sec
>
(
s
.
count
());
reltime
.
seconds
=
static_cast
<
uint32_t
>
(
s
.
count
());
ts
.
tv_nsec
=
static_cast
<
decltype
(
ts
.
tv_nsec
)
>
((
ns
-
s
).
count
());
reltime
.
microseconds
=
static_cast
<
uint32_t
>
(
duration_cast
<
microseconds
>
((
ms
-
s
)).
count
());
}
else
{
}
else
{
ts
.
tv_sec
=
ts_sec
_max
;
reltime
.
seconds
=
uint32
_max
;
ts
.
tv_nsec
=
giga
::
num
-
1
;
reltime
.
microseconds
=
uint32_max
;
}
}
timex_t
reltime
;
reltime
.
seconds
=
ts
.
tv_sec
;
reltime
.
microseconds
=
ts
.
tv_nsec
/
1000u
;
vtimer_t
timer
;
vtimer_t
timer
;
vtimer_set_wakeup
(
&
timer
,
reltime
,
sched_active_pid
);
vtimer_set_wakeup
(
&
timer
,
reltime
,
sched_active_pid
);
thread_sleep
();
thread_sleep
();
vtimer_remove
(
&
timer
);
}
}
void
sleep_until
(
const
time_point
&
sleep_time
)
{
using
namespace
std
::
chrono
;
mutex
mtx
;
condition_variable
cv
;
unique_lock
<
mutex
>
lk
(
mtx
);
while
(
now
()
<
sleep_time
)
{
cv
.
wait_until
(
lk
,
sleep_time
);
}
}
}
}
...
...
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