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

5
Last change on this file since ef6f8a83 was 4025a60f, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/16 at 15:02:54

score: Avoid Giant lock for CORE mtx/sem

Avoid Giant lock for CORE mutex and semaphore flush and delete
operations.

Update #2555.

  • Property mode set to 100644
File size: 4.0 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  ISR_lock_Context            lock_context;
41  rtems_attribute             attribute_set;
42
43  _Objects_Allocator_lock();
44
45  the_semaphore = _Semaphore_Get_interrupt_disable(
46    id,
47    &location,
48    &lock_context
49  );
50  switch ( location ) {
51
52    case OBJECTS_LOCAL:
53      attribute_set = the_semaphore->attribute_set;
54#if defined(RTEMS_SMP)
55      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
56        MRSP_Status mrsp_status;
57
58        _MRSP_Acquire_critical(
59          &the_semaphore->Core_control.mrsp,
60          &lock_context
61        );
62        mrsp_status = _MRSP_Can_destroy( &the_semaphore->Core_control.mrsp );
63        if ( mrsp_status != MRSP_SUCCESSFUL ) {
64          _MRSP_Release(
65            &the_semaphore->Core_control.mrsp,
66            &lock_context
67          );
68          _Objects_Allocator_unlock();
69          return _Semaphore_Translate_MRSP_status_code( mrsp_status );
70        }
71      } else
72#endif
73      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
74        _CORE_mutex_Acquire_critical(
75          &the_semaphore->Core_control.mutex,
76          &lock_context
77        );
78
79        if (
80          _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex )
81            && !_Attributes_Is_simple_binary_semaphore( attribute_set )
82        ) {
83          _CORE_mutex_Release(
84            &the_semaphore->Core_control.mutex,
85            &lock_context
86          );
87          _Objects_Allocator_unlock();
88          return RTEMS_RESOURCE_IN_USE;
89        }
90      } else {
91        _CORE_semaphore_Acquire_critical(
92          &the_semaphore->Core_control.semaphore,
93          &lock_context
94        );
95      }
96
97      _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
98
99#if defined(RTEMS_SMP)
100      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
101        _MRSP_Destroy( &the_semaphore->Core_control.mrsp, &lock_context );
102      } else
103#endif
104      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
105        _CORE_mutex_Flush(
106          &the_semaphore->Core_control.mutex,
107          _CORE_mutex_Was_deleted,
108          _Semaphore_MP_Send_object_was_deleted,
109          id,
110          &lock_context
111        );
112        _CORE_mutex_Destroy( &the_semaphore->Core_control.mutex );
113      } else {
114        _CORE_semaphore_Destroy(
115          &the_semaphore->Core_control.semaphore,
116          _Semaphore_MP_Send_object_was_deleted,
117          id,
118          &lock_context
119        );
120      }
121
122#if defined(RTEMS_MULTIPROCESSING)
123      if ( _Attributes_Is_global( attribute_set ) ) {
124
125        _Objects_MP_Close( &_Semaphore_Information, id );
126
127        _Semaphore_MP_Send_process_packet(
128          SEMAPHORE_MP_ANNOUNCE_DELETE,
129          id,
130          0,                         /* Not used */
131          0                          /* Not used */
132        );
133      }
134#endif
135
136      _Semaphore_Free( the_semaphore );
137      _Objects_Allocator_unlock();
138      return RTEMS_SUCCESSFUL;
139
140#if defined(RTEMS_MULTIPROCESSING)
141    case OBJECTS_REMOTE:
142      _Objects_Allocator_unlock();
143      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
144#endif
145
146    case OBJECTS_ERROR:
147      break;
148  }
149
150  _Objects_Allocator_unlock();
151  return RTEMS_INVALID_ID;
152}
Note: See TracBrowser for help on using the repository browser.