Changeset c45a2ded in rtems


Ignore:
Timestamp:
Jul 8, 2009, 10:26:11 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
66abaa1
Parents:
299fc7a
Message:

2009-07-08 Joel Sherrill <joel.sherrill@…>

  • rtems/src/semcreate.c: Restructure to simplify and improve ability to anlize this routine for coverage.
Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r299fc7a rc45a2ded  
     12009-07-08      Joel Sherrill <joel.sherrill@OARcorp.com>
     2
     3        * rtems/src/semcreate.c: Restructure to simplify and improve ability to
     4        anlize this routine for coverage.
     5
    162009-07-08      Joel Sherrill <joel.sherrill@OARcorp.com>
    27
  • cpukit/rtems/src/semcreate.c

    r299fc7a rc45a2ded  
    7979{
    8080  register Semaphore_Control *the_semaphore;
    81   CORE_mutex_Attributes       the_mutex_attributes;
    82   CORE_semaphore_Attributes   the_semaphore_attributes;
     81  CORE_mutex_Attributes       the_mutex_attr;
     82  CORE_semaphore_Attributes   the_semaphore_attr;
     83  CORE_mutex_Status           mutex_status;
     84
    8385
    8486  if ( !rtems_is_name_valid( name ) )
     
    140142
    141143  /*
    142    *  If it is not a counting semaphore, then it is either a
    143    *  simple binary semaphore or a more powerful mutex style binary
    144    *  semaphore.
     144   *  Initialize it as a counting semaphore.
    145145   */
    146 
    147   if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
    148     CORE_mutex_Status mutex_status;
    149 
    150     if ( _Attributes_Is_inherit_priority( attribute_set ) )
    151       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT;
    152     else if ( _Attributes_Is_priority_ceiling( attribute_set ) )
    153       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING;
    154     else if ( _Attributes_Is_priority( attribute_set ) )
    155       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY;
    156     else
    157       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_FIFO;
    158 
    159 
    160     if ( _Attributes_Is_binary_semaphore( attribute_set ) ) {
    161       the_mutex_attributes.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES;
    162 
    163       switch ( the_mutex_attributes.discipline ) {
    164         case CORE_MUTEX_DISCIPLINES_FIFO:
    165         case CORE_MUTEX_DISCIPLINES_PRIORITY:
    166           the_mutex_attributes.only_owner_release = false;
    167           break;
    168         case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
    169         case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
    170           the_mutex_attributes.only_owner_release = true;
    171           break;
    172       }
    173     } else {
    174       the_mutex_attributes.lock_nesting_behavior = CORE_MUTEX_NESTING_BLOCKS;
    175       the_mutex_attributes.only_owner_release = false;
    176     }
    177 
    178     the_mutex_attributes.priority_ceiling = priority_ceiling;
    179 
    180     mutex_status = _CORE_mutex_Initialize(
    181       &the_semaphore->Core_control.mutex,
    182       &the_mutex_attributes,
    183       (count == 1) ? CORE_MUTEX_UNLOCKED : CORE_MUTEX_LOCKED
    184      );
    185 
    186      if ( mutex_status == CORE_MUTEX_STATUS_CEILING_VIOLATED ) {
    187        _Semaphore_Free( the_semaphore );
    188        _Thread_Enable_dispatch();
    189        return RTEMS_INVALID_PRIORITY;
    190      }
    191   } else {
    192     if ( _Attributes_Is_priority( attribute_set ) )
    193       the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_PRIORITY;
    194     else
    195       the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
    196 
     146  if ( _Attributes_Is_counting_semaphore( attribute_set ) ) {
    197147    /*
    198148     *  This effectively disables limit checking.
    199149     */
    200 
    201     the_semaphore_attributes.maximum_count = 0xFFFFFFFF;
     150    the_semaphore_attr.maximum_count = 0xFFFFFFFF;
     151
     152    if ( _Attributes_Is_priority( attribute_set ) )
     153      the_semaphore_attr.discipline = CORE_SEMAPHORE_DISCIPLINES_PRIORITY;
     154    else
     155      the_semaphore_attr.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
    202156
    203157    /*
    204158     *  The following are just to make Purify happy.
    205159     */
    206 
    207     the_mutex_attributes.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES;
    208     the_mutex_attributes.priority_ceiling = PRIORITY_MINIMUM;
     160    the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES;
     161    the_mutex_attr.priority_ceiling = PRIORITY_MINIMUM;
    209162
    210163    _CORE_semaphore_Initialize(
    211164      &the_semaphore->Core_control.semaphore,
    212       &the_semaphore_attributes,
     165      &the_semaphore_attr,
    213166      count
    214167    );
    215   }
    216 
     168    goto open_object;
     169  }
     170
     171  /*
     172   *  It is either simple binary semaphore or a more powerful mutex
     173   *  style binary semaphore.  This is the mutex style.
     174   */
     175
     176  if ( _Attributes_Is_priority( attribute_set ) )
     177    the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY;
     178  else
     179    the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_FIFO;
     180
     181  if ( _Attributes_Is_binary_semaphore( attribute_set ) ) {
     182    the_mutex_attr.priority_ceiling      = priority_ceiling;
     183    the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_ACQUIRES;
     184
     185    if ( the_mutex_attr.discipline == CORE_MUTEX_DISCIPLINES_PRIORITY ) {
     186      if ( _Attributes_Is_inherit_priority( attribute_set ) ) {
     187        the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT;
     188        the_mutex_attr.only_owner_release = true;
     189      } else {
     190        the_mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING;
     191        the_mutex_attr.only_owner_release = true;
     192      }
     193    } else
     194      the_mutex_attr.only_owner_release = false;
     195  } else /* must be simple binary semaphore */ {
     196    the_mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_BLOCKS;
     197    the_mutex_attr.only_owner_release = false;
     198  }
     199
     200  mutex_status = _CORE_mutex_Initialize(
     201    &the_semaphore->Core_control.mutex,
     202    &the_mutex_attr,
     203    (count == 1) ? CORE_MUTEX_UNLOCKED : CORE_MUTEX_LOCKED
     204  );
     205
     206  if ( mutex_status == CORE_MUTEX_STATUS_CEILING_VIOLATED ) {
     207    _Semaphore_Free( the_semaphore );
     208    _Thread_Enable_dispatch();
     209    return RTEMS_INVALID_PRIORITY;
     210  }
     211
     212open_object:
    217213  _Objects_Open(
    218214    &_Semaphore_Information,
Note: See TracChangeset for help on using the changeset viewer.