From b4ac8f214aa6c4f27d27d1a32ed796e52950e6bf Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 22 Sep 2016 11:44:22 +0100 Subject: [PATCH] BLE - Nordic implementation: Move singleton into a function. This change remove BLE code from the binary generated if the user code doesn't use BLE. --- .../targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xn.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xn.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xn.cpp index f09d8bfb37..61d9a38d90 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xn.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xn.cpp @@ -34,7 +34,11 @@ extern "C" { /** * The singleton which represents the nRF51822 transport for the BLE. */ -static nRF5xn deviceInstance; +static nRF5xn& getDeviceInstance() { + static nRF5xn deviceInstance; + return deviceInstance; +} + /** * BLE-API requires an implementation of the following function in order to @@ -48,7 +52,7 @@ createBLEInstance(void) nRF5xn& nRF5xn::Instance(BLE::InstanceID_t instanceId) { - return deviceInstance; + return getDeviceInstance(); } nRF5xn::nRF5xn(void) :