source: rtems/cpukit/posix/include/rtems/posix/semaphoreimpl.h @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 4.4 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 */
36POSIX_EXTERN 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
44/**
45 *  @brief POSIX Semaphore Manager Initialization
46 *
47 *  This routine performs the initialization necessary for this manager.
48 */
49void _POSIX_Semaphore_Manager_initialization(void);
50
51/**
52 *  @brief POSIX Semaphore Allocate
53 *
54 *  This function allocates a semaphore control block from
55 *  the inactive chain of free semaphore control blocks.
56 */
57
58RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void )
59{
60  return (POSIX_Semaphore_Control *)
61    _Objects_Allocate( &_POSIX_Semaphore_Information );
62}
63
64
65/**
66 *  @brief POSIX Semaphore Free
67 *
68 *  This routine frees a semaphore control block to the
69 *  inactive chain of free semaphore control blocks.
70 */
71RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free (
72  POSIX_Semaphore_Control *the_semaphore
73)
74{
75  _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object );
76}
77
78/**
79 *  @brief POSIX Semaphore Get
80 *
81 *  This function maps semaphore IDs to semaphore control blocks.
82 *  If ID corresponds to a local semaphore, then it returns
83 *  the_semaphore control pointer which maps to ID and location
84 *  is set to OBJECTS_LOCAL.  if the semaphore ID is global and
85 *  resides on a remote node, then location is set to OBJECTS_REMOTE,
86 *  and the_semaphore is undefined.  Otherwise, location is set
87 *  to OBJECTS_ERROR and the_semaphore is undefined.
88 */
89RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get (
90  sem_t             *id,
91  Objects_Locations *location
92)
93{
94  return (POSIX_Semaphore_Control *)
95    _Objects_Get( &_POSIX_Semaphore_Information, (Objects_Id)*id, location );
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 
166/**
167 * @see _POSIX_Name_to_id().
168 */
169RTEMS_INLINE_ROUTINE int _POSIX_Semaphore_Name_to_id(
170  const char *name,
171  Objects_Id *id,
172  size_t     *len
173)
174{
175  return _POSIX_Name_to_id( &_POSIX_Semaphore_Information, name, id, len );
176}
177
178#ifdef __cplusplus
179}
180#endif
181
182#endif
183/*  end of include file */
Note: See TracBrowser for help on using the repository browser.