STM32 driver: Space optimized SystemClock constructor

This commit is contained in:
Pavel Kirienko 2014-04-10 21:23:57 +04:00
parent 1c741016bf
commit 01328da9eb
2 changed files with 11 additions and 5 deletions

View File

@ -59,8 +59,6 @@ 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); }

View File

@ -217,16 +217,24 @@ uavcan::uint32_t getUtcAjdustmentJumpCount()
} // namespace clock
SystemClock SystemClock::self;
SystemClock& SystemClock::instance()
{
MutexLocker mlocker(clock::mutex);
static union SystemClockStorage
{
uavcan::uint8_t buffer[sizeof(SystemClock)];
long long _aligner_1;
long double _aligner_2;
} storage;
SystemClock* const ptr = reinterpret_cast<SystemClock*>(storage.buffer);
if (!clock::initialized)
{
clock::init();
new (ptr) SystemClock();
}
return self;
return *ptr;
}
} // namespace uavcan_stm32