Changeset 419accf in rtems


Ignore:
Timestamp:
10/08/14 08:07:01 (9 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
dfdad6ab
Parents:
044cf4d7
git-author:
Sebastian Huber <sebastian.huber@…> (10/08/14 08:07:01)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/08/14 09:26:26)
Message:

posix: Use function instead of macros

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/src/mutexget.c

    r044cf4d7 r419accf  
    1919#endif
    2020
    21 #include <errno.h>
    22 #include <pthread.h>
    23 
    24 #include <rtems/system.h>
    25 #include <rtems/score/coremuteximpl.h>
    2621#include <rtems/posix/muteximpl.h>
    2722
     23static bool _POSIX_Mutex_Check_id_and_auto_init(
     24  pthread_mutex_t   *mutex,
     25  Objects_Locations *location
     26)
     27{
     28  if ( mutex == NULL ) {
     29    *location = OBJECTS_ERROR;
    2830
    29 /*
    30  *  _POSIX_Mutex_Get_support
    31  *
    32  *  NOTE: The support macro makes it possible for both to use exactly
    33  *        the same code to check for NULL id pointer and
    34  *        PTHREAD_MUTEX_INITIALIZER without adding overhead.
    35  */
     31    return false;
     32  }
    3633
    37 #define ___POSIX_Mutex_Get_support_error_check( _id, _location ) \
    38   do { \
    39     if ( !_id ) { \
    40       *_location = OBJECTS_ERROR; \
    41       return (POSIX_Mutex_Control *) 0; \
    42     }  \
    43   } while (0)
     34  if ( *mutex == PTHREAD_MUTEX_INITIALIZER ) {
     35    int eno;
    4436
    45 #define ___POSIX_Mutex_Get_support_auto_initialization( _id, _location ) \
    46   do { \
    47     int _status; \
    48     \
    49     if ( *_id == PTHREAD_MUTEX_INITIALIZER ) { \
    50       /* \
    51        *  Do an "auto-create" here. \
    52        */ \
    53       \
    54       _status = pthread_mutex_init( (pthread_mutex_t *)_id, 0 ); \
    55       if ( _status ) { \
    56         *_location = OBJECTS_ERROR;  \
    57         return (POSIX_Mutex_Control *) 0; \
    58       } \
    59     } \
    60   } while (0)
     37    eno = pthread_mutex_init( mutex, NULL );
     38
     39    if ( eno != 0 ) {
     40      *location = OBJECTS_ERROR;
     41
     42      return false;
     43    }
     44  }
     45
     46  return true;
     47}
    6148
    6249POSIX_Mutex_Control *_POSIX_Mutex_Get (
     
    6552)
    6653{
    67   ___POSIX_Mutex_Get_support_error_check( mutex, location );
    68 
    69   ___POSIX_Mutex_Get_support_auto_initialization( mutex, location );
     54  if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex, location ) ) {
     55    return NULL;
     56  }
    7057
    7158  return (POSIX_Mutex_Control *)
     
    7966)
    8067{
    81   ___POSIX_Mutex_Get_support_error_check( mutex, location );
    82 
    83   ___POSIX_Mutex_Get_support_auto_initialization( mutex, location );
     68  if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex, location ) ) {
     69    return NULL;
     70  }
    8471
    8572  return (POSIX_Mutex_Control *) _Objects_Get_isr_disable(
Note: See TracChangeset for help on using the changeset viewer.