File indexing completed on 2025-05-11 08:24:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #ifndef _RTEMS_POSIX_SEMAPHOREIMPL_H
0039 #define _RTEMS_POSIX_SEMAPHOREIMPL_H
0040
0041 #include <rtems/posix/semaphore.h>
0042 #include <rtems/posix/posixapi.h>
0043 #include <rtems/score/semaphoreimpl.h>
0044 #include <rtems/seterr.h>
0045
0046 #ifdef __cplusplus
0047 extern "C" {
0048 #endif
0049
0050
0051
0052
0053
0054 #define POSIX_SEMAPHORE_MAGIC 0x5d367fe7UL
0055
0056 static inline POSIX_Semaphore_Control *
0057 _POSIX_Semaphore_Allocate_unprotected( void )
0058 {
0059 return (POSIX_Semaphore_Control *)
0060 _Objects_Allocate_unprotected( &_POSIX_Semaphore_Information );
0061 }
0062
0063
0064
0065
0066
0067
0068
0069 static inline void _POSIX_Semaphore_Free (
0070 POSIX_Semaphore_Control *the_semaphore
0071 )
0072 {
0073 _Objects_Free( &_POSIX_Semaphore_Information, &the_semaphore->Object );
0074 }
0075
0076 static inline POSIX_Semaphore_Control *_POSIX_Semaphore_Get(
0077 sem_t *sem
0078 )
0079 {
0080 return RTEMS_CONTAINER_OF( sem, POSIX_Semaphore_Control, Semaphore );
0081 }
0082
0083 static inline bool _POSIX_Semaphore_Is_named( const sem_t *sem )
0084 {
0085 return sem->_Semaphore._Queue._name != NULL;
0086 }
0087
0088 static inline bool _POSIX_Semaphore_Is_busy( const sem_t *sem )
0089 {
0090 return sem->_Semaphore._Queue._heads != NULL;
0091 }
0092
0093 static inline void _POSIX_Semaphore_Initialize(
0094 sem_t *sem,
0095 const char *name,
0096 unsigned int value
0097 )
0098 {
0099 sem->_flags = (uintptr_t) sem ^ POSIX_SEMAPHORE_MAGIC;
0100 _Semaphore_Initialize_named( &sem->_Semaphore, name, value );
0101 }
0102
0103 static inline void _POSIX_Semaphore_Destroy( sem_t *sem )
0104 {
0105 sem->_flags = 0;
0106 _Semaphore_Destroy( &sem->_Semaphore );
0107 }
0108
0109
0110
0111
0112
0113
0114 void _POSIX_Semaphore_Delete( POSIX_Semaphore_Control *the_semaphore );
0115
0116
0117
0118
0119 static inline void _POSIX_Semaphore_Namespace_remove (
0120 POSIX_Semaphore_Control *the_semaphore
0121 )
0122 {
0123 _Objects_Namespace_remove_string(
0124 &_POSIX_Semaphore_Information,
0125 &the_semaphore->Object
0126 );
0127 }
0128
0129 static inline POSIX_Semaphore_Control *_POSIX_Semaphore_Get_by_name(
0130 const char *name,
0131 size_t *name_length_p,
0132 Objects_Get_by_name_error *error
0133 )
0134 {
0135 return (POSIX_Semaphore_Control *) _Objects_Get_by_name(
0136 &_POSIX_Semaphore_Information,
0137 name,
0138 name_length_p,
0139 error
0140 );
0141 }
0142
0143 #define POSIX_SEMAPHORE_VALIDATE_OBJECT( sem ) \
0144 do { \
0145 if ( \
0146 ( sem ) == NULL \
0147 || ( (uintptr_t) ( sem ) ^ POSIX_SEMAPHORE_MAGIC ) != ( sem )->_flags \
0148 ) { \
0149 rtems_set_errno_and_return_minus_one( EINVAL ); \
0150 } \
0151 } while ( 0 )
0152
0153 #ifdef __cplusplus
0154 }
0155 #endif
0156
0157 #endif
0158