[c18e0ba] | 1 | /** |
---|
| 2 | * @file |
---|
[c06d8f64] | 3 | * |
---|
[c18e0ba] | 4 | * @brief RTEMS Delete Semaphore |
---|
| 5 | * @ingroup ClassicSem |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[3a638ce] | 9 | * COPYRIGHT (c) 1989-2014. |
---|
[c06d8f64] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[c06d8f64] | 15 | */ |
---|
| 16 | |
---|
[1095ec1] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[c06d8f64] | 21 | #include <rtems/system.h> |
---|
| 22 | #include <rtems/rtems/status.h> |
---|
| 23 | #include <rtems/rtems/support.h> |
---|
[63d229d6] | 24 | #include <rtems/rtems/attrimpl.h> |
---|
[c06d8f64] | 25 | #include <rtems/score/isr.h> |
---|
| 26 | #include <rtems/rtems/options.h> |
---|
[2bbea657] | 27 | #include <rtems/rtems/semimpl.h> |
---|
[20e239c2] | 28 | #include <rtems/score/coremuteximpl.h> |
---|
[c4f58558] | 29 | #include <rtems/score/coresemimpl.h> |
---|
[c06d8f64] | 30 | #include <rtems/score/thread.h> |
---|
| 31 | |
---|
| 32 | #include <rtems/score/interr.h> |
---|
| 33 | |
---|
| 34 | rtems_status_code rtems_semaphore_delete( |
---|
[e7541849] | 35 | rtems_id id |
---|
[c06d8f64] | 36 | ) |
---|
| 37 | { |
---|
[3a638ce] | 38 | Semaphore_Control *the_semaphore; |
---|
[c06d8f64] | 39 | Objects_Locations location; |
---|
[8fcafdd5] | 40 | rtems_attribute attribute_set; |
---|
[c06d8f64] | 41 | |
---|
[23fec9f0] | 42 | _Objects_Allocator_lock(); |
---|
| 43 | |
---|
[c06d8f64] | 44 | the_semaphore = _Semaphore_Get( id, &location ); |
---|
| 45 | switch ( location ) { |
---|
| 46 | |
---|
| 47 | case OBJECTS_LOCAL: |
---|
[8fcafdd5] | 48 | attribute_set = the_semaphore->attribute_set; |
---|
| 49 | #if defined(RTEMS_SMP) |
---|
| 50 | if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) { |
---|
| 51 | MRSP_Status mrsp_status = _MRSP_Destroy( |
---|
| 52 | &the_semaphore->Core_control.mrsp |
---|
| 53 | ); |
---|
| 54 | if ( mrsp_status != MRSP_SUCCESSFUL ) { |
---|
| 55 | _Objects_Put( &the_semaphore->Object ); |
---|
| 56 | _Objects_Allocator_unlock(); |
---|
| 57 | return _Semaphore_Translate_MRSP_status_code( mrsp_status ); |
---|
| 58 | } |
---|
| 59 | } else |
---|
| 60 | #endif |
---|
| 61 | if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) { |
---|
[df49c60] | 62 | if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) && |
---|
[8fcafdd5] | 63 | !_Attributes_Is_simple_binary_semaphore( attribute_set ) ) { |
---|
[2d2352b] | 64 | _Objects_Put( &the_semaphore->Object ); |
---|
[23fec9f0] | 65 | _Objects_Allocator_unlock(); |
---|
[c06d8f64] | 66 | return RTEMS_RESOURCE_IN_USE; |
---|
| 67 | } |
---|
[df49c60] | 68 | _CORE_mutex_Flush( |
---|
[50f32b11] | 69 | &the_semaphore->Core_control.mutex, |
---|
[9809d6e0] | 70 | CORE_MUTEX_WAS_DELETED, |
---|
| 71 | _Semaphore_MP_Send_object_was_deleted, |
---|
| 72 | id |
---|
[df49c60] | 73 | ); |
---|
[02c4c441] | 74 | _CORE_mutex_Destroy( &the_semaphore->Core_control.mutex ); |
---|
[df49c60] | 75 | } else { |
---|
[c06d8f64] | 76 | _CORE_semaphore_Flush( |
---|
[50f32b11] | 77 | &the_semaphore->Core_control.semaphore, |
---|
[9809d6e0] | 78 | CORE_SEMAPHORE_WAS_DELETED, |
---|
| 79 | _Semaphore_MP_Send_object_was_deleted, |
---|
| 80 | id |
---|
[c06d8f64] | 81 | ); |
---|
[02c4c441] | 82 | _CORE_semaphore_Destroy( &the_semaphore->Core_control.semaphore ); |
---|
[3a01e8b] | 83 | } |
---|
[c06d8f64] | 84 | |
---|
| 85 | _Objects_Close( &_Semaphore_Information, &the_semaphore->Object ); |
---|
| 86 | |
---|
| 87 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[8fcafdd5] | 88 | if ( _Attributes_Is_global( attribute_set ) ) { |
---|
[c06d8f64] | 89 | |
---|
| 90 | _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id ); |
---|
| 91 | |
---|
| 92 | _Semaphore_MP_Send_process_packet( |
---|
| 93 | SEMAPHORE_MP_ANNOUNCE_DELETE, |
---|
| 94 | the_semaphore->Object.id, |
---|
| 95 | 0, /* Not used */ |
---|
| 96 | 0 /* Not used */ |
---|
| 97 | ); |
---|
| 98 | } |
---|
| 99 | #endif |
---|
[23fec9f0] | 100 | |
---|
[2d2352b] | 101 | _Objects_Put( &the_semaphore->Object ); |
---|
[23fec9f0] | 102 | _Semaphore_Free( the_semaphore ); |
---|
| 103 | _Objects_Allocator_unlock(); |
---|
[c06d8f64] | 104 | return RTEMS_SUCCESSFUL; |
---|
[ebe61382] | 105 | |
---|
| 106 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 107 | case OBJECTS_REMOTE: |
---|
[23fec9f0] | 108 | _Objects_Allocator_unlock(); |
---|
[ebe61382] | 109 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
| 110 | #endif |
---|
| 111 | |
---|
| 112 | case OBJECTS_ERROR: |
---|
| 113 | break; |
---|
[c06d8f64] | 114 | } |
---|
| 115 | |
---|
[23fec9f0] | 116 | _Objects_Allocator_unlock(); |
---|
[ebe61382] | 117 | return RTEMS_INVALID_ID; |
---|
[c06d8f64] | 118 | } |
---|