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

4.104.114.84.95
Last change on this file since f7d4f0a was e7541849, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/04/05 at 15:09:39

Use rtems_id for semaphores.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  Semaphore Manager
3 *
4 *  DESCRIPTION:
5 *
6 *  This package is the implementation of the Semaphore Manager.
7 *  This manager utilizes standard Dijkstra counting semaphores to provide
8 *  synchronization and mutual exclusion capabilities.
9 *
10 *  Directives provided are:
11 *
12 *     + create a semaphore
13 *     + get an ID of a semaphore
14 *     + delete a semaphore
15 *     + acquire a semaphore
16 *     + release a semaphore
17 *
18 *  COPYRIGHT (c) 1989-1999.
19 *  On-Line Applications Research Corporation (OAR).
20 *
21 *  The license and distribution terms for this file may be
22 *  found in the file LICENSE in this distribution or at
23 *  http://www.rtems.com/license/LICENSE.
24 *
25 *  $Id$
26 */
27
28#if HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <rtems/system.h>
33#include <rtems/rtems/status.h>
34#include <rtems/rtems/support.h>
35#include <rtems/rtems/attr.h>
36#include <rtems/score/isr.h>
37#include <rtems/score/object.h>
38#include <rtems/rtems/options.h>
39#include <rtems/rtems/sem.h>
40#include <rtems/score/coremutex.h>
41#include <rtems/score/coresem.h>
42#include <rtems/score/states.h>
43#include <rtems/score/thread.h>
44#include <rtems/score/threadq.h>
45#if defined(RTEMS_MULTIPROCESSING)
46#include <rtems/score/mpci.h>
47#endif
48#include <rtems/score/sysstate.h>
49
50#include <rtems/score/interr.h>
51
52/*PAGE
53 *
54 *  rtems_semaphore_delete
55 *
56 *  This directive allows a thread to delete a semaphore specified by
57 *  the semaphore id.  The semaphore is freed back to the inactive
58 *  semaphore chain.
59 *
60 *  Input parameters:
61 *    id - semaphore id
62 *
63 *  Output parameters:
64 *    RTEMS_SUCCESSFUL - if successful
65 *    error code       - if unsuccessful
66 */
67
68#if defined(RTEMS_MULTIPROCESSING)
69#define SEMAPHORE_MP_OBJECT_WAS_DELETED _Semaphore_MP_Send_object_was_deleted
70#else
71#define SEMAPHORE_MP_OBJECT_WAS_DELETED NULL
72#endif
73
74rtems_status_code rtems_semaphore_delete(
75  rtems_id   id
76)
77{
78  register Semaphore_Control *the_semaphore;
79  Objects_Locations           location;
80
81  the_semaphore = _Semaphore_Get( id, &location );
82  switch ( location ) {
83
84    case OBJECTS_REMOTE:
85#if defined(RTEMS_MULTIPROCESSING)
86      _Thread_Dispatch();
87      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
88#endif
89
90    case OBJECTS_ERROR:
91      return RTEMS_INVALID_ID;
92
93    case OBJECTS_LOCAL:
94      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
95        if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) &&
96             !_Attributes_Is_simple_binary_semaphore(
97                 the_semaphore->attribute_set ) ) {
98          _Thread_Enable_dispatch();
99          return RTEMS_RESOURCE_IN_USE;
100        }
101        _CORE_mutex_Flush(
102          &the_semaphore->Core_control.mutex,
103          SEMAPHORE_MP_OBJECT_WAS_DELETED,
104          CORE_MUTEX_WAS_DELETED
105        );
106      } else {
107        _CORE_semaphore_Flush(
108          &the_semaphore->Core_control.semaphore,
109          SEMAPHORE_MP_OBJECT_WAS_DELETED,
110          CORE_SEMAPHORE_WAS_DELETED
111        );
112     }
113
114      _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
115
116      _Semaphore_Free( the_semaphore );
117
118#if defined(RTEMS_MULTIPROCESSING)
119      if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) {
120
121        _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id );
122
123        _Semaphore_MP_Send_process_packet(
124          SEMAPHORE_MP_ANNOUNCE_DELETE,
125          the_semaphore->Object.id,
126          0,                         /* Not used */
127          0                          /* Not used */
128        );
129      }
130#endif
131      _Thread_Enable_dispatch();
132      return RTEMS_SUCCESSFUL;
133  }
134
135  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
136}
Note: See TracBrowser for help on using the repository browser.