From 3ef54dcc4c0a2366495338b13a8afc055a7f8982 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 6 Jul 2000 19:33:52 +0000 Subject: Added support for converting a mutex id to a pointer and returning with interrupts disabled. --- cpukit/posix/inline/rtems/posix/mutex.inl | 60 ++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'cpukit/posix/inline/rtems/posix') diff --git a/cpukit/posix/inline/rtems/posix/mutex.inl b/cpukit/posix/inline/rtems/posix/mutex.inl index 47ff46d507..b7f5f2e003 100644 --- a/cpukit/posix/inline/rtems/posix/mutex.inl +++ b/cpukit/posix/inline/rtems/posix/mutex.inl @@ -41,39 +41,57 @@ RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Free ( /*PAGE * * _POSIX_Mutex_Get + * + * NOTE: The support macro makes it possible for both to use exactly + * the same code to check for NULL id pointer and + * PTHREAD_MUTEX_INITIALIZER without adding overhead. */ + +#define ___POSIX_Mutex_Get_support( _id, _location ) \ + do { \ + int _status; \ + \ + if ( !_id ) { \ + *_location = OBJECTS_ERROR; \ + return (POSIX_Mutex_Control *) 0; \ + } \ + \ + if ( *_id == PTHREAD_MUTEX_INITIALIZER ) { \ + /* \ + * Do an "auto-create" here. \ + */ \ + \ + _status = pthread_mutex_init( _id, 0 ); \ + if ( _status ) { \ + *_location = OBJECTS_ERROR; \ + return (POSIX_Mutex_Control *) 0; \ + } \ + } \ + } while (0) RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Get ( Objects_Id *id, Objects_Locations *location ) { - int status; - - if ( !id ) { - *location = OBJECTS_ERROR; - return (POSIX_Mutex_Control *) 0; - } + ___POSIX_Mutex_Get_support( id, location ); - if ( *id == PTHREAD_MUTEX_INITIALIZER ) { - /* - * Do an "auto-create" here. - */ - - status = pthread_mutex_init( id, 0 ); - if ( status ) { - *location = OBJECTS_ERROR; - return (POSIX_Mutex_Control *) 0; - } - } + return (POSIX_Mutex_Control *) + _Objects_Get( &_POSIX_Mutex_Information, *id, location ); +} - /* - * Now call Objects_Get() - */ +RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable ( + Objects_Id *id, + Objects_Locations *location, + ISR_Level *level +) +{ + ___POSIX_Mutex_Get_support( id, location ); return (POSIX_Mutex_Control *) - _Objects_Get( &_POSIX_Mutex_Information, *id, location ); + _Objects_Get_isr_disable( &_POSIX_Mutex_Information, *id, location, level ); } + /*PAGE * -- cgit v1.2.3