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

5
Last change on this file since c3d8d9e was c3d8d9e, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/16 at 04:55:49

score: Get rid of mp_id parameter

Get rid of the mp_id parameter used for some thread queue methods. Use
THREAD_QUEUE_QUEUE_TO_OBJECT() instead.

  • Property mode set to 100644
File size: 3.2 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/rtems/semimpl.h>
22#include <rtems/rtems/attrimpl.h>
23
24rtems_status_code rtems_semaphore_delete(
25  rtems_id   id
26)
27{
28  Semaphore_Control *the_semaphore;
29  ISR_lock_Context   lock_context;
30  rtems_attribute    attribute_set;
31
32  _Objects_Allocator_lock();
33  the_semaphore = _Semaphore_Get( id, &lock_context );
34
35  if ( the_semaphore == NULL ) {
36    _Objects_Allocator_unlock();
37
38#if defined(RTEMS_MULTIPROCESSING)
39    if ( _Semaphore_MP_Is_remote( id ) ) {
40      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
41    }
42#endif
43
44    return RTEMS_INVALID_ID;
45  }
46
47  attribute_set = the_semaphore->attribute_set;
48
49#if defined(RTEMS_SMP)
50  if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
51    MRSP_Status mrsp_status;
52
53    _MRSP_Acquire_critical(
54      &the_semaphore->Core_control.mrsp,
55      &lock_context
56    );
57    mrsp_status = _MRSP_Can_destroy( &the_semaphore->Core_control.mrsp );
58    if ( mrsp_status != MRSP_SUCCESSFUL ) {
59      _MRSP_Release(
60        &the_semaphore->Core_control.mrsp,
61        &lock_context
62      );
63      _Objects_Allocator_unlock();
64      return _Semaphore_Translate_MRSP_status_code( mrsp_status );
65    }
66  } else
67#endif
68  if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
69    _CORE_mutex_Acquire_critical(
70      &the_semaphore->Core_control.mutex,
71      &lock_context
72    );
73
74    if (
75      _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex )
76        && !_Attributes_Is_simple_binary_semaphore( attribute_set )
77    ) {
78      _CORE_mutex_Release(
79        &the_semaphore->Core_control.mutex,
80        &lock_context
81      );
82      _Objects_Allocator_unlock();
83      return RTEMS_RESOURCE_IN_USE;
84    }
85  } else {
86    _CORE_semaphore_Acquire_critical(
87      &the_semaphore->Core_control.semaphore,
88      &lock_context
89    );
90  }
91
92  _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
93
94#if defined(RTEMS_SMP)
95  if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
96    _MRSP_Destroy( &the_semaphore->Core_control.mrsp, &lock_context );
97  } else
98#endif
99  if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
100    _CORE_mutex_Flush(
101      &the_semaphore->Core_control.mutex,
102      _CORE_mutex_Was_deleted,
103      _Semaphore_MP_Send_object_was_deleted,
104      &lock_context
105    );
106    _CORE_mutex_Destroy( &the_semaphore->Core_control.mutex );
107  } else {
108    _CORE_semaphore_Destroy(
109      &the_semaphore->Core_control.semaphore,
110      _Semaphore_MP_Send_object_was_deleted,
111      &lock_context
112    );
113  }
114
115#if defined(RTEMS_MULTIPROCESSING)
116  if ( _Attributes_Is_global( attribute_set ) ) {
117
118    _Objects_MP_Close( &_Semaphore_Information, id );
119
120    _Semaphore_MP_Send_process_packet(
121      SEMAPHORE_MP_ANNOUNCE_DELETE,
122      id,
123      0,                         /* Not used */
124      0                          /* Not used */
125    );
126  }
127#endif
128
129  _Semaphore_Free( the_semaphore );
130  _Objects_Allocator_unlock();
131  return RTEMS_SUCCESSFUL;
132}
Note: See TracBrowser for help on using the repository browser.