mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-14 06:43:34 +08:00
Fixed singletons in the STM32 test app (http://stackoverflow.com/questions/22985570)
This commit is contained in:
@@ -59,6 +59,8 @@ class SystemClock : public uavcan::ISystemClock, uavcan::Noncopyable
|
||||
{
|
||||
SystemClock() { }
|
||||
|
||||
static SystemClock self;
|
||||
|
||||
virtual uavcan::MonotonicTime getMonotonic() const { return clock::getMonotonic(); }
|
||||
virtual uavcan::UtcTime getUtc() const { return clock::getUtc(); }
|
||||
virtual void adjustUtc(uavcan::UtcDuration adjustment) { clock::adjustUtc(adjustment); }
|
||||
|
||||
@@ -217,6 +217,8 @@ uavcan::uint32_t getUtcAjdustmentJumpCount()
|
||||
|
||||
} // namespace clock
|
||||
|
||||
SystemClock SystemClock::self;
|
||||
|
||||
SystemClock& SystemClock::instance()
|
||||
{
|
||||
MutexLocker mlocker(clock::mutex);
|
||||
@@ -224,8 +226,7 @@ SystemClock& SystemClock::instance()
|
||||
{
|
||||
clock::init();
|
||||
}
|
||||
static SystemClock inst;
|
||||
return inst;
|
||||
return self;
|
||||
}
|
||||
|
||||
} // namespace uavcan_stm32
|
||||
|
||||
@@ -16,10 +16,15 @@ uavcan_stm32::CanInitHelper<> can;
|
||||
|
||||
typedef uavcan::Node<4096> Node;
|
||||
|
||||
uavcan::LazyConstructor<Node> node_;
|
||||
|
||||
Node& getNode()
|
||||
{
|
||||
static Node node(can.driver, uavcan_stm32::SystemClock::instance());
|
||||
return node;
|
||||
if (!node_.isConstructed())
|
||||
{
|
||||
node_.construct<uavcan::ICanDriver&, uavcan::ISystemClock&>(can.driver, uavcan_stm32::SystemClock::instance());
|
||||
}
|
||||
return *node_;
|
||||
}
|
||||
|
||||
void ledSet(bool state)
|
||||
|
||||
Reference in New Issue
Block a user