Skip to content

Initialize the interface at the construction #8975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions features/nanostack/mbed-mesh-api/source/LoWPANNDInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing singleton_unlock here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sinleton_unlock's has been added

}
inited = true;
}
singleton_unlock();
return &interface;
}
#endif
18 changes: 15 additions & 3 deletions features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 14 additions & 3 deletions features/nanostack/mbed-mesh-api/source/WisunInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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