Use NimBLE calls for critical sections

This commit is contained in:
h2zero
2021-12-29 08:10:57 -07:00
parent 8620092c90
commit 9debfcd226
7 changed files with 21 additions and 27 deletions
+4 -5
View File
@@ -57,7 +57,6 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
m_pRemoteService = pRemoteService;
m_notifyCallback = nullptr;
m_timestamp = 0;
m_valMux = portMUX_INITIALIZER_UNLOCKED;
NIMBLE_LOGD(LOG_TAG, "<< NimBLERemoteCharacteristic(): %s", m_uuid.toString().c_str());
} // NimBLERemoteCharacteristic
@@ -405,12 +404,12 @@ NimBLEUUID NimBLERemoteCharacteristic::getUUID() {
* @return The value of the remote characteristic.
*/
std::string NimBLERemoteCharacteristic::getValue(time_t *timestamp) {
portENTER_CRITICAL(&m_valMux);
ble_npl_hw_enter_critical();
std::string value = m_value;
if(timestamp != nullptr) {
*timestamp = m_timestamp;
}
portEXIT_CRITICAL(&m_valMux);
ble_npl_hw_exit_critical(0);
return value;
}
@@ -512,13 +511,13 @@ std::string NimBLERemoteCharacteristic::readValue(time_t *timestamp) {
} while(rc != 0 && retryCount--);
time_t t = time(nullptr);
portENTER_CRITICAL(&m_valMux);
ble_npl_hw_enter_critical();
m_value = value;
m_timestamp = t;
if(timestamp != nullptr) {
*timestamp = m_timestamp;
}
portEXIT_CRITICAL(&m_valMux);
ble_npl_hw_exit_critical(0);
NIMBLE_LOGD(LOG_TAG, "<< readValue length: %d rc=%d", value.length(), rc);
return value;