Skip to content
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

Fix NimBLEDevice::init() deadlock problem #584

Open
wants to merge 1 commit into
base: release/1.4
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions src/NimBLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ NimBLEServer* NimBLEDevice::m_pServer = nullptr;
#endif
uint32_t NimBLEDevice::m_passkey = 123456;
bool NimBLEDevice::m_synced = false;
SemaphoreHandle_t m_synced_sem = xSemaphoreCreateBinary();
#if defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER)
# if CONFIG_BT_NIMBLE_EXT_ADV
NimBLEExtAdvertising* NimBLEDevice::m_bleAdvertising = nullptr;
Expand Down Expand Up @@ -807,6 +808,7 @@ void NimBLEDevice::onSync(void)
taskYIELD();

m_synced = true;
xSemaphoreGive(m_synced_sem);

if(initialized) {
#if defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
Expand Down Expand Up @@ -906,6 +908,7 @@ void NimBLEDevice::init(const std::string &deviceName) {
}

// Wait for host and controller to sync before returning and accepting new tasks
xSemaphoreTake(m_synced_sem, portMAX_DELAY);
while(!m_synced){
taskYIELD();
}
Expand Down