source: rtems/cpukit/posix/include/rtems/posix/semaphoreimpl.h @ 928d455

5
Last change on this file since 928d455 was c904df5, checked in by Sebastian Huber <sebastian.huber@…>, on 03/18/16 at 06:25:23

score: Add _Objects_Get_by_name()

Replace _Objects_Name_to_id_string() with _Objects_Get_by_name() since
all users of this function are interested in the object itself and not
the identifier.

Use the object allocator lock to protect the search.

Update #2555.

  • Property mode set to 100644
File size: 4.6 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  _CORE_semaphore_Destroy( &the_semaphore->Semaphore );
62  _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object );
63}
64
65/**
66 *  @brief POSIX Semaphore Get
67 *
68 *  This function maps semaphore IDs to semaphore control blocks.
69 *  If ID corresponds to a local semaphore, then it returns
70 *  the_semaphore control pointer which maps to ID and location
71 *  is set to OBJECTS_LOCAL.  if the semaphore ID is global and
72 *  resides on a remote node, then location is set to OBJECTS_REMOTE,
73 *  and the_semaphore is undefined.  Otherwise, location is set
74 *  to OBJECTS_ERROR and the_semaphore is undefined.
75 */
76RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get (
77  sem_t             *id,
78  Objects_Locations *location
79)
80{
81  return (POSIX_Semaphore_Control *)
82    _Objects_Get( &_POSIX_Semaphore_Information, (Objects_Id)*id, location );
83}
84
85RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *
86_POSIX_Semaphore_Get_interrupt_disable(
87  sem_t             *id,
88  Objects_Locations *location,
89  ISR_lock_Context  *lock_context
90)
91{
92  return (POSIX_Semaphore_Control *) _Objects_Get_isr_disable(
93    &_POSIX_Semaphore_Information,
94    (Objects_Id)*id,
95    location,
96    lock_context
97  );
98}
99
100/**
101 *  @brief POSIX Semaphore Create Support
102 *
103 *  This routine supports the sem_init and sem_open routines.
104 */
105
106int _POSIX_Semaphore_Create_support(
107  const char                *name,
108  size_t                     name_len,
109  int                        pshared,
110  unsigned int               value,
111  POSIX_Semaphore_Control  **the_sem
112);
113
114/**
115 *  @brief POSIX Semaphore Delete
116 *
117 * This routine supports the sem_close and sem_unlink routines.
118 */
119void _POSIX_Semaphore_Delete(
120  POSIX_Semaphore_Control *the_semaphore
121);
122
123/**
124 * @brief POSIX semaphore wait support.
125 *
126 * This routine supports the sem_wait, sem_trywait, and sem_timedwait
127 * services.
128 */
129int _POSIX_Semaphore_Wait_support(
130  sem_t               *sem,
131  bool                 blocking,
132  Watchdog_Interval    timeout
133);
134
135/**
136 *  @brief POSIX Semaphore Translate Score to POSIX Return Codes
137 *
138 *  A support routine which converts core semaphore status codes into the
139 *  appropriate POSIX status values.
140 */
141RTEMS_INLINE_ROUTINE int
142_POSIX_Semaphore_Translate_core_semaphore_return_code(
143  CORE_semaphore_Status  the_semaphore_status
144)
145{
146  /*
147   *  Internal consistency check for bad status from SuperCore
148   */
149  #if defined(RTEMS_DEBUG)
150    if ( the_semaphore_status > CORE_SEMAPHORE_STATUS_LAST )
151      return EINVAL;
152  #endif
153  return _POSIX_Semaphore_Return_codes[the_semaphore_status];
154}
155 
156/**
157 *  @brief POSIX Semaphore Namespace Remove
158 */
159RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Namespace_remove (
160  POSIX_Semaphore_Control *the_semaphore
161)
162{
163  _Objects_Namespace_remove(
164    &_POSIX_Semaphore_Information, &the_semaphore->Object );
165}
166
167RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get_by_name(
168  const char                *name,
169  size_t                    *name_length_p,
170  Objects_Get_by_name_error *error
171)
172{
173  return (POSIX_Semaphore_Control *) _Objects_Get_by_name(
174    &_POSIX_Semaphore_Information,
175    name,
176    name_length_p,
177    error
178  );
179}
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif
186/*  end of include file */
Note: See TracBrowser for help on using the repository browser.