OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems/] [c/] [src/] [exec/] [rtems/] [src/] [semdelete.c] - Blame information for rev 208

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 158 chris
/*
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.OARcorp.com/rtems/license.html.
24
 *
25 208 chris
 *  $Id: semdelete.c,v 1.2 2001-09-27 11:59:19 chris Exp $
26 158 chris
 */
27
 
28
#include <rtems/system.h>
29
#include <rtems/rtems/status.h>
30
#include <rtems/rtems/support.h>
31
#include <rtems/rtems/attr.h>
32
#include <rtems/score/isr.h>
33
#include <rtems/score/object.h>
34
#include <rtems/rtems/options.h>
35
#include <rtems/rtems/sem.h>
36
#include <rtems/score/coremutex.h>
37
#include <rtems/score/coresem.h>
38
#include <rtems/score/states.h>
39
#include <rtems/score/thread.h>
40
#include <rtems/score/threadq.h>
41
#if defined(RTEMS_MULTIPROCESSING)
42
#include <rtems/score/mpci.h>
43
#endif
44
#include <rtems/score/sysstate.h>
45
 
46
#include <rtems/score/interr.h>
47
 
48
/*PAGE
49
 *
50
 *  rtems_semaphore_delete
51
 *
52
 *  This directive allows a thread to delete a semaphore specified by
53
 *  the semaphore id.  The semaphore is freed back to the inactive
54
 *  semaphore chain.
55
 *
56
 *  Input parameters:
57
 *    id - semaphore id
58
 *
59
 *  Output parameters:
60
 *    RTEMS_SUCCESSFUL - if successful
61
 *    error code        - if unsuccessful
62
 */
63
 
64
#if defined(RTEMS_MULTIPROCESSING)
65
#define SEMAPHORE_MP_OBJECT_WAS_DELETED _Semaphore_MP_Send_object_was_deleted
66
#else
67
#define SEMAPHORE_MP_OBJECT_WAS_DELETED NULL
68
#endif
69
 
70
rtems_status_code rtems_semaphore_delete(
71
  Objects_Id id
72
)
73
{
74
  register Semaphore_Control *the_semaphore;
75
  Objects_Locations           location;
76
 
77
  the_semaphore = _Semaphore_Get( id, &location );
78
  switch ( location ) {
79
 
80
    case OBJECTS_REMOTE:
81
#if defined(RTEMS_MULTIPROCESSING)
82
      _Thread_Dispatch();
83
      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
84
#endif
85
 
86
    case OBJECTS_ERROR:
87
      return RTEMS_INVALID_ID;
88
 
89
    case OBJECTS_LOCAL:
90
      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
91
        if ( _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex ) &&
92
             !_Attributes_Is_simple_binary_semaphore(
93
                 the_semaphore->attribute_set ) ) {
94
          _Thread_Enable_dispatch();
95
          return RTEMS_RESOURCE_IN_USE;
96
        }
97
        _CORE_mutex_Flush(
98
          &the_semaphore->Core_control.mutex,
99
          SEMAPHORE_MP_OBJECT_WAS_DELETED,
100
          CORE_MUTEX_WAS_DELETED
101
        );
102
      } else {
103
        _CORE_semaphore_Flush(
104
          &the_semaphore->Core_control.semaphore,
105
          SEMAPHORE_MP_OBJECT_WAS_DELETED,
106
          CORE_SEMAPHORE_WAS_DELETED
107
        );
108
     }
109
 
110
      _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
111
 
112
      _Semaphore_Free( the_semaphore );
113
 
114
#if defined(RTEMS_MULTIPROCESSING)
115
      if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) {
116
 
117
        _Objects_MP_Close( &_Semaphore_Information, the_semaphore->Object.id );
118
 
119
        _Semaphore_MP_Send_process_packet(
120
          SEMAPHORE_MP_ANNOUNCE_DELETE,
121
          the_semaphore->Object.id,
122
          0,                         /* Not used */
123
 
124
        );
125
      }
126
#endif
127
      _Thread_Enable_dispatch();
128
      return RTEMS_SUCCESSFUL;
129
  }
130
 
131
  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
132
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.