RTEMS  5.1
semaphoreimpl.h
Go to the documentation of this file.
1 
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>
25 #include <rtems/seterr.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
35 #define POSIX_SEMAPHORE_MAGIC 0x5d367fe7UL
36 
38  _POSIX_Semaphore_Allocate_unprotected( void )
39 {
40  return (POSIX_Semaphore_Control *)
42 }
43 
51  POSIX_Semaphore_Control *the_semaphore
52 )
53 {
54  _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object );
55 }
56 
57 RTEMS_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 
64 RTEMS_INLINE_ROUTINE bool _POSIX_Semaphore_Is_named( const sem_t *sem )
65 {
66  return sem->_Semaphore._Queue._name != NULL;
67 }
68 
69 RTEMS_INLINE_ROUTINE bool _POSIX_Semaphore_Is_busy( const sem_t *sem )
70 {
71  return sem->_Semaphore._Queue._heads != NULL;
72 }
73 
74 RTEMS_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 
84 RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Destroy( sem_t *sem )
85 {
86  sem->_flags = 0;
87  _Semaphore_Destroy( &sem->_Semaphore );
88 }
89 
96 
101  POSIX_Semaphore_Control *the_semaphore
102 )
103 {
106  &the_semaphore->Object
107  );
108 }
109 
110 RTEMS_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 {
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 */
Semaphore Implementation.
RTEMS_INLINE_ROUTINE Objects_Control * _Objects_Allocate_unprotected(Objects_Information *information)
Allocates an object without locking the allocator mutex.
Definition: objectimpl.h:874
Data which Ease the Burden of Consistently Setting Errno.
POSIX API Implementation.
Definition: semaphore.h:44
#define RTEMS_CONTAINER_OF(_m, _type, _member_name)
Returns a pointer to the container of a specified member pointer.
Definition: basedefs.h:430
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:26
#define POSIX_SEMAPHORE_MAGIC
This is a random number used to check if a semaphore object is properly initialized.
Definition: semaphoreimpl.h:35
RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Namespace_remove(POSIX_Semaphore_Control *the_semaphore)
POSIX Semaphore Namespace Remove.
Definition: semaphoreimpl.h:100
RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free(POSIX_Semaphore_Control *the_semaphore)
POSIX Semaphore Free.
Definition: semaphoreimpl.h:50
Objects_Information _POSIX_Semaphore_Information
The POSIX Semaphore objects information.
RTEMS_INLINE_ROUTINE void _Objects_Free(Objects_Information *information, Objects_Control *the_object)
Frees an object.
Definition: objectimpl.h:930
Private Support Information for POSIX Semaphores.
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:25
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
void _POSIX_Semaphore_Delete(POSIX_Semaphore_Control *the_semaphore)
POSIX Semaphore Delete.
Definition: semaphoredeletesupp.c:23
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77