mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-13 15:40:35 +08:00
Renaming: MonotonicDeadlineHandler --> DeadlineHandler
This commit is contained in:
@@ -12,18 +12,18 @@ namespace uavcan
|
||||
|
||||
class Scheduler;
|
||||
|
||||
class MonotonicDeadlineHandler : public LinkedListNode<MonotonicDeadlineHandler>, Noncopyable
|
||||
class DeadlineHandler : public LinkedListNode<DeadlineHandler>, Noncopyable
|
||||
{
|
||||
MonotonicTime deadline_;
|
||||
|
||||
protected:
|
||||
Scheduler& scheduler_;
|
||||
|
||||
explicit MonotonicDeadlineHandler(Scheduler& scheduler)
|
||||
explicit DeadlineHandler(Scheduler& scheduler)
|
||||
: scheduler_(scheduler)
|
||||
{ }
|
||||
|
||||
virtual ~MonotonicDeadlineHandler() { stop(); }
|
||||
virtual ~DeadlineHandler() { stop(); }
|
||||
|
||||
public:
|
||||
virtual void handleDeadline(MonotonicTime current_timestamp) = 0;
|
||||
@@ -40,14 +40,14 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class MonotonicDeadlineScheduler : Noncopyable
|
||||
class DeadlineScheduler : Noncopyable
|
||||
{
|
||||
LinkedListRoot<MonotonicDeadlineHandler> handlers_; // Ordered by deadline, lowest first
|
||||
LinkedListRoot<DeadlineHandler> handlers_; // Ordered by deadline, lowest first
|
||||
|
||||
public:
|
||||
void add(MonotonicDeadlineHandler* mdh);
|
||||
void remove(MonotonicDeadlineHandler* mdh);
|
||||
bool doesExist(const MonotonicDeadlineHandler* mdh) const;
|
||||
void add(DeadlineHandler* mdh);
|
||||
void remove(DeadlineHandler* mdh);
|
||||
bool doesExist(const DeadlineHandler* mdh) const;
|
||||
unsigned int getNumHandlers() const { return handlers_.getLength(); }
|
||||
|
||||
MonotonicTime pollAndGetMonotonicTimestamp(ISystemClock& sysclock);
|
||||
@@ -57,15 +57,15 @@ public:
|
||||
|
||||
class Scheduler : Noncopyable
|
||||
{
|
||||
enum { DefaultMonotonicDeadlineResolutionMs = 5 };
|
||||
enum { MinMonotonicDeadlineResolutionMs = 1 };
|
||||
enum { MaxMonotonicDeadlineResolutionMs = 100 };
|
||||
enum { DefaultDeadlineResolutionMs = 5 };
|
||||
enum { MinDeadlineResolutionMs = 1 };
|
||||
enum { MaxDeadlineResolutionMs = 100 };
|
||||
|
||||
enum { DefaultCleanupPeriodMs = 1000 };
|
||||
enum { MinCleanupPeriodMs = 10 };
|
||||
enum { MaxCleanupPeriodMs = 10000 };
|
||||
|
||||
MonotonicDeadlineScheduler deadline_scheduler_;
|
||||
DeadlineScheduler deadline_scheduler_;
|
||||
Dispatcher dispatcher_;
|
||||
MonotonicTime prev_cleanup_ts_;
|
||||
MonotonicDuration deadline_resolution_;
|
||||
@@ -79,24 +79,24 @@ public:
|
||||
NodeID self_node_id)
|
||||
: dispatcher_(can_driver, allocator, sysclock, otr, self_node_id)
|
||||
, prev_cleanup_ts_(sysclock.getMonotonic())
|
||||
, deadline_resolution_(MonotonicDuration::fromMSec(DefaultMonotonicDeadlineResolutionMs))
|
||||
, deadline_resolution_(MonotonicDuration::fromMSec(DefaultDeadlineResolutionMs))
|
||||
, cleanup_period_(MonotonicDuration::fromMSec(DefaultCleanupPeriodMs))
|
||||
{ }
|
||||
|
||||
int spin(MonotonicTime deadline);
|
||||
|
||||
MonotonicDeadlineScheduler& getMonotonicDeadlineScheduler() { return deadline_scheduler_; }
|
||||
DeadlineScheduler& getDeadlineScheduler() { return deadline_scheduler_; }
|
||||
Dispatcher& getDispatcher() { return dispatcher_; }
|
||||
|
||||
ISystemClock& getSystemClock() { return dispatcher_.getSystemClock(); }
|
||||
MonotonicTime getMonotonicTimestamp() const { return dispatcher_.getSystemClock().getMonotonic(); }
|
||||
UtcTime getUtcTimestamp() const { return dispatcher_.getSystemClock().getUtc(); }
|
||||
|
||||
MonotonicDuration getMonotonicDeadlineResolution() const { return deadline_resolution_; }
|
||||
void setMonotonicDeadlineResolution(MonotonicDuration res)
|
||||
MonotonicDuration getDeadlineResolution() const { return deadline_resolution_; }
|
||||
void setDeadlineResolution(MonotonicDuration res)
|
||||
{
|
||||
res = std::min(res, MonotonicDuration::fromMSec(MaxMonotonicDeadlineResolutionMs));
|
||||
res = std::max(res, MonotonicDuration::fromMSec(MinMonotonicDeadlineResolutionMs));
|
||||
res = std::min(res, MonotonicDuration::fromMSec(MaxDeadlineResolutionMs));
|
||||
res = std::max(res, MonotonicDuration::fromMSec(MinDeadlineResolutionMs));
|
||||
deadline_resolution_ = res;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,20 +29,20 @@ struct TimerEvent
|
||||
};
|
||||
|
||||
|
||||
class Timer : private MonotonicDeadlineHandler
|
||||
class Timer : private DeadlineHandler
|
||||
{
|
||||
MonotonicDuration period_;
|
||||
|
||||
void handleDeadline(MonotonicTime current_timestamp);
|
||||
|
||||
public:
|
||||
using MonotonicDeadlineHandler::stop;
|
||||
using MonotonicDeadlineHandler::isRunning;
|
||||
using MonotonicDeadlineHandler::getDeadline;
|
||||
using MonotonicDeadlineHandler::getScheduler;
|
||||
using DeadlineHandler::stop;
|
||||
using DeadlineHandler::isRunning;
|
||||
using DeadlineHandler::getDeadline;
|
||||
using DeadlineHandler::getScheduler;
|
||||
|
||||
explicit Timer(Scheduler& scheduler)
|
||||
: MonotonicDeadlineHandler(scheduler)
|
||||
: DeadlineHandler(scheduler)
|
||||
, period_(MonotonicDuration::getInfinite())
|
||||
{ }
|
||||
|
||||
|
||||
@@ -11,27 +11,27 @@ namespace uavcan
|
||||
/*
|
||||
* MonotonicDeadlineHandler
|
||||
*/
|
||||
void MonotonicDeadlineHandler::startWithDeadline(MonotonicTime deadline)
|
||||
void DeadlineHandler::startWithDeadline(MonotonicTime deadline)
|
||||
{
|
||||
assert(!deadline.isZero());
|
||||
stop();
|
||||
deadline_ = deadline;
|
||||
scheduler_.getMonotonicDeadlineScheduler().add(this);
|
||||
scheduler_.getDeadlineScheduler().add(this);
|
||||
}
|
||||
|
||||
void MonotonicDeadlineHandler::startWithDelay(MonotonicDuration delay)
|
||||
void DeadlineHandler::startWithDelay(MonotonicDuration delay)
|
||||
{
|
||||
startWithDeadline(scheduler_.getMonotonicTimestamp() + delay);
|
||||
}
|
||||
|
||||
void MonotonicDeadlineHandler::stop()
|
||||
void DeadlineHandler::stop()
|
||||
{
|
||||
scheduler_.getMonotonicDeadlineScheduler().remove(this);
|
||||
scheduler_.getDeadlineScheduler().remove(this);
|
||||
}
|
||||
|
||||
bool MonotonicDeadlineHandler::isRunning() const
|
||||
bool DeadlineHandler::isRunning() const
|
||||
{
|
||||
return scheduler_.getMonotonicDeadlineScheduler().doesExist(this);
|
||||
return scheduler_.getDeadlineScheduler().doesExist(this);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -41,28 +41,28 @@ struct MonotonicDeadlineHandlerInsertionComparator
|
||||
{
|
||||
const MonotonicTime ts;
|
||||
MonotonicDeadlineHandlerInsertionComparator(MonotonicTime ts) : ts(ts) { }
|
||||
bool operator()(const MonotonicDeadlineHandler* t) const
|
||||
bool operator()(const DeadlineHandler* t) const
|
||||
{
|
||||
return t->getDeadline() > ts;
|
||||
}
|
||||
};
|
||||
|
||||
void MonotonicDeadlineScheduler::add(MonotonicDeadlineHandler* mdh)
|
||||
void DeadlineScheduler::add(DeadlineHandler* mdh)
|
||||
{
|
||||
assert(mdh);
|
||||
handlers_.insertBefore(mdh, MonotonicDeadlineHandlerInsertionComparator(mdh->getDeadline()));
|
||||
}
|
||||
|
||||
void MonotonicDeadlineScheduler::remove(MonotonicDeadlineHandler* mdh)
|
||||
void DeadlineScheduler::remove(DeadlineHandler* mdh)
|
||||
{
|
||||
assert(mdh);
|
||||
handlers_.remove(mdh);
|
||||
}
|
||||
|
||||
bool MonotonicDeadlineScheduler::doesExist(const MonotonicDeadlineHandler* mdh) const
|
||||
bool DeadlineScheduler::doesExist(const DeadlineHandler* mdh) const
|
||||
{
|
||||
assert(mdh);
|
||||
const MonotonicDeadlineHandler* p = handlers_.get();
|
||||
const DeadlineHandler* p = handlers_.get();
|
||||
#if UAVCAN_DEBUG
|
||||
MonotonicTime prev_deadline;
|
||||
#endif
|
||||
@@ -80,11 +80,11 @@ bool MonotonicDeadlineScheduler::doesExist(const MonotonicDeadlineHandler* mdh)
|
||||
return false;
|
||||
}
|
||||
|
||||
MonotonicTime MonotonicDeadlineScheduler::pollAndGetMonotonicTimestamp(ISystemClock& sysclock)
|
||||
MonotonicTime DeadlineScheduler::pollAndGetMonotonicTimestamp(ISystemClock& sysclock)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
MonotonicDeadlineHandler* const mdh = handlers_.get();
|
||||
DeadlineHandler* const mdh = handlers_.get();
|
||||
if (!mdh)
|
||||
return sysclock.getMonotonic();
|
||||
#if UAVCAN_DEBUG
|
||||
@@ -103,9 +103,9 @@ MonotonicTime MonotonicDeadlineScheduler::pollAndGetMonotonicTimestamp(ISystemCl
|
||||
return MonotonicTime();
|
||||
}
|
||||
|
||||
MonotonicTime MonotonicDeadlineScheduler::getEarliestDeadline() const
|
||||
MonotonicTime DeadlineScheduler::getEarliestDeadline() const
|
||||
{
|
||||
const MonotonicDeadlineHandler* const mdh = handlers_.get();
|
||||
const DeadlineHandler* const mdh = handlers_.get();
|
||||
if (mdh)
|
||||
return mdh->getDeadline();
|
||||
return MonotonicTime::getMax();
|
||||
|
||||
@@ -25,14 +25,14 @@ void Timer::startOneShotWithDeadline(MonotonicTime deadline)
|
||||
{
|
||||
stop();
|
||||
period_ = MonotonicDuration::getInfinite();
|
||||
MonotonicDeadlineHandler::startWithDeadline(deadline);
|
||||
DeadlineHandler::startWithDeadline(deadline);
|
||||
}
|
||||
|
||||
void Timer::startOneShotWithDelay(MonotonicDuration delay)
|
||||
{
|
||||
stop();
|
||||
period_ = MonotonicDuration::getInfinite();
|
||||
MonotonicDeadlineHandler::startWithDelay(delay);
|
||||
DeadlineHandler::startWithDelay(delay);
|
||||
}
|
||||
|
||||
void Timer::startPeriodic(MonotonicDuration period)
|
||||
@@ -40,7 +40,7 @@ void Timer::startPeriodic(MonotonicDuration period)
|
||||
assert(period < MonotonicDuration::getInfinite());
|
||||
stop();
|
||||
period_ = period;
|
||||
MonotonicDeadlineHandler::startWithDelay(period);
|
||||
DeadlineHandler::startWithDelay(period);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,14 +45,14 @@ TEST(Scheduler, Timers)
|
||||
uavcan::TimerEventForwarder<TimerCallCounter::Binder>
|
||||
b(sch, TimerCallCounter::Binder(&tcc, &TimerCallCounter::callB));
|
||||
|
||||
ASSERT_EQ(0, sch.getMonotonicDeadlineScheduler().getNumHandlers());
|
||||
ASSERT_EQ(0, sch.getDeadlineScheduler().getNumHandlers());
|
||||
|
||||
const uavcan::MonotonicTime start_ts = clock_driver.getMonotonic();
|
||||
|
||||
a.startOneShotWithDeadline(start_ts + durMono(100000));
|
||||
b.startPeriodic(durMono(1000));
|
||||
|
||||
ASSERT_EQ(2, sch.getMonotonicDeadlineScheduler().getNumHandlers());
|
||||
ASSERT_EQ(2, sch.getDeadlineScheduler().getNumHandlers());
|
||||
|
||||
/*
|
||||
* Spinning
|
||||
@@ -82,7 +82,7 @@ TEST(Scheduler, Timers)
|
||||
/*
|
||||
* Deinitialization
|
||||
*/
|
||||
ASSERT_EQ(1, sch.getMonotonicDeadlineScheduler().getNumHandlers());
|
||||
ASSERT_EQ(1, sch.getDeadlineScheduler().getNumHandlers());
|
||||
|
||||
ASSERT_FALSE(a.isRunning());
|
||||
ASSERT_EQ(uavcan::MonotonicDuration::getInfinite(), a.getPeriod());
|
||||
@@ -91,6 +91,6 @@ TEST(Scheduler, Timers)
|
||||
ASSERT_EQ(1000, b.getPeriod().toUSec());
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, sch.getMonotonicDeadlineScheduler().getNumHandlers()); // Both timers were destroyed now
|
||||
ASSERT_EQ(0, sch.getDeadlineScheduler().getNumHandlers()); // Both timers were destroyed now
|
||||
ASSERT_EQ(0, sch.spin(clock_driver.getMonotonic() + durMono(1000))); // Spin some more without timers
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user