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

4.115
Last change on this file since a2e3f33 was a2e3f33, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 11:50:54

score: Create object implementation header

Move implementation specific parts of object.h and object.inl into new
header file objectimpl.h. The object.h contains now only the
application visible API.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Delete Semaphore
5 *  @ingroup ClassicSem
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
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.com/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
34#if defined(RTEMS_MULTIPROCESSING)
35#define SEMAPHORE_MP_OBJECT_WAS_DELETED _Semaphore_MP_Send_object_was_deleted
36#else
37#define SEMAPHORE_MP_OBJECT_WAS_DELETED NULL
38#endif
39
40rtems_status_code rtems_semaphore_delete(
41  rtems_id   id
42)
43{
44  register Semaphore_Control *the_semaphore;
45  Objects_Locations           location;
46
47  the_semaphore = _Semaphore_Get( id, &location );
48  switch ( location ) {
49
50    case OBJECTS_LOCAL:
51      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
52        if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) &&
53             !_Attributes_Is_simple_binary_semaphore(
54                 the_semaphore->attribute_set ) ) {
55          _Objects_Put( &the_semaphore->Object );
56          return RTEMS_RESOURCE_IN_USE;
57        }
58        _CORE_mutex_Flush(
59          &the_semaphore->Core_control.mutex,
60          SEMAPHORE_MP_OBJECT_WAS_DELETED,
61          CORE_MUTEX_WAS_DELETED
62        );
63      } else {
64        _CORE_semaphore_Flush(
65          &the_semaphore->Core_control.semaphore,
66          SEMAPHORE_MP_OBJECT_WAS_DELETED,
67          CORE_SEMAPHORE_WAS_DELETED
68        );
69     }
70
71      _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
72
73      _Semaphore_Free( the_semaphore );
74
75#if defined(RTEMS_MULTIPROCESSING)
76      if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) {
77
78        _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id );
79
80        _Semaphore_MP_Send_process_packet(
81          SEMAPHORE_MP_ANNOUNCE_DELETE,
82          the_semaphore->Object.id,
83          0,                         /* Not used */
84          0                          /* Not used */
85        );
86      }
87#endif
88      _Objects_Put( &the_semaphore->Object );
89      return RTEMS_SUCCESSFUL;
90
91#if defined(RTEMS_MULTIPROCESSING)
92    case OBJECTS_REMOTE:
93      _Thread_Dispatch();
94      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
95#endif
96
97    case OBJECTS_ERROR:
98      break;
99  }
100
101  return RTEMS_INVALID_ID;
102}
Note: See TracBrowser for help on using the repository browser.