From 92be5d47eea5dd73369c0f35f8022e81726fbd55 Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Sat, 25 Jan 2025 11:23:07 +0000 Subject: [PATCH] Mutex robust APIs are not available on Mac Signed-off-by: Gaurav Aggarwal --- .../GCC/Posix/utils/wait_for_event.c | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c index 443bb7909..55fd7bbfc 100644 --- a/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c +++ b/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c @@ -39,6 +39,7 @@ struct event pthread_cond_t cond; bool event_triggered; }; +/*-----------------------------------------------------------*/ struct event * event_create( void ) { @@ -48,13 +49,16 @@ struct event * event_create( void ) { ev->event_triggered = false; pthread_mutexattr_init( &ev->mutexattr ); - pthread_mutexattr_setrobust( &ev->mutexattr, PTHREAD_MUTEX_ROBUST ); + #ifndef __APPLE__ + pthread_mutexattr_setrobust( &ev->mutexattr, PTHREAD_MUTEX_ROBUST ); + #endif pthread_mutex_init( &ev->mutex, &ev->mutexattr ); pthread_cond_init( &ev->cond, NULL ); } return ev; } +/*-----------------------------------------------------------*/ void event_delete( struct event * ev ) { @@ -63,13 +67,16 @@ void event_delete( struct event * ev ) pthread_cond_destroy( &ev->cond ); free( ev ); } +/*-----------------------------------------------------------*/ bool event_wait( struct event * ev ) { if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD ) { - /* If the thread owning the mutex died, make the mutex consistent. */ - pthread_mutex_consistent( &ev->mutex ); + #ifndef __APPLE__ + /* If the thread owning the mutex died, make the mutex consistent. */ + pthread_mutex_consistent( &ev->mutex ); + #endif } while( ev->event_triggered == false ) @@ -81,6 +88,8 @@ bool event_wait( struct event * ev ) pthread_mutex_unlock( &ev->mutex ); return true; } +/*-----------------------------------------------------------*/ + bool event_wait_timed( struct event * ev, time_t ms ) { @@ -92,8 +101,10 @@ bool event_wait_timed( struct event * ev, ts.tv_nsec += ( ( ms % 1000 ) * 1000000 ); if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD ) { - /* If the thread owning the mutex died, make the mutex consistent. */ - pthread_mutex_consistent( &ev->mutex ); + #ifndef __APPLE__ + /* If the thread owning the mutex died, make the mutex consistent. */ + pthread_mutex_consistent( &ev->mutex ); + #endif } while( ( ev->event_triggered == false ) && ( ret == 0 ) ) @@ -110,15 +121,19 @@ bool event_wait_timed( struct event * ev, pthread_mutex_unlock( &ev->mutex ); return true; } +/*-----------------------------------------------------------*/ void event_signal( struct event * ev ) { if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD ) { - /* If the thread owning the mutex died, make the mutex consistent. */ - pthread_mutex_consistent( &ev->mutex ); + #ifndef __APPLE__ + /* If the thread owning the mutex died, make the mutex consistent. */ + pthread_mutex_consistent( &ev->mutex ); + #endif } ev->event_triggered = true; pthread_cond_signal( &ev->cond ); pthread_mutex_unlock( &ev->mutex ); } +/*-----------------------------------------------------------*/