mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-12-22 19:10:46 +01:00
Fix crashing caused by calling time() in a critical section (#159)
* Fix for random notify crash in ISR context Tested for stability over 30 minutes with a daisy chain of 3 esp32 Co-authored-by: h2zero <powellperalta@gmail.com>
This commit is contained in:
parent
a85ac6ad5a
commit
7ed962d963
3 changed files with 6 additions and 3 deletions
|
@ -473,9 +473,10 @@ void NimBLECharacteristic::setValue(const uint8_t* data, size_t length) {
|
|||
return;
|
||||
}
|
||||
|
||||
time_t t = time(nullptr);
|
||||
portENTER_CRITICAL(&m_valMux);
|
||||
m_value = std::string((char*)data, length);
|
||||
m_timestamp = time(nullptr);
|
||||
m_timestamp = t;
|
||||
portEXIT_CRITICAL(&m_valMux);
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< setValue");
|
||||
|
|
|
@ -789,9 +789,10 @@ uint16_t NimBLEClient::getMTU() {
|
|||
if(characteristic != cVector->cend()) {
|
||||
NIMBLE_LOGD(LOG_TAG, "Got Notification for characteristic %s", (*characteristic)->toString().c_str());
|
||||
|
||||
time_t t = time(nullptr);
|
||||
portENTER_CRITICAL(&(*characteristic)->m_valMux);
|
||||
(*characteristic)->m_value = std::string((char *)event->notify_rx.om->om_data, event->notify_rx.om->om_len);
|
||||
(*characteristic)->m_timestamp = time(nullptr);
|
||||
(*characteristic)->m_timestamp = t;
|
||||
portEXIT_CRITICAL(&(*characteristic)->m_valMux);
|
||||
|
||||
if ((*characteristic)->m_notifyCallback != nullptr) {
|
||||
|
|
|
@ -447,9 +447,10 @@ std::string NimBLERemoteCharacteristic::readValue(time_t *timestamp) {
|
|||
}
|
||||
} while(rc != 0 && retryCount--);
|
||||
|
||||
time_t t = time(nullptr);
|
||||
portENTER_CRITICAL(&m_valMux);
|
||||
m_value = value;
|
||||
m_timestamp = time(nullptr);
|
||||
m_timestamp = t;
|
||||
if(timestamp != nullptr) {
|
||||
*timestamp = m_timestamp;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue