-
Notifications
You must be signed in to change notification settings - Fork 90
Restore GAP device name after GATT reset #426
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -891,6 +891,10 @@ bool NimBLEServer::resetGATT() { | |
|
|
||
| ble_gatts_reset(); | ||
| ble_svc_gap_init(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follwed up with: Then we don't need to add any static members. |
||
| if (NimBLEDevice::m_deviceNameSet && !NimBLEDevice::setDeviceName(NimBLEDevice::m_deviceName)) { | ||
| return false; | ||
| } | ||
|
Comment on lines
+894
to
+896
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shiver me timbers! A potential race condition be lurkin' in these waters! Arr matey, while yer logic fer reapplyin' the cached device name be sound as a Spanish doubloon, there be a concurrency concern that could make yer ship run aground: The static members Now, in most BLE applications, these operations be serialized by the nature o' the code flow. But from a library design standpoint, there be no enforcement o' this serialization, savvy? 🏴☠️ Possible solutions fer this concurrency concernOption 1: Document that BLE operations must be serialized by the application (low effort, shifts responsibility to user) Option 2: Add a mutex to protect access to the static members (higher effort, makes library thread-safe by design) // In NimBLEDevice.h, add a static mutex
static std::mutex m_deviceNameMutex;
// In setDeviceName:
{
std::lock_guard<std::mutex> lock(m_deviceNameMutex);
m_deviceName = deviceName;
m_deviceNameSet = true;
}
// In resetGATT:
std::string cachedName;
bool nameWasSet;
{
std::lock_guard<std::mutex> lock(NimBLEDevice::m_deviceNameMutex);
cachedName = NimBLEDevice::m_deviceName;
nameWasSet = NimBLEDevice::m_deviceNameSet;
}
if (nameWasSet && !NimBLEDevice::setDeviceName(cachedName)) {
return false;
}🤖 Prompt for AI Agents |
||
|
|
||
| ble_svc_gatt_init(); | ||
|
|
||
| for (auto svcIt = m_svcVec.begin(); svcIt != m_svcVec.end();) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better if we just added these lines here: