|
|
@ -20,6 +20,7 @@
|
|
|
|
#ifndef SRSLTE_TIMERS_H
|
|
|
|
#ifndef SRSLTE_TIMERS_H
|
|
|
|
#define SRSLTE_TIMERS_H
|
|
|
|
#define SRSLTE_TIMERS_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "srslte/adt/move_callback.h"
|
|
|
|
#include "srslte/phy/utils/debug.h"
|
|
|
|
#include "srslte/phy/utils/debug.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
|
|
|
#include <functional>
|
|
|
@ -49,7 +50,7 @@ class timer_handler
|
|
|
|
uint32_t duration = 0, timeout = 0;
|
|
|
|
uint32_t duration = 0, timeout = 0;
|
|
|
|
bool running = false;
|
|
|
|
bool running = false;
|
|
|
|
bool active = false;
|
|
|
|
bool active = false;
|
|
|
|
std::function<void(uint32_t)> callback;
|
|
|
|
srslte::move_callback<void(uint32_t)> callback;
|
|
|
|
|
|
|
|
|
|
|
|
explicit timer_impl(timer_handler* parent_) : parent(parent_) {}
|
|
|
|
explicit timer_impl(timer_handler* parent_) : parent(parent_) {}
|
|
|
|
|
|
|
|
|
|
|
@ -79,7 +80,7 @@ class timer_handler
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool set(uint32_t duration_, std::function<void(int)> callback_)
|
|
|
|
bool set(uint32_t duration_, srslte::move_callback<void(uint32_t)> callback_)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (set(duration_)) {
|
|
|
|
if (set(duration_)) {
|
|
|
|
callback = std::move(callback_);
|
|
|
|
callback = std::move(callback_);
|
|
|
@ -113,7 +114,7 @@ class timer_handler
|
|
|
|
stop();
|
|
|
|
stop();
|
|
|
|
duration = 0;
|
|
|
|
duration = 0;
|
|
|
|
active = false;
|
|
|
|
active = false;
|
|
|
|
callback = std::function<void(uint32_t)>();
|
|
|
|
callback = srslte::move_callback<void(uint32_t)>();
|
|
|
|
// leave run_id unchanged. Since the timeout was changed, we shall not get spurious triggering
|
|
|
|
// leave run_id unchanged. Since the timeout was changed, we shall not get spurious triggering
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -121,7 +122,7 @@ class timer_handler
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (is_running()) {
|
|
|
|
if (is_running()) {
|
|
|
|
running = false;
|
|
|
|
running = false;
|
|
|
|
if (callback) {
|
|
|
|
if (not callback.is_empty()) {
|
|
|
|
callback(id());
|
|
|
|
callback(id());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -164,7 +165,10 @@ public:
|
|
|
|
|
|
|
|
|
|
|
|
bool is_valid() const { return parent != nullptr; }
|
|
|
|
bool is_valid() const { return parent != nullptr; }
|
|
|
|
|
|
|
|
|
|
|
|
void set(uint32_t duration_, const std::function<void(int)>& callback_) { impl()->set(duration_, callback_); }
|
|
|
|
void set(uint32_t duration_, move_callback<void(uint32_t)> callback_)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
impl()->set(duration_, std::move(callback_));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void set(uint32_t duration_) { impl()->set(duration_); }
|
|
|
|
void set(uint32_t duration_) { impl()->set(duration_); }
|
|
|
|
|
|
|
|
|
|
|
@ -271,7 +275,7 @@ public:
|
|
|
|
void defer_callback(uint32_t duration, const F& func)
|
|
|
|
void defer_callback(uint32_t duration, const F& func)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32_t id = alloc_timer();
|
|
|
|
uint32_t id = alloc_timer();
|
|
|
|
std::function<void(uint32_t)> c = [func, this, id](uint32_t tid) {
|
|
|
|
srslte::move_callback<void(uint32_t)> c = [func, this, id](uint32_t tid) {
|
|
|
|
func();
|
|
|
|
func();
|
|
|
|
// auto-deletes timer
|
|
|
|
// auto-deletes timer
|
|
|
|
timer_list[id].clear();
|
|
|
|
timer_list[id].clear();
|
|
|
|