source: rtems/cpukit/rtems/src/semrelease.c @ fe6c170c

4.115
Last change on this file since fe6c170c was fe6c170c, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 14:19:52

score: Create states implementation header

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

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief RTEMS Semaphore Release
5 * @ingroup ClassicSem Semaphores
6 *
7 *  DESCRIPTION:
8 *
9 *  This package is the implementation of the Semaphore Manager.
10 *  This manager utilizes standard Dijkstra counting semaphores to provide
11 *  synchronization and mutual exclusion capabilities.
12 *
13 *  Directives provided are:
14 *
15 *     + create a semaphore
16 *     + get an ID of a semaphore
17 *     + delete a semaphore
18 *     + acquire a semaphore
19 *     + release a semaphore
20 *
21 */
22
23/*
24 *  COPYRIGHT (c) 1989-2007.
25 *  On-Line Applications Research Corporation (OAR).
26 *
27 *  The license and distribution terms for this file may be
28 *  found in the file LICENSE in this distribution or at
29 *  http://www.rtems.com/license/LICENSE.
30 */
31
32#if HAVE_CONFIG_H
33#include "config.h"
34#endif
35
36#include <rtems/system.h>
37#include <rtems/rtems/status.h>
38#include <rtems/rtems/support.h>
39#include <rtems/rtems/attrimpl.h>
40#include <rtems/score/isr.h>
41#include <rtems/score/object.h>
42#include <rtems/rtems/options.h>
43#include <rtems/rtems/semimpl.h>
44#include <rtems/score/coremuteximpl.h>
45#include <rtems/score/coresemimpl.h>
46#include <rtems/score/thread.h>
47#include <rtems/score/threadq.h>
48#if defined(RTEMS_MULTIPROCESSING)
49#include <rtems/score/mpci.h>
50#endif
51
52#include <rtems/score/interr.h>
53
54/*
55 *  rtems_semaphore_release
56 *
57 *  This directive allows a thread to release a semaphore.
58 *
59 *  Input parameters:
60 *    id - semaphore id
61 *
62 *  Output parameters:
63 *    RTEMS_SUCCESSFUL - if successful
64 *    error code        - if unsuccessful
65 */
66
67#if defined(RTEMS_MULTIPROCESSING)
68#define MUTEX_MP_SUPPORT _Semaphore_Core_mutex_mp_support
69#else
70#define MUTEX_MP_SUPPORT NULL
71#endif
72
73rtems_status_code rtems_semaphore_release(
74  rtems_id   id
75)
76{
77  register Semaphore_Control *the_semaphore;
78  Objects_Locations           location;
79  CORE_mutex_Status           mutex_status;
80  CORE_semaphore_Status       semaphore_status;
81
82  the_semaphore = _Semaphore_Get( id, &location );
83  switch ( location ) {
84
85    case OBJECTS_LOCAL:
86      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
87        mutex_status = _CORE_mutex_Surrender(
88          &the_semaphore->Core_control.mutex,
89          id,
90          MUTEX_MP_SUPPORT
91        );
92        _Objects_Put( &the_semaphore->Object );
93        return _Semaphore_Translate_core_mutex_return_code( mutex_status );
94      } else {
95        semaphore_status = _CORE_semaphore_Surrender(
96          &the_semaphore->Core_control.semaphore,
97          id,
98          MUTEX_MP_SUPPORT
99        );
100        _Objects_Put( &the_semaphore->Object );
101        return
102          _Semaphore_Translate_core_semaphore_return_code( semaphore_status );
103      }
104
105#if defined(RTEMS_MULTIPROCESSING)
106    case OBJECTS_REMOTE:
107      return _Semaphore_MP_Send_request_packet(
108        SEMAPHORE_MP_RELEASE_REQUEST,
109        id,
110        0,                               /* Not used */
111        MPCI_DEFAULT_TIMEOUT
112      );
113#endif
114
115    case OBJECTS_ERROR:
116      break;
117  }
118
119  return RTEMS_INVALID_ID;
120}
Note: See TracBrowser for help on using the repository browser.