Skip to content

Commit d8efe71

Browse files
authored
Merge pull request #2778 from pan-/avoid_inclusion_of_ble_code_if_not_used
BLE - Nordic implementation: Move singleton into a function.
2 parents e756048 + e8bddd6 commit d8efe71

File tree

2 files changed

+12
-4
lines changed
  • features/FEATURE_BLE/targets/TARGET_NORDIC

2 files changed

+12
-4
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_MCU_NRF51822/source/nRF5xn.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ extern "C" {
3333
/**
3434
* The singleton which represents the nRF51822 transport for the BLE.
3535
*/
36-
static nRF5xn deviceInstance;
36+
static nRF5xn& getDeviceInstance() {
37+
static nRF5xn deviceInstance;
38+
return deviceInstance;
39+
}
40+
3741

3842
/**
3943
* BLE-API requires an implementation of the following function in order to
@@ -47,7 +51,7 @@ createBLEInstance(void)
4751

4852
nRF5xn& nRF5xn::Instance(BLE::InstanceID_t instanceId)
4953
{
50-
return deviceInstance;
54+
return getDeviceInstance();
5155
}
5256

5357
nRF5xn::nRF5xn(void) :

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xn.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ extern "C" {
3434
/**
3535
* The singleton which represents the nRF51822 transport for the BLE.
3636
*/
37-
static nRF5xn deviceInstance;
37+
static nRF5xn& getDeviceInstance() {
38+
static nRF5xn deviceInstance;
39+
return deviceInstance;
40+
}
41+
3842

3943
/**
4044
* BLE-API requires an implementation of the following function in order to
@@ -48,7 +52,7 @@ createBLEInstance(void)
4852

4953
nRF5xn& nRF5xn::Instance(BLE::InstanceID_t instanceId)
5054
{
51-
return deviceInstance;
55+
return getDeviceInstance();
5256
}
5357

5458
nRF5xn::nRF5xn(void) :

0 commit comments

Comments
 (0)