diff --git a/features/nanostack/mbed-mesh-api/source/LoWPANNDInterface.cpp b/features/nanostack/mbed-mesh-api/source/LoWPANNDInterface.cpp index 7b911865b7..d660b0968d 100644 --- a/features/nanostack/mbed-mesh-api/source/LoWPANNDInterface.cpp +++ b/features/nanostack/mbed-mesh-api/source/LoWPANNDInterface.cpp @@ -178,8 +178,19 @@ bool LoWPANNDInterface::getRouterIpAddress(char *address, int8_t len) #if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == LOWPAN && DEVICE_802_15_4_PHY MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance() { - static LoWPANNDInterface lowpan(&NanostackRfPhy::get_default_instance()); - - return &lowpan; + static bool inited; + static LoWPANNDInterface interface; + singleton_lock(); + if (!inited) { + nsapi_error_t result = interface.initialize(&NanostackRfPhy::get_default_instance()); + if (result != 0) { + tr_error("LoWPANND initialize failed: %d", error); + singleton_unlock(); + return NULL; + } + inited = true; + } + singleton_unlock(); + return &interface; } #endif diff --git a/features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp b/features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp index 60e16f3fb9..608af2462a 100644 --- a/features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp +++ b/features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp @@ -269,10 +269,22 @@ mesh_error_t Nanostack::ThreadInterface::device_pskd_set(const char *pskd) #define THREAD 0x2345 #if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == THREAD && DEVICE_802_15_4_PHY + MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance() { - static ThreadInterface thread(&NanostackRfPhy::get_default_instance()); - - return &thread; + static bool inited; + static ThreadInterface interface; + singleton_lock(); + if (!inited) { + nsapi_error_t result = interface.initialize(&NanostackRfPhy::get_default_instance()); + if (result != 0) { + tr_error("Thread initialize failed: %d", error); + singleton_unlock(); + return NULL; + } + inited = true; + } + singleton_unlock(); + return &interface; } #endif diff --git a/features/nanostack/mbed-mesh-api/source/WisunInterface.cpp b/features/nanostack/mbed-mesh-api/source/WisunInterface.cpp index 252656a4bb..9952bdc6ea 100644 --- a/features/nanostack/mbed-mesh-api/source/WisunInterface.cpp +++ b/features/nanostack/mbed-mesh-api/source/WisunInterface.cpp @@ -178,8 +178,19 @@ bool WisunInterface::getRouterIpAddress(char *address, int8_t len) #if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance() { - static WisunInterface wisun(&NanostackRfPhy::get_default_instance()); - - return &wisun; + static bool inited; + static WisunInterface interface; + singleton_lock(); + if (!inited) { + nsapi_error_t result = interface.initialize(&NanostackRfPhy::get_default_instance()); + if (result != 0) { + tr_error("Wi-SUN initialize failed: %d", error); + singleton_unlock(); + return NULL; + } + inited = true; + } + singleton_unlock(); + return &interface; } #endif