source: rtems/cpukit/rtems/src/semrelease.c @ 65daade

4.104.114.84.95
Last change on this file since 65daade was 1095ec1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/18/05 at 09:03:45

Include config.h.

  • Property mode set to 100644
File size: 3.0 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_release
55 *
56 *  This directive allows a thread to release a semaphore.
57 *
58 *  Input parameters:
59 *    id - semaphore id
60 *
61 *  Output parameters:
62 *    RTEMS_SUCCESSFUL - if successful
63 *    error code        - if unsuccessful
64 */
65
66#if defined(RTEMS_MULTIPROCESSING)
67#define MUTEX_MP_SUPPORT _Semaphore_Core_mutex_mp_support
68#else
69#define MUTEX_MP_SUPPORT NULL
70#endif
71
72rtems_status_code rtems_semaphore_release(
73  Objects_Id id
74)
75{
76  register Semaphore_Control *the_semaphore;
77  Objects_Locations           location;
78  CORE_mutex_Status           mutex_status;
79  CORE_semaphore_Status       semaphore_status;
80
81  the_semaphore = _Semaphore_Get( id, &location );
82  switch ( location ) {
83
84    case OBJECTS_REMOTE:
85#if defined(RTEMS_MULTIPROCESSING)
86      return _Semaphore_MP_Send_request_packet(
87        SEMAPHORE_MP_RELEASE_REQUEST,
88        id,
89        0,                               /* Not used */
90        MPCI_DEFAULT_TIMEOUT
91      );
92#endif
93
94    case OBJECTS_ERROR:
95      return RTEMS_INVALID_ID;
96
97    case OBJECTS_LOCAL:
98      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
99        mutex_status = _CORE_mutex_Surrender(
100          &the_semaphore->Core_control.mutex,
101          id,
102          MUTEX_MP_SUPPORT
103        );
104        _Thread_Enable_dispatch();
105        return _Semaphore_Translate_core_mutex_return_code( mutex_status );
106      } else {
107        semaphore_status = _CORE_semaphore_Surrender(
108          &the_semaphore->Core_control.semaphore,
109          id,
110          MUTEX_MP_SUPPORT
111        );
112        _Thread_Enable_dispatch();
113        return
114          _Semaphore_Translate_core_semaphore_return_code( semaphore_status );
115      }
116  }
117
118  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
119}
Note: See TracBrowser for help on using the repository browser.