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

4.104.115
Last change on this file since eaef4657 was ebe61382, checked in by Joel Sherrill <joel.sherrill@…>, on 11/30/07 at 21:49:41

2007-11-30 Joel Sherrill <joel.sherrill@…>

  • rtems/src/barrierdelete.c, rtems/src/barrierrelease.c, rtems/src/barriertranslatereturncode.c, rtems/src/barrierwait.c, rtems/src/clockget.c, rtems/src/dpmemdelete.c, rtems/src/dpmemexternal2internal.c, rtems/src/dpmeminternal2external.c, rtems/src/eventsend.c, rtems/src/eventtimeout.c, rtems/src/msgqbroadcast.c, rtems/src/msgqdelete.c, rtems/src/msgqflush.c, rtems/src/msgqgetnumberpending.c, rtems/src/msgqreceive.c, rtems/src/msgqsend.c, rtems/src/msgqurgent.c, rtems/src/partdelete.c, rtems/src/partgetbuffer.c, rtems/src/partreturnbuffer.c, rtems/src/ratemoncancel.c, rtems/src/ratemondelete.c, rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c, rtems/src/ratemonresetstatistics.c, rtems/src/ratemontimeout.c, rtems/src/semdelete.c, rtems/src/semflush.c, rtems/src/semobtain.c, rtems/src/semrelease.c, rtems/src/semtranslatereturncode.c, rtems/src/signalsend.c, rtems/src/taskdelete.c, rtems/src/taskgetnote.c, rtems/src/taskissuspended.c, rtems/src/taskrestart.c, rtems/src/taskresume.c, rtems/src/tasksetnote.c, rtems/src/tasksetpriority.c, rtems/src/taskstart.c, rtems/src/tasksuspend.c, rtems/src/taskvariableadd.c, rtems/src/taskvariabledelete.c, rtems/src/taskvariableget.c, rtems/src/timercancel.c, rtems/src/timerdelete.c, rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c, rtems/src/timerreset.c, rtems/src/timerserverfireafter.c, rtems/src/timerserverfirewhen.c: Restructured all code with the switch (location) pattern so that OBJECTS_LOCAL is first and we can fall into it and the OBJECTS_ERROR case breaks to a return RTEMS_INVALID_ID. This eliminates the return RTEMS_INTERNAL_ERROR at the bottom of each of these files which was unreachable and untestable code. This resulted in a code savings of approximately 20 bytes per file on the SPARC/ERC32.
  • Property mode set to 100644
File size: 3.5 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-2007.
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_LOCAL:
85      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
86        if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) &&
87             !_Attributes_Is_simple_binary_semaphore(
88                 the_semaphore->attribute_set ) ) {
89          _Thread_Enable_dispatch();
90          return RTEMS_RESOURCE_IN_USE;
91        }
92        _CORE_mutex_Flush(
93          &the_semaphore->Core_control.mutex,
94          SEMAPHORE_MP_OBJECT_WAS_DELETED,
95          CORE_MUTEX_WAS_DELETED
96        );
97      } else {
98        _CORE_semaphore_Flush(
99          &the_semaphore->Core_control.semaphore,
100          SEMAPHORE_MP_OBJECT_WAS_DELETED,
101          CORE_SEMAPHORE_WAS_DELETED
102        );
103     }
104
105      _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
106
107      _Semaphore_Free( the_semaphore );
108
109#if defined(RTEMS_MULTIPROCESSING)
110      if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) {
111
112        _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id );
113
114        _Semaphore_MP_Send_process_packet(
115          SEMAPHORE_MP_ANNOUNCE_DELETE,
116          the_semaphore->Object.id,
117          0,                         /* Not used */
118          0                          /* Not used */
119        );
120      }
121#endif
122      _Thread_Enable_dispatch();
123      return RTEMS_SUCCESSFUL;
124
125#if defined(RTEMS_MULTIPROCESSING)
126    case OBJECTS_REMOTE:
127      _Thread_Dispatch();
128      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
129#endif
130
131    case OBJECTS_ERROR:
132      break;
133  }
134
135  return RTEMS_INVALID_ID;
136}
Note: See TracBrowser for help on using the repository browser.