Fixed singletons in the STM32 test app (http://stackoverflow.com/questions/22985570)

This commit is contained in:
Pavel Kirienko
2014-04-10 15:06:28 +04:00
parent c26c320dd9
commit d7b34ffd99
3 changed files with 12 additions and 4 deletions
@@ -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)