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
8b57944e
Commit
8b57944e
authored
Nov 13, 2014
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix wait_for to work with RIOT vtimer
wait_until is not working, however (chrono is not available in RIOT).
parent
5f0fd702
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
51 deletions
+19
-51
libcaf_core/caf/condition_variable.hpp
libcaf_core/caf/condition_variable.hpp
+19
-15
libcaf_core/src/condition_variable.cpp
libcaf_core/src/condition_variable.cpp
+0
-36
No files found.
libcaf_core/caf/condition_variable.hpp
View file @
8b57944e
...
...
@@ -27,6 +27,11 @@
#include "mutex.hpp"
extern
"C"
{
#include "sched.h"
#include "vtimer.h"
}
namespace
caf
{
enum
class
cv_status
{
no_timeout
,
timeout
};
...
...
@@ -36,7 +41,6 @@ class condition_variable {
public:
using
native_handle_type
=
priority_queue_t
*
;
// constexpr condition_variable() : m_queue{NULL} { }
inline
condition_variable
()
{
m_queue
.
first
=
NULL
;
}
...
...
@@ -68,10 +72,6 @@ class condition_variable {
condition_variable
(
const
condition_variable
&
);
condition_variable
&
operator
=
(
const
condition_variable
&
);
void
do_timed_wait
(
unique_lock
<
mutex
>&
lock
,
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
,
std
::
chrono
::
nanoseconds
>
)
noexcept
;
priority_queue_t
m_queue
;
};
...
...
@@ -122,18 +122,22 @@ cv_status condition_variable::wait_for(unique_lock<mutex>& lock,
if
(
timeout_duration
<=
timeout_duration
.
zero
())
{
return
cv_status
::
timeout
;
}
typedef
time_point
<
system_clock
,
duration
<
long
double
,
std
::
nano
>>
tpf
;
typedef
time_point
<
system_clock
,
nanoseconds
>
tpi
;
tpf
tpf_max
=
tpi
::
max
();
system_clock
::
time_point
sys_now
=
system_clock
::
now
();
steady_clock
::
time_point
sdy_now
=
steady_clock
::
now
();
if
(
tpf_max
-
timeout_duration
>
sys_now
)
{
do_timed_wait
(
lock
,
sys_now
+
ceil
<
nanoseconds
>
(
timeout_duration
));
timex_t
timeout
,
before
,
after
;
auto
s
=
duration_cast
<
seconds
>
(
timeout_duration
);
timeout
.
seconds
=
s
.
count
();
timeout
.
microseconds
=
(
duration_cast
<
microseconds
>
(
timeout_duration
)
-
s
).
count
();
vtimer_now
(
&
before
);
vtimer_t
timer
;
vtimer_set_wakeup
(
&
timer
,
timeout
,
sched_active_pid
);
wait
(
lock
);
vtimer_now
(
&
after
);
vtimer_remove
(
&
timer
);
auto
passed
=
timex_sub
(
after
,
before
);
if
(
passed
.
seconds
>=
timeout
.
seconds
&&
passed
.
microseconds
>=
timeout
.
microseconds
)
{
return
cv_status
::
timeout
;
}
else
{
do_timed_wait
(
lock
,
tpi
::
max
())
;
return
cv_status
::
no_timeout
;
}
return
steady_clock
::
now
()
-
sdy_now
<
timeout_duration
?
cv_status
::
no_timeout
:
cv_status
::
timeout
;
}
template
<
class
Rep
,
class
Period
,
class
Predicate
>
...
...
libcaf_core/src/condition_variable.cpp
View file @
8b57944e
...
...
@@ -85,40 +85,4 @@ void condition_variable::wait(unique_lock<mutex>& lock) noexcept {
mutex_lock
(
lock
.
mutex
()
->
native_handle
());
}
void
condition_variable
::
do_timed_wait
(
unique_lock
<
mutex
>&
lock
,
time_point
<
system_clock
,
nanoseconds
>
tp
)
noexcept
{
if
(
!
lock
.
owns_lock
())
{
throw
std
::
runtime_error
(
"condition_variable::timed wait: mutex not locked"
);
}
nanoseconds
d
=
tp
.
time_since_epoch
();
if
(
d
>
nanoseconds
(
0x59682F000000E941
))
{
d
=
nanoseconds
(
0x59682F000000E941
);
}
timespec
ts
;
seconds
s
=
duration_cast
<
seconds
>
(
d
);
typedef
decltype
(
ts
.
tv_sec
)
ts_sec
;
constexpr
ts_sec
ts_sec_max
=
std
::
numeric_limits
<
ts_sec
>::
max
();
if
(
s
.
count
()
<
ts_sec_max
)
{
ts
.
tv_sec
=
static_cast
<
ts_sec
>
(
s
.
count
());
ts
.
tv_nsec
=
static_cast
<
decltype
(
ts
.
tv_nsec
)
>
((
d
-
s
).
count
());
}
else
{
ts
.
tv_sec
=
ts_sec_max
;
ts
.
tv_nsec
=
std
::
giga
::
num
-
1
;
}
timex_t
now
,
then
,
reltime
;
// vtimer_now(&now) does not seem to work, so lets use chrono ...
system_clock
::
time_point
sys_now
=
system_clock
::
now
();
auto
duration
=
sys_now
.
time_since_epoch
();
now
.
seconds
=
duration_cast
<
seconds
>
(
duration
).
count
();
now
.
microseconds
=
(
duration_cast
<
microseconds
>
(
duration
)
-
duration_cast
<
seconds
>
(
duration
)).
count
();
then
.
seconds
=
ts
.
tv_sec
;
then
.
microseconds
=
ts
.
tv_nsec
/
1000u
;
reltime
=
timex_sub
(
then
,
now
);
vtimer_t
timer
;
vtimer_set_wakeup
(
&
timer
,
reltime
,
sched_active_pid
);
wait
(
lock
);
vtimer_remove
(
&
timer
);
}
}
// namespace caf
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