source: rtems/cpukit/rtems/src/semdelete.c @ ca18cb59

5
Last change on this file since ca18cb59 was ca18cb59, checked in by Sebastian Huber <sebastian.huber@…>, on 04/18/16 at 04:53:10

score: Close semaphore object before flush

This prevents use of the object after the flush on uni-processor
configurations.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Delete Semaphore
5 *  @ingroup ClassicSem
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
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
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/rtems/status.h>
23#include <rtems/rtems/support.h>
24#include <rtems/rtems/attrimpl.h>
25#include <rtems/score/isr.h>
26#include <rtems/rtems/options.h>
27#include <rtems/rtems/semimpl.h>
28#include <rtems/score/coremuteximpl.h>
29#include <rtems/score/coresemimpl.h>
30#include <rtems/score/thread.h>
31
32#include <rtems/score/interr.h>
33
34rtems_status_code rtems_semaphore_delete(
35  rtems_id   id
36)
37{
38  Semaphore_Control          *the_semaphore;
39  Objects_Locations           location;
40  rtems_attribute             attribute_set;
41
42  _Objects_Allocator_lock();
43
44  the_semaphore = _Semaphore_Get( id, &location );
45  switch ( location ) {
46
47    case OBJECTS_LOCAL:
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;
52
53        mrsp_status = _MRSP_Can_destroy( &the_semaphore->Core_control.mrsp );
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 (
62        !_Attributes_Is_counting_semaphore( attribute_set )
63          && _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex )
64          && !_Attributes_Is_simple_binary_semaphore( attribute_set )
65      ) {
66        _Objects_Put( &the_semaphore->Object );
67        _Objects_Allocator_unlock();
68        return RTEMS_RESOURCE_IN_USE;
69      }
70
71      _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
72
73#if defined(RTEMS_MULTIPROCESSING)
74      if ( _Attributes_Is_global( attribute_set ) ) {
75
76        _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id );
77
78        _Semaphore_MP_Send_process_packet(
79          SEMAPHORE_MP_ANNOUNCE_DELETE,
80          the_semaphore->Object.id,
81          0,                         /* Not used */
82          0                          /* Not used */
83        );
84      }
85#endif
86
87#if defined(RTEMS_SMP)
88      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
89        _MRSP_Destroy( &the_semaphore->Core_control.mrsp );
90      } else
91#endif
92      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
93        _CORE_mutex_Flush(
94          &the_semaphore->Core_control.mutex,
95          CORE_MUTEX_WAS_DELETED,
96          _Semaphore_MP_Send_object_was_deleted,
97          id
98        );
99        _CORE_mutex_Destroy( &the_semaphore->Core_control.mutex );
100      } else {
101        _CORE_semaphore_Destroy(
102          &the_semaphore->Core_control.semaphore,
103          _Semaphore_MP_Send_object_was_deleted,
104          id
105        );
106      }
107
108      _Objects_Put( &the_semaphore->Object );
109      _Semaphore_Free( the_semaphore );
110      _Objects_Allocator_unlock();
111      return RTEMS_SUCCESSFUL;
112
113#if defined(RTEMS_MULTIPROCESSING)
114    case OBJECTS_REMOTE:
115      _Objects_Allocator_unlock();
116      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
117#endif
118
119    case OBJECTS_ERROR:
120      break;
121  }
122
123  _Objects_Allocator_unlock();
124  return RTEMS_INVALID_ID;
125}
Note: See TracBrowser for help on using the repository browser.