source: rtems/cpukit/include/rtems/posix/semaphoreimpl.h @ 21275b58

5
Last change on this file since 21275b58 was 21275b58, checked in by Sebastian Huber <sebastian.huber@…>, on 11/22/18 at 18:14:51

score: Static Objects_Information initialization

Statically allocate the objects information together with the initial
set of objects either via <rtems/confdefs.h>. Provide default object
informations with zero objects via librtemscpu.a. This greatly
simplifies the workspace size estimate. RTEMS applications which do not
use the unlimited objects option are easier to debug since all objects
reside now in statically allocated objects of the right types.

Close #3621.

  • Property mode set to 100644
File size: 3.2 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/semaphoreimpl.h>
25#include <rtems/seterr.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * @brief This is a random number used to check if a semaphore object is
33 * properly initialized.
34 */
35#define POSIX_SEMAPHORE_MAGIC 0x5d367fe7UL
36
37RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *
38  _POSIX_Semaphore_Allocate_unprotected( void )
39{
40  return (POSIX_Semaphore_Control *)
41    _Objects_Allocate_unprotected( &_POSIX_Semaphore_Information );
42}
43
44/**
45 *  @brief POSIX Semaphore Free
46 *
47 *  This routine frees a semaphore control block to the
48 *  inactive chain of free semaphore control blocks.
49 */
50RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free (
51  POSIX_Semaphore_Control *the_semaphore
52)
53{
54  _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object );
55}
56
57RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get(
58  sem_t *sem
59)
60{
61  return RTEMS_CONTAINER_OF( sem, POSIX_Semaphore_Control, Semaphore );
62}
63
64RTEMS_INLINE_ROUTINE bool _POSIX_Semaphore_Is_named( const sem_t *sem )
65{
66  return sem->_Semaphore._Queue._name != NULL;
67}
68
69RTEMS_INLINE_ROUTINE bool _POSIX_Semaphore_Is_busy( const sem_t *sem )
70{
71  return sem->_Semaphore._Queue._heads != NULL;
72}
73
74RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Initialize(
75  sem_t        *sem,
76  const char   *name,
77  unsigned int  value
78)
79{
80  sem->_flags = (uintptr_t) sem ^ POSIX_SEMAPHORE_MAGIC;
81  _Semaphore_Initialize_named( &sem->_Semaphore, name, value );
82}
83
84RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Destroy( sem_t *sem )
85{
86  sem->_flags = 0;
87  _Semaphore_Destroy( &sem->_Semaphore );
88}
89
90/**
91 *  @brief POSIX Semaphore Delete
92 *
93 * This routine supports the sem_close and sem_unlink routines.
94 */
95void _POSIX_Semaphore_Delete( POSIX_Semaphore_Control *the_semaphore );
96
97/**
98 *  @brief POSIX Semaphore Namespace Remove
99 */
100RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Namespace_remove (
101  POSIX_Semaphore_Control *the_semaphore
102)
103{
104  _Objects_Namespace_remove_string(
105    &_POSIX_Semaphore_Information,
106    &the_semaphore->Object
107  );
108}
109
110RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get_by_name(
111  const char                *name,
112  size_t                    *name_length_p,
113  Objects_Get_by_name_error *error
114)
115{
116  return (POSIX_Semaphore_Control *) _Objects_Get_by_name(
117    &_POSIX_Semaphore_Information,
118    name,
119    name_length_p,
120    error
121  );
122}
123
124#define POSIX_SEMAPHORE_VALIDATE_OBJECT( sem ) \
125  do { \
126    if ( \
127      ( sem ) == NULL \
128        || ( (uintptr_t) ( sem ) ^ POSIX_SEMAPHORE_MAGIC ) != ( sem )->_flags \
129    ) { \
130      rtems_set_errno_and_return_minus_one( EINVAL ); \
131    } \
132  } while ( 0 )
133
134#ifdef __cplusplus
135}
136#endif
137
138#endif
139/*  end of include file */
Note: See TracBrowser for help on using the repository browser.