source: rtems/cpukit/posix/include/rtems/posix/semaphoreimpl.h @ 90f1265e

5
Last change on this file since 90f1265e was 90f1265e, checked in by Sebastian Huber <sebastian.huber@…>, on 04/18/16 at 04:23:27

score: Fix _CORE_semaphore_Flush()

Use proper CORE_semaphore_Status for _CORE_semaphore_Flush() and
_CORE_semaphore_Destroy() operations.

Close #2696.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief Private Inlined Routines for POSIX Semaphores
5 *
6 * This include file contains the static inline implementation of the private
7 * inlined routines for POSIX Semaphores.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2013.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef _RTEMS_POSIX_SEMAPHOREIMPL_H
20#define _RTEMS_POSIX_SEMAPHOREIMPL_H
21
22#include <rtems/posix/semaphore.h>
23#include <rtems/posix/posixapi.h>
24#include <rtems/score/coresemimpl.h>
25
26#include <errno.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/**
33 *  This defines the information control block used to manage
34 *  this class of objects.
35 */
36extern Objects_Information _POSIX_Semaphore_Information;
37
38/**
39 *  This defines the mapping from Score status codes to POSIX return codes.
40 */
41extern const int
42  _POSIX_Semaphore_Return_codes[CORE_SEMAPHORE_STATUS_LAST + 1];
43
44RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *
45  _POSIX_Semaphore_Allocate_unprotected( void )
46{
47  return (POSIX_Semaphore_Control *)
48    _Objects_Allocate_unprotected( &_POSIX_Semaphore_Information );
49}
50
51/**
52 *  @brief POSIX Semaphore Free
53 *
54 *  This routine frees a semaphore control block to the
55 *  inactive chain of free semaphore control blocks.
56 */
57RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free (
58  POSIX_Semaphore_Control *the_semaphore
59)
60{
61  _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object );
62}
63
64/**
65 *  @brief POSIX Semaphore Get
66 *
67 *  This function maps semaphore IDs to semaphore control blocks.
68 *  If ID corresponds to a local semaphore, then it returns
69 *  the_semaphore control pointer which maps to ID and location
70 *  is set to OBJECTS_LOCAL.  if the semaphore ID is global and
71 *  resides on a remote node, then location is set to OBJECTS_REMOTE,
72 *  and the_semaphore is undefined.  Otherwise, location is set
73 *  to OBJECTS_ERROR and the_semaphore is undefined.
74 */
75RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get (
76  sem_t             *id,
77  Objects_Locations *location
78)
79{
80  return (POSIX_Semaphore_Control *)
81    _Objects_Get( &_POSIX_Semaphore_Information, (Objects_Id)*id, location );
82}
83
84RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *
85_POSIX_Semaphore_Get_interrupt_disable(
86  sem_t             *id,
87  Objects_Locations *location,
88  ISR_lock_Context  *lock_context
89)
90{
91  return (POSIX_Semaphore_Control *) _Objects_Get_isr_disable(
92    &_POSIX_Semaphore_Information,
93    (Objects_Id)*id,
94    location,
95    lock_context
96  );
97}
98
99/**
100 *  @brief POSIX Semaphore Create Support
101 *
102 *  This routine supports the sem_init and sem_open routines.
103 */
104
105int _POSIX_Semaphore_Create_support(
106  const char                *name,
107  size_t                     name_len,
108  int                        pshared,
109  unsigned int               value,
110  POSIX_Semaphore_Control  **the_sem
111);
112
113/**
114 *  @brief POSIX Semaphore Delete
115 *
116 * This routine supports the sem_close and sem_unlink routines.
117 */
118void _POSIX_Semaphore_Delete(
119  POSIX_Semaphore_Control *the_semaphore
120);
121
122/**
123 * @brief POSIX semaphore wait support.
124 *
125 * This routine supports the sem_wait, sem_trywait, and sem_timedwait
126 * services.
127 */
128int _POSIX_Semaphore_Wait_support(
129  sem_t               *sem,
130  bool                 blocking,
131  Watchdog_Interval    timeout
132);
133
134/**
135 *  @brief POSIX Semaphore Translate Score to POSIX Return Codes
136 *
137 *  A support routine which converts core semaphore status codes into the
138 *  appropriate POSIX status values.
139 */
140RTEMS_INLINE_ROUTINE int
141_POSIX_Semaphore_Translate_core_semaphore_return_code(
142  CORE_semaphore_Status  the_semaphore_status
143)
144{
145  /*
146   *  Internal consistency check for bad status from SuperCore
147   */
148  #if defined(RTEMS_DEBUG)
149    if ( the_semaphore_status > CORE_SEMAPHORE_STATUS_LAST )
150      return EINVAL;
151  #endif
152  return _POSIX_Semaphore_Return_codes[the_semaphore_status];
153}
154 
155/**
156 *  @brief POSIX Semaphore Namespace Remove
157 */
158RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Namespace_remove (
159  POSIX_Semaphore_Control *the_semaphore
160)
161{
162  _Objects_Namespace_remove(
163    &_POSIX_Semaphore_Information, &the_semaphore->Object );
164}
165
166RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get_by_name(
167  const char                *name,
168  size_t                    *name_length_p,
169  Objects_Get_by_name_error *error
170)
171{
172  return (POSIX_Semaphore_Control *) _Objects_Get_by_name(
173    &_POSIX_Semaphore_Information,
174    name,
175    name_length_p,
176    error
177  );
178}
179
180#ifdef __cplusplus
181}
182#endif
183
184#endif
185/*  end of include file */
Note: See TracBrowser for help on using the repository browser.