Changeset c06d8f64 in rtems


Ignore:
Timestamp:
May 17, 1999, 10:58:30 PM (22 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
5f9b3db
Parents:
a2d0f39
Message:

Split the Semaphore Manager into one routine per file.

Files:
12 added
3 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/rtems/src/Makefile.in

    ra2d0f39 rc06d8f64  
    3737  msgqsend msgqsubmit msgqtranslatereturncode msgqurgent
    3838
     39SEMAPHORE_PIECES=\
     40  sem semcreate semdelete semident semobtain semrelease \
     41  semtranslatereturncode
     42
    3943C_PIECES=attr $(CLOCK_PIECES) dpmem event intr intrbody \
    4044   $(MESSAGE_QUEUE_PIECES) \
    41    part ratemon $(REGION_PIECES) sem signal \
     45   part ratemon $(REGION_PIECES) $(SEMAPHORE_PIECES) signal \
    4246   $(TASK_PIECES) timer $(MP_PIECES)
    4347C_FILES=$(C_PIECES:%=%.c)
  • c/src/exec/rtems/src/sem.c

    ra2d0f39 rc06d8f64  
    8686
    8787}
    88 
    89 /*PAGE
    90  *
    91  *  rtems_semaphore_create
    92  *
    93  *  This directive creates a semaphore and sets the initial value based
    94  *  on the given count.  A semaphore id is returned.
    95  *
    96  *  Input parameters:
    97  *    name             - user defined semaphore name
    98  *    count            - initial count of semaphore
    99  *    attribute_set    - semaphore attributes
    100  *    priority_ceiling - semaphore's ceiling priority
    101  *    id               - pointer to semaphore id
    102  *
    103  *  Output parameters:
    104  *    id       - semaphore id
    105  *    RTEMS_SUCCESSFUL - if successful
    106  *    error code - if unsuccessful
    107  */
    108 
    109 rtems_status_code rtems_semaphore_create(
    110   rtems_name           name,
    111   unsigned32           count,
    112   rtems_attribute      attribute_set,
    113   rtems_task_priority  priority_ceiling,
    114   Objects_Id          *id
    115 )
    116 {
    117   register Semaphore_Control *the_semaphore;
    118   CORE_mutex_Attributes       the_mutex_attributes;
    119   CORE_semaphore_Attributes   the_semaphore_attributes;
    120   unsigned32                  lock;
    121 
    122   if ( !rtems_is_name_valid( name ) )
    123     return RTEMS_INVALID_NAME;
    124 
    125 #if defined(RTEMS_MULTIPROCESSING)
    126   if ( _Attributes_Is_global( attribute_set ) ) {
    127 
    128     if ( !_System_state_Is_multiprocessing )
    129       return RTEMS_MP_NOT_CONFIGURED;
    130 
    131     if ( _Attributes_Is_inherit_priority( attribute_set ) )
    132       return RTEMS_NOT_DEFINED;
    133 
    134   } else
    135 #endif
    136   if ( _Attributes_Is_inherit_priority( attribute_set ) ||
    137               _Attributes_Is_priority_ceiling( attribute_set ) ) {
    138 
    139     if ( ! ( _Attributes_Is_binary_semaphore( attribute_set ) &&
    140              _Attributes_Is_priority( attribute_set ) ) )
    141       return RTEMS_NOT_DEFINED;
    142 
    143   }
    144 
    145   if ( _Attributes_Is_binary_semaphore( attribute_set ) && ( count > 1 ) )
    146     return RTEMS_INVALID_NUMBER;
    147 
    148   _Thread_Disable_dispatch();             /* prevents deletion */
    149 
    150   the_semaphore = _Semaphore_Allocate();
    151 
    152   if ( !the_semaphore ) {
    153     _Thread_Enable_dispatch();
    154     return RTEMS_TOO_MANY;
    155   }
    156 
    157 #if defined(RTEMS_MULTIPROCESSING)
    158   if ( _Attributes_Is_global( attribute_set ) &&
    159        ! ( _Objects_MP_Allocate_and_open( &_Semaphore_Information, name,
    160                             the_semaphore->Object.id, FALSE ) ) ) {
    161     _Semaphore_Free( the_semaphore );
    162     _Thread_Enable_dispatch();
    163     return RTEMS_TOO_MANY;
    164   }
    165 #endif
    166 
    167   the_semaphore->attribute_set = attribute_set;
    168 
    169   if ( _Attributes_Is_binary_semaphore( attribute_set ) ) {
    170     if ( _Attributes_Is_inherit_priority( attribute_set ) )
    171       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT;
    172     else if (_Attributes_Is_priority_ceiling( attribute_set ) )
    173       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING;
    174     else if (_Attributes_Is_priority( attribute_set ) )
    175       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY;
    176     else
    177       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_FIFO;
    178 
    179     the_mutex_attributes.allow_nesting = TRUE;
    180 
    181     /* Add priority ceiling code here ????? */
    182 
    183     the_mutex_attributes.priority_ceiling = priority_ceiling;
    184 
    185     if ( count == 1 )
    186       lock = CORE_MUTEX_UNLOCKED;
    187     else
    188       lock = CORE_MUTEX_LOCKED;
    189 
    190     _CORE_mutex_Initialize(
    191       &the_semaphore->Core_control.mutex,
    192       OBJECTS_RTEMS_SEMAPHORES,
    193       &the_mutex_attributes,
    194       lock,
    195 #if defined(RTEMS_MULTIPROCESSING)
    196       _Semaphore_MP_Send_extract_proxy
    197 #else
    198       NULL
    199 #endif
    200     );
    201   }
    202   else {
    203     if ( _Attributes_Is_priority( attribute_set ) )
    204       the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_PRIORITY;
    205     else
    206       the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
    207 
    208     /*
    209      *  The following are just to make Purify happy.
    210      */
    211 
    212     the_mutex_attributes.allow_nesting = TRUE;
    213     the_mutex_attributes.priority_ceiling = PRIORITY_MINIMUM;
    214 
    215     _CORE_semaphore_Initialize(
    216       &the_semaphore->Core_control.semaphore,
    217       OBJECTS_RTEMS_SEMAPHORES,
    218       &the_semaphore_attributes,
    219       count,
    220 #if defined(RTEMS_MULTIPROCESSING)
    221       _Semaphore_MP_Send_extract_proxy
    222 #else
    223       NULL
    224 #endif
    225     );
    226   }
    227 
    228   _Objects_Open( &_Semaphore_Information, &the_semaphore->Object, &name );
    229 
    230   *id = the_semaphore->Object.id;
    231 
    232 #if defined(RTEMS_MULTIPROCESSING)
    233   if ( _Attributes_Is_global( attribute_set ) )
    234     _Semaphore_MP_Send_process_packet(
    235       SEMAPHORE_MP_ANNOUNCE_CREATE,
    236       the_semaphore->Object.id,
    237       name,
    238       0                          /* Not used */
    239     );
    240 #endif
    241   _Thread_Enable_dispatch();
    242   return RTEMS_SUCCESSFUL;
    243 }
    244 
    245 /*PAGE
    246  *
    247  *  rtems_semaphore_ident
    248  *
    249  *  This directive returns the system ID associated with
    250  *  the semaphore name.
    251  *
    252  *  Input parameters:
    253  *    name - user defined semaphore name
    254  *    node - node(s) to be searched
    255  *    id   - pointer to semaphore id
    256  *
    257  *  Output parameters:
    258  *    *id      - semaphore id
    259  *    RTEMS_SUCCESSFUL - if successful
    260  *    error code - if unsuccessful
    261  */
    262 
    263 rtems_status_code rtems_semaphore_ident(
    264   rtems_name  name,
    265   unsigned32  node,
    266   Objects_Id *id
    267 )
    268 {
    269   Objects_Name_to_id_errors  status;
    270  
    271   status = _Objects_Name_to_id( &_Semaphore_Information, &name, node, id );
    272  
    273   return _Status_Object_name_errors_to_status[ status ];
    274 }
    275 
    276 /*PAGE
    277  *
    278  *  rtems_semaphore_delete
    279  *
    280  *  This directive allows a thread to delete a semaphore specified by
    281  *  the semaphore id.  The semaphore is freed back to the inactive
    282  *  semaphore chain.
    283  *
    284  *  Input parameters:
    285  *    id - semaphore id
    286  *
    287  *  Output parameters:
    288  *    RTEMS_SUCCESSFUL - if successful
    289  *    error code        - if unsuccessful
    290  */
    291 
    292 rtems_status_code rtems_semaphore_delete(
    293   Objects_Id id
    294 )
    295 {
    296   register Semaphore_Control *the_semaphore;
    297   Objects_Locations           location;
    298 
    299   the_semaphore = _Semaphore_Get( id, &location );
    300   switch ( location ) {
    301 
    302     case OBJECTS_REMOTE:
    303 #if defined(RTEMS_MULTIPROCESSING)
    304       _Thread_Dispatch();
    305       return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
    306 #endif
    307 
    308     case OBJECTS_ERROR:
    309       return RTEMS_INVALID_ID;
    310 
    311     case OBJECTS_LOCAL:
    312       if ( _Attributes_Is_binary_semaphore( the_semaphore->attribute_set) ) {
    313         if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) ) {
    314           _Thread_Enable_dispatch();
    315           return RTEMS_RESOURCE_IN_USE;
    316         }
    317         else
    318           _CORE_mutex_Flush(
    319             &the_semaphore->Core_control.mutex,
    320 #if defined(RTEMS_MULTIPROCESSING)
    321             _Semaphore_MP_Send_object_was_deleted,
    322 #else
    323             NULL,
    324 #endif
    325             CORE_MUTEX_WAS_DELETED
    326           );
    327       }
    328       else
    329         _CORE_semaphore_Flush(
    330           &the_semaphore->Core_control.semaphore,
    331 #if defined(RTEMS_MULTIPROCESSING)
    332           _Semaphore_MP_Send_object_was_deleted,
    333 #else
    334           NULL,
    335 #endif
    336           CORE_SEMAPHORE_WAS_DELETED
    337         );
    338 
    339       _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
    340 
    341       _Semaphore_Free( the_semaphore );
    342 
    343 #if defined(RTEMS_MULTIPROCESSING)
    344       if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) {
    345 
    346         _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id );
    347 
    348         _Semaphore_MP_Send_process_packet(
    349           SEMAPHORE_MP_ANNOUNCE_DELETE,
    350           the_semaphore->Object.id,
    351           0,                         /* Not used */
    352           0                          /* Not used */
    353         );
    354       }
    355 #endif
    356       _Thread_Enable_dispatch();
    357       return RTEMS_SUCCESSFUL;
    358   }
    359 
    360   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    361 }
    362 
    363 /*PAGE
    364  *
    365  *  rtems_semaphore_obtain
    366  *
    367  *  This directive allows a thread to acquire a semaphore.
    368  *
    369  *  Input parameters:
    370  *    id         - semaphore id
    371  *    option_set - wait option
    372  *    timeout    - number of ticks to wait (0 means wait forever)
    373  *
    374  *  Output parameters:
    375  *    RTEMS_SUCCESSFUL - if successful
    376  *    error code        - if unsuccessful
    377  */
    378 
    379 rtems_status_code rtems_semaphore_obtain(
    380   Objects_Id      id,
    381   unsigned32      option_set,
    382   rtems_interval  timeout
    383 )
    384 {
    385   register Semaphore_Control *the_semaphore;
    386   Objects_Locations           location;
    387   boolean                     wait;
    388 
    389   the_semaphore = _Semaphore_Get( id, &location );
    390   switch ( location ) {
    391     case OBJECTS_REMOTE:
    392 #if defined(RTEMS_MULTIPROCESSING)
    393       return _Semaphore_MP_Send_request_packet(
    394           SEMAPHORE_MP_OBTAIN_REQUEST,
    395           id,
    396           option_set,
    397           timeout
    398       );
    399 #endif
    400 
    401     case OBJECTS_ERROR:
    402       return RTEMS_INVALID_ID;
    403 
    404     case OBJECTS_LOCAL:
    405       if ( _Options_Is_no_wait( option_set ) )
    406         wait = FALSE;
    407       else
    408         wait = TRUE;
    409 
    410       if ( _Attributes_Is_binary_semaphore( the_semaphore->attribute_set ) ) {
    411         _CORE_mutex_Seize(
    412           &the_semaphore->Core_control.mutex,
    413           id,
    414           wait,
    415           timeout
    416         );
    417         _Thread_Enable_dispatch();
    418         return _Semaphore_Translate_core_mutex_return_code(
    419                   _Thread_Executing->Wait.return_code );
    420       } else {
    421         _CORE_semaphore_Seize(
    422           &the_semaphore->Core_control.semaphore,
    423           id,
    424           wait,
    425           timeout
    426         );
    427         _Thread_Enable_dispatch();
    428         return _Semaphore_Translate_core_semaphore_return_code(
    429                   _Thread_Executing->Wait.return_code );
    430       }
    431   }
    432 
    433   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    434 }
    435 
    436 /*PAGE
    437  *
    438  *  rtems_semaphore_release
    439  *
    440  *  This directive allows a thread to release a semaphore.
    441  *
    442  *  Input parameters:
    443  *    id - semaphore id
    444  *
    445  *  Output parameters:
    446  *    RTEMS_SUCCESSFUL - if successful
    447  *    error code        - if unsuccessful
    448  */
    449 
    450 rtems_status_code rtems_semaphore_release(
    451   Objects_Id id
    452 )
    453 {
    454   register Semaphore_Control *the_semaphore;
    455   Objects_Locations           location;
    456   CORE_mutex_Status           mutex_status;
    457   CORE_semaphore_Status       semaphore_status;
    458 
    459   the_semaphore = _Semaphore_Get( id, &location );
    460   switch ( location ) {
    461 
    462     case OBJECTS_REMOTE:
    463 #if defined(RTEMS_MULTIPROCESSING)
    464       return _Semaphore_MP_Send_request_packet(
    465         SEMAPHORE_MP_RELEASE_REQUEST,
    466         id,
    467         0,                               /* Not used */
    468         MPCI_DEFAULT_TIMEOUT
    469       );
    470 #endif
    471 
    472     case OBJECTS_ERROR:
    473       return RTEMS_INVALID_ID;
    474 
    475     case OBJECTS_LOCAL:
    476       if ( _Attributes_Is_binary_semaphore( the_semaphore->attribute_set ) ) {
    477         mutex_status = _CORE_mutex_Surrender(
    478                          &the_semaphore->Core_control.mutex,
    479                          id,
    480 #if defined(RTEMS_MULTIPROCESSING)
    481                          _Semaphore_Core_mutex_mp_support
    482 #else
    483                          NULL
    484 #endif
    485                        );
    486         _Thread_Enable_dispatch();
    487         return _Semaphore_Translate_core_mutex_return_code( mutex_status );
    488       }
    489       else
    490         semaphore_status = _CORE_semaphore_Surrender(
    491                              &the_semaphore->Core_control.semaphore,
    492                              id,
    493 #if defined(RTEMS_MULTIPROCESSING)
    494                              _Semaphore_Core_semaphore_mp_support
    495 #else
    496                              NULL
    497 #endif
    498                            );
    499         _Thread_Enable_dispatch();
    500         return
    501           _Semaphore_Translate_core_semaphore_return_code( semaphore_status );
    502   }
    503 
    504   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    505 }
    506 
    507 /*PAGE
    508  *
    509  *  _Semaphore_Translate_core_mutex_return_code
    510  *
    511  *  Input parameters:
    512  *    the_mutex_status - mutex status code to translate
    513  *
    514  *  Output parameters:
    515  *    rtems status code - translated RTEMS status code
    516  *
    517  */
    518  
    519 rtems_status_code _Semaphore_Translate_core_mutex_return_code (
    520   unsigned32 the_mutex_status
    521 )
    522 {
    523   switch ( the_mutex_status ) {
    524     case  CORE_MUTEX_STATUS_SUCCESSFUL:
    525       return RTEMS_SUCCESSFUL;
    526     case CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT:
    527       return RTEMS_UNSATISFIED;
    528     case CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED:
    529       return RTEMS_INTERNAL_ERROR;
    530     case CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE:
    531       return RTEMS_NOT_OWNER_OF_RESOURCE;
    532     case CORE_MUTEX_WAS_DELETED:
    533       return RTEMS_OBJECT_WAS_DELETED;
    534     case CORE_MUTEX_TIMEOUT:
    535       return RTEMS_TIMEOUT;
    536     case THREAD_STATUS_PROXY_BLOCKING:
    537       return THREAD_STATUS_PROXY_BLOCKING;
    538   }
    539   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    540 }
    541 
    542 /*PAGE
    543  *
    544  *  _Semaphore_Translate_core_semaphore_return_code
    545  *
    546  *  Input parameters:
    547  *    the_semaphore_status - semaphore status code to translate
    548  *
    549  *  Output parameters:
    550  *    rtems status code - translated RTEMS status code
    551  *
    552  */
    553  
    554 rtems_status_code _Semaphore_Translate_core_semaphore_return_code (
    555   unsigned32 the_semaphore_status
    556 )
    557 {
    558   switch ( the_semaphore_status ) {
    559     case  CORE_SEMAPHORE_STATUS_SUCCESSFUL:
    560       return RTEMS_SUCCESSFUL;
    561     case CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT:
    562       return RTEMS_UNSATISFIED;
    563     case CORE_SEMAPHORE_WAS_DELETED:
    564       return RTEMS_OBJECT_WAS_DELETED;
    565     case CORE_SEMAPHORE_TIMEOUT:
    566       return RTEMS_TIMEOUT;
    567     case THREAD_STATUS_PROXY_BLOCKING:
    568       return THREAD_STATUS_PROXY_BLOCKING;
    569   }
    570   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    571 }
  • cpukit/rtems/src/sem.c

    ra2d0f39 rc06d8f64  
    8686
    8787}
    88 
    89 /*PAGE
    90  *
    91  *  rtems_semaphore_create
    92  *
    93  *  This directive creates a semaphore and sets the initial value based
    94  *  on the given count.  A semaphore id is returned.
    95  *
    96  *  Input parameters:
    97  *    name             - user defined semaphore name
    98  *    count            - initial count of semaphore
    99  *    attribute_set    - semaphore attributes
    100  *    priority_ceiling - semaphore's ceiling priority
    101  *    id               - pointer to semaphore id
    102  *
    103  *  Output parameters:
    104  *    id       - semaphore id
    105  *    RTEMS_SUCCESSFUL - if successful
    106  *    error code - if unsuccessful
    107  */
    108 
    109 rtems_status_code rtems_semaphore_create(
    110   rtems_name           name,
    111   unsigned32           count,
    112   rtems_attribute      attribute_set,
    113   rtems_task_priority  priority_ceiling,
    114   Objects_Id          *id
    115 )
    116 {
    117   register Semaphore_Control *the_semaphore;
    118   CORE_mutex_Attributes       the_mutex_attributes;
    119   CORE_semaphore_Attributes   the_semaphore_attributes;
    120   unsigned32                  lock;
    121 
    122   if ( !rtems_is_name_valid( name ) )
    123     return RTEMS_INVALID_NAME;
    124 
    125 #if defined(RTEMS_MULTIPROCESSING)
    126   if ( _Attributes_Is_global( attribute_set ) ) {
    127 
    128     if ( !_System_state_Is_multiprocessing )
    129       return RTEMS_MP_NOT_CONFIGURED;
    130 
    131     if ( _Attributes_Is_inherit_priority( attribute_set ) )
    132       return RTEMS_NOT_DEFINED;
    133 
    134   } else
    135 #endif
    136   if ( _Attributes_Is_inherit_priority( attribute_set ) ||
    137               _Attributes_Is_priority_ceiling( attribute_set ) ) {
    138 
    139     if ( ! ( _Attributes_Is_binary_semaphore( attribute_set ) &&
    140              _Attributes_Is_priority( attribute_set ) ) )
    141       return RTEMS_NOT_DEFINED;
    142 
    143   }
    144 
    145   if ( _Attributes_Is_binary_semaphore( attribute_set ) && ( count > 1 ) )
    146     return RTEMS_INVALID_NUMBER;
    147 
    148   _Thread_Disable_dispatch();             /* prevents deletion */
    149 
    150   the_semaphore = _Semaphore_Allocate();
    151 
    152   if ( !the_semaphore ) {
    153     _Thread_Enable_dispatch();
    154     return RTEMS_TOO_MANY;
    155   }
    156 
    157 #if defined(RTEMS_MULTIPROCESSING)
    158   if ( _Attributes_Is_global( attribute_set ) &&
    159        ! ( _Objects_MP_Allocate_and_open( &_Semaphore_Information, name,
    160                             the_semaphore->Object.id, FALSE ) ) ) {
    161     _Semaphore_Free( the_semaphore );
    162     _Thread_Enable_dispatch();
    163     return RTEMS_TOO_MANY;
    164   }
    165 #endif
    166 
    167   the_semaphore->attribute_set = attribute_set;
    168 
    169   if ( _Attributes_Is_binary_semaphore( attribute_set ) ) {
    170     if ( _Attributes_Is_inherit_priority( attribute_set ) )
    171       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT;
    172     else if (_Attributes_Is_priority_ceiling( attribute_set ) )
    173       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING;
    174     else if (_Attributes_Is_priority( attribute_set ) )
    175       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_PRIORITY;
    176     else
    177       the_mutex_attributes.discipline = CORE_MUTEX_DISCIPLINES_FIFO;
    178 
    179     the_mutex_attributes.allow_nesting = TRUE;
    180 
    181     /* Add priority ceiling code here ????? */
    182 
    183     the_mutex_attributes.priority_ceiling = priority_ceiling;
    184 
    185     if ( count == 1 )
    186       lock = CORE_MUTEX_UNLOCKED;
    187     else
    188       lock = CORE_MUTEX_LOCKED;
    189 
    190     _CORE_mutex_Initialize(
    191       &the_semaphore->Core_control.mutex,
    192       OBJECTS_RTEMS_SEMAPHORES,
    193       &the_mutex_attributes,
    194       lock,
    195 #if defined(RTEMS_MULTIPROCESSING)
    196       _Semaphore_MP_Send_extract_proxy
    197 #else
    198       NULL
    199 #endif
    200     );
    201   }
    202   else {
    203     if ( _Attributes_Is_priority( attribute_set ) )
    204       the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_PRIORITY;
    205     else
    206       the_semaphore_attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
    207 
    208     /*
    209      *  The following are just to make Purify happy.
    210      */
    211 
    212     the_mutex_attributes.allow_nesting = TRUE;
    213     the_mutex_attributes.priority_ceiling = PRIORITY_MINIMUM;
    214 
    215     _CORE_semaphore_Initialize(
    216       &the_semaphore->Core_control.semaphore,
    217       OBJECTS_RTEMS_SEMAPHORES,
    218       &the_semaphore_attributes,
    219       count,
    220 #if defined(RTEMS_MULTIPROCESSING)
    221       _Semaphore_MP_Send_extract_proxy
    222 #else
    223       NULL
    224 #endif
    225     );
    226   }
    227 
    228   _Objects_Open( &_Semaphore_Information, &the_semaphore->Object, &name );
    229 
    230   *id = the_semaphore->Object.id;
    231 
    232 #if defined(RTEMS_MULTIPROCESSING)
    233   if ( _Attributes_Is_global( attribute_set ) )
    234     _Semaphore_MP_Send_process_packet(
    235       SEMAPHORE_MP_ANNOUNCE_CREATE,
    236       the_semaphore->Object.id,
    237       name,
    238       0                          /* Not used */
    239     );
    240 #endif
    241   _Thread_Enable_dispatch();
    242   return RTEMS_SUCCESSFUL;
    243 }
    244 
    245 /*PAGE
    246  *
    247  *  rtems_semaphore_ident
    248  *
    249  *  This directive returns the system ID associated with
    250  *  the semaphore name.
    251  *
    252  *  Input parameters:
    253  *    name - user defined semaphore name
    254  *    node - node(s) to be searched
    255  *    id   - pointer to semaphore id
    256  *
    257  *  Output parameters:
    258  *    *id      - semaphore id
    259  *    RTEMS_SUCCESSFUL - if successful
    260  *    error code - if unsuccessful
    261  */
    262 
    263 rtems_status_code rtems_semaphore_ident(
    264   rtems_name  name,
    265   unsigned32  node,
    266   Objects_Id *id
    267 )
    268 {
    269   Objects_Name_to_id_errors  status;
    270  
    271   status = _Objects_Name_to_id( &_Semaphore_Information, &name, node, id );
    272  
    273   return _Status_Object_name_errors_to_status[ status ];
    274 }
    275 
    276 /*PAGE
    277  *
    278  *  rtems_semaphore_delete
    279  *
    280  *  This directive allows a thread to delete a semaphore specified by
    281  *  the semaphore id.  The semaphore is freed back to the inactive
    282  *  semaphore chain.
    283  *
    284  *  Input parameters:
    285  *    id - semaphore id
    286  *
    287  *  Output parameters:
    288  *    RTEMS_SUCCESSFUL - if successful
    289  *    error code        - if unsuccessful
    290  */
    291 
    292 rtems_status_code rtems_semaphore_delete(
    293   Objects_Id id
    294 )
    295 {
    296   register Semaphore_Control *the_semaphore;
    297   Objects_Locations           location;
    298 
    299   the_semaphore = _Semaphore_Get( id, &location );
    300   switch ( location ) {
    301 
    302     case OBJECTS_REMOTE:
    303 #if defined(RTEMS_MULTIPROCESSING)
    304       _Thread_Dispatch();
    305       return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
    306 #endif
    307 
    308     case OBJECTS_ERROR:
    309       return RTEMS_INVALID_ID;
    310 
    311     case OBJECTS_LOCAL:
    312       if ( _Attributes_Is_binary_semaphore( the_semaphore->attribute_set) ) {
    313         if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) ) {
    314           _Thread_Enable_dispatch();
    315           return RTEMS_RESOURCE_IN_USE;
    316         }
    317         else
    318           _CORE_mutex_Flush(
    319             &the_semaphore->Core_control.mutex,
    320 #if defined(RTEMS_MULTIPROCESSING)
    321             _Semaphore_MP_Send_object_was_deleted,
    322 #else
    323             NULL,
    324 #endif
    325             CORE_MUTEX_WAS_DELETED
    326           );
    327       }
    328       else
    329         _CORE_semaphore_Flush(
    330           &the_semaphore->Core_control.semaphore,
    331 #if defined(RTEMS_MULTIPROCESSING)
    332           _Semaphore_MP_Send_object_was_deleted,
    333 #else
    334           NULL,
    335 #endif
    336           CORE_SEMAPHORE_WAS_DELETED
    337         );
    338 
    339       _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
    340 
    341       _Semaphore_Free( the_semaphore );
    342 
    343 #if defined(RTEMS_MULTIPROCESSING)
    344       if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) {
    345 
    346         _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id );
    347 
    348         _Semaphore_MP_Send_process_packet(
    349           SEMAPHORE_MP_ANNOUNCE_DELETE,
    350           the_semaphore->Object.id,
    351           0,                         /* Not used */
    352           0                          /* Not used */
    353         );
    354       }
    355 #endif
    356       _Thread_Enable_dispatch();
    357       return RTEMS_SUCCESSFUL;
    358   }
    359 
    360   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    361 }
    362 
    363 /*PAGE
    364  *
    365  *  rtems_semaphore_obtain
    366  *
    367  *  This directive allows a thread to acquire a semaphore.
    368  *
    369  *  Input parameters:
    370  *    id         - semaphore id
    371  *    option_set - wait option
    372  *    timeout    - number of ticks to wait (0 means wait forever)
    373  *
    374  *  Output parameters:
    375  *    RTEMS_SUCCESSFUL - if successful
    376  *    error code        - if unsuccessful
    377  */
    378 
    379 rtems_status_code rtems_semaphore_obtain(
    380   Objects_Id      id,
    381   unsigned32      option_set,
    382   rtems_interval  timeout
    383 )
    384 {
    385   register Semaphore_Control *the_semaphore;
    386   Objects_Locations           location;
    387   boolean                     wait;
    388 
    389   the_semaphore = _Semaphore_Get( id, &location );
    390   switch ( location ) {
    391     case OBJECTS_REMOTE:
    392 #if defined(RTEMS_MULTIPROCESSING)
    393       return _Semaphore_MP_Send_request_packet(
    394           SEMAPHORE_MP_OBTAIN_REQUEST,
    395           id,
    396           option_set,
    397           timeout
    398       );
    399 #endif
    400 
    401     case OBJECTS_ERROR:
    402       return RTEMS_INVALID_ID;
    403 
    404     case OBJECTS_LOCAL:
    405       if ( _Options_Is_no_wait( option_set ) )
    406         wait = FALSE;
    407       else
    408         wait = TRUE;
    409 
    410       if ( _Attributes_Is_binary_semaphore( the_semaphore->attribute_set ) ) {
    411         _CORE_mutex_Seize(
    412           &the_semaphore->Core_control.mutex,
    413           id,
    414           wait,
    415           timeout
    416         );
    417         _Thread_Enable_dispatch();
    418         return _Semaphore_Translate_core_mutex_return_code(
    419                   _Thread_Executing->Wait.return_code );
    420       } else {
    421         _CORE_semaphore_Seize(
    422           &the_semaphore->Core_control.semaphore,
    423           id,
    424           wait,
    425           timeout
    426         );
    427         _Thread_Enable_dispatch();
    428         return _Semaphore_Translate_core_semaphore_return_code(
    429                   _Thread_Executing->Wait.return_code );
    430       }
    431   }
    432 
    433   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    434 }
    435 
    436 /*PAGE
    437  *
    438  *  rtems_semaphore_release
    439  *
    440  *  This directive allows a thread to release a semaphore.
    441  *
    442  *  Input parameters:
    443  *    id - semaphore id
    444  *
    445  *  Output parameters:
    446  *    RTEMS_SUCCESSFUL - if successful
    447  *    error code        - if unsuccessful
    448  */
    449 
    450 rtems_status_code rtems_semaphore_release(
    451   Objects_Id id
    452 )
    453 {
    454   register Semaphore_Control *the_semaphore;
    455   Objects_Locations           location;
    456   CORE_mutex_Status           mutex_status;
    457   CORE_semaphore_Status       semaphore_status;
    458 
    459   the_semaphore = _Semaphore_Get( id, &location );
    460   switch ( location ) {
    461 
    462     case OBJECTS_REMOTE:
    463 #if defined(RTEMS_MULTIPROCESSING)
    464       return _Semaphore_MP_Send_request_packet(
    465         SEMAPHORE_MP_RELEASE_REQUEST,
    466         id,
    467         0,                               /* Not used */
    468         MPCI_DEFAULT_TIMEOUT
    469       );
    470 #endif
    471 
    472     case OBJECTS_ERROR:
    473       return RTEMS_INVALID_ID;
    474 
    475     case OBJECTS_LOCAL:
    476       if ( _Attributes_Is_binary_semaphore( the_semaphore->attribute_set ) ) {
    477         mutex_status = _CORE_mutex_Surrender(
    478                          &the_semaphore->Core_control.mutex,
    479                          id,
    480 #if defined(RTEMS_MULTIPROCESSING)
    481                          _Semaphore_Core_mutex_mp_support
    482 #else
    483                          NULL
    484 #endif
    485                        );
    486         _Thread_Enable_dispatch();
    487         return _Semaphore_Translate_core_mutex_return_code( mutex_status );
    488       }
    489       else
    490         semaphore_status = _CORE_semaphore_Surrender(
    491                              &the_semaphore->Core_control.semaphore,
    492                              id,
    493 #if defined(RTEMS_MULTIPROCESSING)
    494                              _Semaphore_Core_semaphore_mp_support
    495 #else
    496                              NULL
    497 #endif
    498                            );
    499         _Thread_Enable_dispatch();
    500         return
    501           _Semaphore_Translate_core_semaphore_return_code( semaphore_status );
    502   }
    503 
    504   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    505 }
    506 
    507 /*PAGE
    508  *
    509  *  _Semaphore_Translate_core_mutex_return_code
    510  *
    511  *  Input parameters:
    512  *    the_mutex_status - mutex status code to translate
    513  *
    514  *  Output parameters:
    515  *    rtems status code - translated RTEMS status code
    516  *
    517  */
    518  
    519 rtems_status_code _Semaphore_Translate_core_mutex_return_code (
    520   unsigned32 the_mutex_status
    521 )
    522 {
    523   switch ( the_mutex_status ) {
    524     case  CORE_MUTEX_STATUS_SUCCESSFUL:
    525       return RTEMS_SUCCESSFUL;
    526     case CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT:
    527       return RTEMS_UNSATISFIED;
    528     case CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED:
    529       return RTEMS_INTERNAL_ERROR;
    530     case CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE:
    531       return RTEMS_NOT_OWNER_OF_RESOURCE;
    532     case CORE_MUTEX_WAS_DELETED:
    533       return RTEMS_OBJECT_WAS_DELETED;
    534     case CORE_MUTEX_TIMEOUT:
    535       return RTEMS_TIMEOUT;
    536     case THREAD_STATUS_PROXY_BLOCKING:
    537       return THREAD_STATUS_PROXY_BLOCKING;
    538   }
    539   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    540 }
    541 
    542 /*PAGE
    543  *
    544  *  _Semaphore_Translate_core_semaphore_return_code
    545  *
    546  *  Input parameters:
    547  *    the_semaphore_status - semaphore status code to translate
    548  *
    549  *  Output parameters:
    550  *    rtems status code - translated RTEMS status code
    551  *
    552  */
    553  
    554 rtems_status_code _Semaphore_Translate_core_semaphore_return_code (
    555   unsigned32 the_semaphore_status
    556 )
    557 {
    558   switch ( the_semaphore_status ) {
    559     case  CORE_SEMAPHORE_STATUS_SUCCESSFUL:
    560       return RTEMS_SUCCESSFUL;
    561     case CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT:
    562       return RTEMS_UNSATISFIED;
    563     case CORE_SEMAPHORE_WAS_DELETED:
    564       return RTEMS_OBJECT_WAS_DELETED;
    565     case CORE_SEMAPHORE_TIMEOUT:
    566       return RTEMS_TIMEOUT;
    567     case THREAD_STATUS_PROXY_BLOCKING:
    568       return THREAD_STATUS_PROXY_BLOCKING;
    569   }
    570   return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
    571 }
Note: See TracChangeset for help on using the changeset viewer.