mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/cpp11-compat: Use ztimer64_usec instead of xtimer
This commit is contained in:
parent
50cd32fbbf
commit
4f6448ed05
@ -417,7 +417,7 @@ endif
|
|||||||
|
|
||||||
ifneq (,$(filter cpp11-compat,$(USEMODULE)))
|
ifneq (,$(filter cpp11-compat,$(USEMODULE)))
|
||||||
USEMODULE += cpp_new_delete
|
USEMODULE += cpp_new_delete
|
||||||
USEMODULE += xtimer
|
USEMODULE += ztimer64_usec
|
||||||
USEMODULE += timex
|
USEMODULE += timex
|
||||||
FEATURES_REQUIRED += cpp
|
FEATURES_REQUIRED += cpp
|
||||||
FEATURES_REQUIRED += libstdcpp
|
FEATURES_REQUIRED += libstdcpp
|
||||||
|
@ -15,6 +15,5 @@ config MODULE_CPP11-COMPAT
|
|||||||
select MODULE_CPP
|
select MODULE_CPP
|
||||||
select MODULE_LIBSTDCPP
|
select MODULE_LIBSTDCPP
|
||||||
select MODULE_CPP_NEW_DELETE
|
select MODULE_CPP_NEW_DELETE
|
||||||
select MODULE_XTIMER
|
select ZTIMER64_USEC
|
||||||
select MODULE_TIMEX
|
select MODULE_TIMEX
|
||||||
select MODULE_ZTIMER64_XTIMER_COMPAT if MODULE_ZTIMER_XTIMER_COMPAT
|
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
#include "sched.h"
|
#include "sched.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "timex.h"
|
#include "time_units.h"
|
||||||
#include "xtimer.h"
|
#include "ztimer64.h"
|
||||||
#include "priority_queue.h"
|
#include "priority_queue.h"
|
||||||
|
|
||||||
#include "riot/condition_variable.hpp"
|
#include "riot/condition_variable.hpp"
|
||||||
@ -99,18 +99,19 @@ void condition_variable::wait(unique_lock<mutex>& lock) noexcept {
|
|||||||
|
|
||||||
cv_status condition_variable::wait_until(unique_lock<mutex>& lock,
|
cv_status condition_variable::wait_until(unique_lock<mutex>& lock,
|
||||||
const time_point& timeout_time) {
|
const time_point& timeout_time) {
|
||||||
xtimer_t timer;
|
ztimer64_t timer;
|
||||||
// todo: use function to wait for absolute timepoint once available
|
uint64_t total_timeout_time_us = timeout_time.microseconds();
|
||||||
timex_t before;
|
total_timeout_time_us += timeout_time.seconds() * US_PER_SEC;
|
||||||
xtimer_now_timex(&before);
|
|
||||||
auto diff = timex_sub(timeout_time.native_handle(), before);
|
ztimer64_set_wakeup_at(ZTIMER64_USEC, &timer, total_timeout_time_us,
|
||||||
xtimer_set_wakeup(&timer, timex_uint64(diff), thread_getpid());
|
thread_getpid());
|
||||||
wait(lock);
|
wait(lock);
|
||||||
timex_t after;
|
if (ztimer64_now(ZTIMER64_USEC) >= total_timeout_time_us) {
|
||||||
xtimer_now_timex(&after);
|
ztimer64_remove(ZTIMER64_USEC, &timer);
|
||||||
xtimer_remove(&timer);
|
return cv_status::timeout;
|
||||||
auto cmp = timex_cmp(after, timeout_time.native_handle());
|
}
|
||||||
return cmp < 1 ? cv_status::no_timeout : cv_status::timeout;
|
ztimer64_remove(ZTIMER64_USEC, &timer);
|
||||||
|
return cv_status::no_timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace riot
|
} // namespace riot
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
*
|
*
|
||||||
* @file
|
* @file
|
||||||
* @brief C++11 chrono drop in replacement that adds the function now based on
|
* @brief C++11 chrono drop in replacement that adds the function now based on
|
||||||
* xtimer/timex
|
* ztimer/timex
|
||||||
* @see <a href="http://en.cppreference.com/w/cpp/thread/thread">
|
* @see <a href="http://en.cppreference.com/w/cpp/thread/thread">
|
||||||
* std::thread, defined in header thread
|
* std::thread, defined in header thread
|
||||||
* </a>
|
* </a>
|
||||||
@ -29,7 +29,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include "xtimer.h"
|
#include "timex.h"
|
||||||
|
#include "ztimer64.h"
|
||||||
|
|
||||||
namespace riot {
|
namespace riot {
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ class time_point {
|
|||||||
*/
|
*/
|
||||||
inline time_point now() {
|
inline time_point now() {
|
||||||
timex_t tp;
|
timex_t tp;
|
||||||
xtimer_now_timex(&tp);
|
tp = timex_from_uint64(ztimer64_now(ZTIMER64_USEC));
|
||||||
return time_point(std::move(tp));
|
return time_point(std::move(tp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#define RIOT_CONDITION_VARIABLE_HPP
|
#define RIOT_CONDITION_VARIABLE_HPP
|
||||||
|
|
||||||
#include "sched.h"
|
#include "sched.h"
|
||||||
#include "xtimer.h"
|
#include "ztimer64.h"
|
||||||
#include "priority_queue.h"
|
#include "priority_queue.h"
|
||||||
|
|
||||||
#include "riot/mutex.hpp"
|
#include "riot/mutex.hpp"
|
||||||
@ -171,20 +171,18 @@ cv_status condition_variable::wait_for(unique_lock<mutex>& lock,
|
|||||||
if (timeout_duration <= timeout_duration.zero()) {
|
if (timeout_duration <= timeout_duration.zero()) {
|
||||||
return cv_status::timeout;
|
return cv_status::timeout;
|
||||||
}
|
}
|
||||||
timex_t timeout, before, after;
|
uint64_t timeout, before, after;
|
||||||
auto s = duration_cast<seconds>(timeout_duration);
|
timeout = (duration_cast<microseconds>(timeout_duration)).count();
|
||||||
timeout.seconds = s.count();
|
before = ztimer64_now(ZTIMER64_USEC);
|
||||||
timeout.microseconds
|
ztimer64_t timer;
|
||||||
= (duration_cast<microseconds>(timeout_duration - s)).count();
|
ztimer64_set_wakeup(ZTIMER64_USEC, &timer, timeout, thread_getpid());
|
||||||
xtimer_now_timex(&before);
|
|
||||||
xtimer_t timer;
|
|
||||||
xtimer_set_wakeup(&timer, timex_uint64(timeout), thread_getpid());
|
|
||||||
wait(lock);
|
wait(lock);
|
||||||
xtimer_now_timex(&after);
|
after = ztimer64_now(ZTIMER64_USEC);
|
||||||
xtimer_remove(&timer);
|
ztimer64_remove(ZTIMER64_USEC, &timer);
|
||||||
auto passed = timex_sub(after, before);
|
if (after - before >= timeout) {
|
||||||
auto cmp = timex_cmp(passed, timeout);
|
return cv_status::timeout;
|
||||||
return cmp < 1 ? cv_status::no_timeout : cv_status::timeout;
|
}
|
||||||
|
return cv_status::no_timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Rep, class Period, class Predicate>
|
template <class Rep, class Period, class Predicate>
|
||||||
|
@ -17,12 +17,10 @@
|
|||||||
*
|
*
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "xtimer.h"
|
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
|
||||||
|
#include "ztimer64.h"
|
||||||
#include "riot/thread.hpp"
|
#include "riot/thread.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -73,7 +71,8 @@ namespace this_thread {
|
|||||||
void sleep_for(const chrono::nanoseconds& ns) {
|
void sleep_for(const chrono::nanoseconds& ns) {
|
||||||
using namespace chrono;
|
using namespace chrono;
|
||||||
if (ns > nanoseconds::zero()) {
|
if (ns > nanoseconds::zero()) {
|
||||||
xtimer_usleep64(static_cast<uint64_t>(duration_cast<microseconds>(ns).count()));
|
ztimer64_sleep(ZTIMER64_USEC,
|
||||||
|
static_cast<uint64_t>(duration_cast<microseconds>(ns).count()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user