fix: pthread_mutex_unlock unlock and update owner atomically
Added scheduler suspend to unlock and  the owner atomically
@@ -297,6 +297,10 @@ int pthread_mutex_unlock( pthread_mutex_t * mutex )
if( iStatus == 0 )
{
+ /* Suspend the sheduler so that
+ * mutex is unlocked AND owner is updated atomically */
+ vTaskSuspendAll();
+
/* Call the correct FreeRTOS mutex unlock function based on mutex type. */
if( pxMutex->xAttr.iType == PTHREAD_MUTEX_RECURSIVE )
{
@@ -310,6 +314,9 @@ int pthread_mutex_unlock( pthread_mutex_t * mutex )
/* Update the owner of the mutex. A recursive mutex may still have an
* owner, so it should be updated with xSemaphoreGetMutexHolder. */
pxMutex->xTaskOwner = xSemaphoreGetMutexHolder( ( SemaphoreHandle_t ) &pxMutex->xMutex );
+
+ /* Resume the scheduler */
+ ( void ) xTaskResumeAll();
}
return iStatus;
