Fix semaphores in IDF & std::string assert (#2728)
* Fix semaphores in IDF & std::string assert Fixes the problem of giving a mutex from a callback with the latest IDF. Also addresses an occasional assert that happens when the btc_task callback gives the semaphore and causes an assert due to both cores potentially writing m_owner concurrently. * Restored m_owner position in wait() as requested * Reapply assert fix and move setting m_owner in ::give() Revert previous revert commit and move setting of m_owner in ::give to before giving the semaphore to prevent race condition possibility.
This commit is contained in:
parent
bea7bd1852
commit
43bf393dbf
@ -68,8 +68,6 @@ uint32_t FreeRTOS::Semaphore::wait(std::string owner) {
|
||||
xSemaphoreTake(m_semaphore, portMAX_DELAY);
|
||||
}
|
||||
|
||||
m_owner = owner;
|
||||
|
||||
if (m_usePthreads) {
|
||||
pthread_mutex_unlock(&m_pthread_mutex);
|
||||
} else {
|
||||
@ -77,7 +75,6 @@ uint32_t FreeRTOS::Semaphore::wait(std::string owner) {
|
||||
}
|
||||
|
||||
log_v("<< wait: Semaphore released: %s", toString().c_str());
|
||||
m_owner = std::string("<N/A>");
|
||||
return m_value;
|
||||
} // wait
|
||||
|
||||
@ -87,7 +84,8 @@ FreeRTOS::Semaphore::Semaphore(std::string name) {
|
||||
if (m_usePthreads) {
|
||||
pthread_mutex_init(&m_pthread_mutex, nullptr);
|
||||
} else {
|
||||
m_semaphore = xSemaphoreCreateMutex();
|
||||
m_semaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(m_semaphore);
|
||||
}
|
||||
|
||||
m_name = name;
|
||||
@ -111,6 +109,8 @@ FreeRTOS::Semaphore::~Semaphore() {
|
||||
*/
|
||||
void FreeRTOS::Semaphore::give() {
|
||||
log_v("Semaphore giving: %s", toString().c_str());
|
||||
m_owner = std::string("<N/A>");
|
||||
|
||||
if (m_usePthreads) {
|
||||
pthread_mutex_unlock(&m_pthread_mutex);
|
||||
} else {
|
||||
@ -120,7 +120,6 @@ void FreeRTOS::Semaphore::give() {
|
||||
// FreeRTOS::sleep(10);
|
||||
// #endif
|
||||
|
||||
m_owner = std::string("<N/A>");
|
||||
} // Semaphore::give
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user