mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-20 05:21:59 -04:00
Mutex robust APIs are not available on Mac
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
parent
2e38eb5423
commit
92be5d47ee
|
@ -39,6 +39,7 @@ struct event
|
||||||
pthread_cond_t cond;
|
pthread_cond_t cond;
|
||||||
bool event_triggered;
|
bool event_triggered;
|
||||||
};
|
};
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
struct event * event_create( void )
|
struct event * event_create( void )
|
||||||
{
|
{
|
||||||
|
@ -48,13 +49,16 @@ struct event * event_create( void )
|
||||||
{
|
{
|
||||||
ev->event_triggered = false;
|
ev->event_triggered = false;
|
||||||
pthread_mutexattr_init( &ev->mutexattr );
|
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_mutex_init( &ev->mutex, &ev->mutexattr );
|
||||||
pthread_cond_init( &ev->cond, NULL );
|
pthread_cond_init( &ev->cond, NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
return ev;
|
return ev;
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void event_delete( struct event * ev )
|
void event_delete( struct event * ev )
|
||||||
{
|
{
|
||||||
|
@ -63,13 +67,16 @@ void event_delete( struct event * ev )
|
||||||
pthread_cond_destroy( &ev->cond );
|
pthread_cond_destroy( &ev->cond );
|
||||||
free( ev );
|
free( ev );
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
bool event_wait( struct event * ev )
|
bool event_wait( struct event * ev )
|
||||||
{
|
{
|
||||||
if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD )
|
if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD )
|
||||||
{
|
{
|
||||||
/* If the thread owning the mutex died, make the mutex consistent. */
|
#ifndef __APPLE__
|
||||||
pthread_mutex_consistent( &ev->mutex );
|
/* If the thread owning the mutex died, make the mutex consistent. */
|
||||||
|
pthread_mutex_consistent( &ev->mutex );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
while( ev->event_triggered == false )
|
while( ev->event_triggered == false )
|
||||||
|
@ -81,6 +88,8 @@ bool event_wait( struct event * ev )
|
||||||
pthread_mutex_unlock( &ev->mutex );
|
pthread_mutex_unlock( &ev->mutex );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
bool event_wait_timed( struct event * ev,
|
bool event_wait_timed( struct event * ev,
|
||||||
time_t ms )
|
time_t ms )
|
||||||
{
|
{
|
||||||
|
@ -92,8 +101,10 @@ bool event_wait_timed( struct event * ev,
|
||||||
ts.tv_nsec += ( ( ms % 1000 ) * 1000000 );
|
ts.tv_nsec += ( ( ms % 1000 ) * 1000000 );
|
||||||
if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD )
|
if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD )
|
||||||
{
|
{
|
||||||
/* If the thread owning the mutex died, make the mutex consistent. */
|
#ifndef __APPLE__
|
||||||
pthread_mutex_consistent( &ev->mutex );
|
/* If the thread owning the mutex died, make the mutex consistent. */
|
||||||
|
pthread_mutex_consistent( &ev->mutex );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
while( ( ev->event_triggered == false ) && ( ret == 0 ) )
|
while( ( ev->event_triggered == false ) && ( ret == 0 ) )
|
||||||
|
@ -110,15 +121,19 @@ bool event_wait_timed( struct event * ev,
|
||||||
pthread_mutex_unlock( &ev->mutex );
|
pthread_mutex_unlock( &ev->mutex );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void event_signal( struct event * ev )
|
void event_signal( struct event * ev )
|
||||||
{
|
{
|
||||||
if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD )
|
if( pthread_mutex_lock( &ev->mutex ) == EOWNERDEAD )
|
||||||
{
|
{
|
||||||
/* If the thread owning the mutex died, make the mutex consistent. */
|
#ifndef __APPLE__
|
||||||
pthread_mutex_consistent( &ev->mutex );
|
/* If the thread owning the mutex died, make the mutex consistent. */
|
||||||
|
pthread_mutex_consistent( &ev->mutex );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
ev->event_triggered = true;
|
ev->event_triggered = true;
|
||||||
pthread_cond_signal( &ev->cond );
|
pthread_cond_signal( &ev->cond );
|
||||||
pthread_mutex_unlock( &ev->mutex );
|
pthread_mutex_unlock( &ev->mutex );
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in a new issue