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

5
Last change on this file since dce48791 was dce48791, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/16 at 11:37:59

score: Add Status_Control for all APIs

Unify the status codes of the Classic and POSIX API to use the new enum
Status_Control. This eliminates the Thread_Control::Wait::timeout_code
field and the timeout parameter of _Thread_queue_Enqueue_critical() and
_MPCI_Send_request_packet(). It gets rid of the status code translation
tables and instead uses simple bit operations to get the status for a
particular API. This enables translation of status code constants at
compile time. Add _Thread_Wait_get_status() to avoid direct access of
thread internal data structures.

  • 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#include <rtems/rtems/statusimpl.h>
24
25rtems_status_code rtems_semaphore_delete(
26  rtems_id   id
27)
28{
29  Semaphore_Control    *the_semaphore;
30  Thread_queue_Context  queue_context;
31  rtems_attribute       attribute_set;
32
33  _Objects_Allocator_lock();
34  the_semaphore = _Semaphore_Get(
35    id,
36    &queue_context,
37    _Semaphore_MP_Send_object_was_deleted
38  );
39
40  if ( the_semaphore == NULL ) {
41    _Objects_Allocator_unlock();
42
43#if defined(RTEMS_MULTIPROCESSING)
44    if ( _Semaphore_MP_Is_remote( id ) ) {
45      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
46    }
47#endif
48
49    return RTEMS_INVALID_ID;
50  }
51
52  attribute_set = the_semaphore->attribute_set;
53
54#if defined(RTEMS_SMP)
55  if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
56    Status_Control status;
57
58    _MRSP_Acquire_critical(
59      &the_semaphore->Core_control.mrsp,
60      &queue_context
61    );
62    status = _MRSP_Can_destroy( &the_semaphore->Core_control.mrsp );
63    if ( status != STATUS_SUCCESSFUL ) {
64      _MRSP_Release(
65        &the_semaphore->Core_control.mrsp,
66        &queue_context
67      );
68      _Objects_Allocator_unlock();
69      return _Status_Get( 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      &queue_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        &queue_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      &queue_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, &queue_context );
102  } else
103#endif
104  if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
105    _CORE_mutex_Flush(
106      &the_semaphore->Core_control.mutex,
107      _Thread_queue_Flush_status_object_was_deleted,
108      &queue_context
109    );
110    _CORE_mutex_Destroy( &the_semaphore->Core_control.mutex );
111  } else {
112    _CORE_semaphore_Destroy(
113      &the_semaphore->Core_control.semaphore,
114      &queue_context
115    );
116  }
117
118#if defined(RTEMS_MULTIPROCESSING)
119  if ( _Attributes_Is_global( attribute_set ) ) {
120
121    _Objects_MP_Close( &_Semaphore_Information, id );
122
123    _Semaphore_MP_Send_process_packet(
124      SEMAPHORE_MP_ANNOUNCE_DELETE,
125      id,
126      0,                         /* Not used */
127      0                          /* Not used */
128    );
129  }
130#endif
131
132  _Semaphore_Free( the_semaphore );
133  _Objects_Allocator_unlock();
134  return RTEMS_SUCCESSFUL;
135}
Note: See TracBrowser for help on using the repository browser.