RTEMS 6.1-rc5
Loading...
Searching...
No Matches
semaphoreimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * COPYRIGHT (c) 1989-2013.
14 * On-Line Applications Research Corporation (OAR).
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _RTEMS_POSIX_SEMAPHOREIMPL_H
39#define _RTEMS_POSIX_SEMAPHOREIMPL_H
40
44#include <rtems/seterr.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
54#define POSIX_SEMAPHORE_MAGIC 0x5d367fe7UL
55
56static inline POSIX_Semaphore_Control *
57 _POSIX_Semaphore_Allocate_unprotected( void )
58{
60 _Objects_Allocate_unprotected( &_POSIX_Semaphore_Information );
61}
62
69static inline void _POSIX_Semaphore_Free (
70 POSIX_Semaphore_Control *the_semaphore
71)
72{
73 _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object );
74}
75
76static inline POSIX_Semaphore_Control *_POSIX_Semaphore_Get(
77 sem_t *sem
78)
79{
80 return RTEMS_CONTAINER_OF( sem, POSIX_Semaphore_Control, Semaphore );
81}
82
83static inline bool _POSIX_Semaphore_Is_named( const sem_t *sem )
84{
85 return sem->_Semaphore._Queue._name != NULL;
86}
87
88static inline bool _POSIX_Semaphore_Is_busy( const sem_t *sem )
89{
90 return sem->_Semaphore._Queue._heads != NULL;
91}
92
93static inline void _POSIX_Semaphore_Initialize(
94 sem_t *sem,
95 const char *name,
96 unsigned int value
97)
98{
99 sem->_flags = (uintptr_t) sem ^ POSIX_SEMAPHORE_MAGIC;
100 _Semaphore_Initialize_named( &sem->_Semaphore, name, value );
101}
102
103static inline void _POSIX_Semaphore_Destroy( sem_t *sem )
104{
105 sem->_flags = 0;
106 _Semaphore_Destroy( &sem->_Semaphore );
107}
108
115
119static inline void _POSIX_Semaphore_Namespace_remove (
120 POSIX_Semaphore_Control *the_semaphore
121)
122{
125 &the_semaphore->Object
126 );
127}
128
129static inline POSIX_Semaphore_Control *_POSIX_Semaphore_Get_by_name(
130 const char *name,
131 size_t *name_length_p,
132 Objects_Get_by_name_error *error
133)
134{
137 name,
138 name_length_p,
139 error
140 );
141}
142
143#define POSIX_SEMAPHORE_VALIDATE_OBJECT( sem ) \
144 do { \
145 if ( \
146 ( sem ) == NULL \
147 || ( (uintptr_t) ( sem ) ^ POSIX_SEMAPHORE_MAGIC ) != ( sem )->_flags \
148 ) { \
149 rtems_set_errno_and_return_minus_one( EINVAL ); \
150 } \
151 } while ( 0 )
152
153#ifdef __cplusplus
154}
155#endif
156
157#endif
158/* end of include file */
Objects_Information _POSIX_Semaphore_Information
The POSIX Semaphore objects information.
#define RTEMS_CONTAINER_OF(_m, _type, _member_name)
Gets the container of a member.
Definition: basedefs.h:306
Objects_Control * _Objects_Get_by_name(const Objects_Information *information, const char *name, size_t *name_length_p, Objects_Get_by_name_error *error)
Gets an object control block identified by its name.
Definition: objectnametoidstring.c:46
void _Objects_Namespace_remove_string(const Objects_Information *information, Objects_Control *the_object)
Removes object with a string name from its namespace.
Definition: objectnamespaceremove.c:45
void _POSIX_Semaphore_Delete(POSIX_Semaphore_Control *the_semaphore)
POSIX Semaphore Delete.
Definition: semaphoredeletesupp.c:42
#define POSIX_SEMAPHORE_MAGIC
This is a random number used to check if a semaphore object is properly initialized.
Definition: semaphoreimpl.h:54
This header file provides interfaces used by the POSIX API implementation.
This header file provides the interfaces of the System Lock Semaphore Support.
Private Support Information for POSIX Semaphores.
This header file defines macros to set errno and return minus one.
Definition: semaphore.h:63