[6c2675d] | 1 | /** |
---|
| 2 | * @file rtems/posix/semaphore.h |
---|
| 3 | */ |
---|
| 4 | |
---|
[5e9b32b] | 5 | /* rtems/posix/semaphore.h |
---|
| 6 | * |
---|
| 7 | * This include file contains all the private support information for |
---|
| 8 | * POSIX Semaphores. |
---|
| 9 | * |
---|
[860c34e] | 10 | * COPYRIGHT (c) 1989-2007. |
---|
[5e9b32b] | 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
[98e4ebf5] | 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
[8e36f29] | 15 | * http://www.rtems.com/license/LICENSE. |
---|
[5e9b32b] | 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
[874297f3] | 19 | |
---|
[5ec2f12d] | 20 | #ifndef _RTEMS_POSIX_SEMAPHORE_H |
---|
| 21 | #define _RTEMS_POSIX_SEMAPHORE_H |
---|
[874297f3] | 22 | |
---|
[5e9b32b] | 23 | #ifdef __cplusplus |
---|
| 24 | extern "C" { |
---|
| 25 | #endif |
---|
| 26 | |
---|
[799c767] | 27 | #include <semaphore.h> |
---|
[5e9b32b] | 28 | #include <rtems/score/coresem.h> |
---|
| 29 | |
---|
[733a248] | 30 | #define SEM_FAILED (sem_t *) -1 |
---|
| 31 | |
---|
[5e9b32b] | 32 | /* |
---|
| 33 | * Data Structure used to manage a POSIX semaphore |
---|
| 34 | */ |
---|
[874297f3] | 35 | |
---|
[5e9b32b] | 36 | typedef struct { |
---|
| 37 | Objects_Control Object; |
---|
| 38 | int process_shared; |
---|
| 39 | boolean named; |
---|
| 40 | boolean linked; |
---|
[39cefdd] | 41 | uint32_t open_count; |
---|
[5e9b32b] | 42 | CORE_semaphore_Control Semaphore; |
---|
| 43 | } POSIX_Semaphore_Control; |
---|
| 44 | |
---|
| 45 | /* |
---|
| 46 | * The following defines the information control block used to manage |
---|
| 47 | * this class of objects. |
---|
| 48 | */ |
---|
[874297f3] | 49 | |
---|
[c627b2a3] | 50 | POSIX_EXTERN Objects_Information _POSIX_Semaphore_Information; |
---|
[874297f3] | 51 | |
---|
[5e9b32b] | 52 | /* |
---|
| 53 | * _POSIX_Semaphore_Manager_initialization |
---|
| 54 | * |
---|
| 55 | * DESCRIPTION: |
---|
| 56 | * |
---|
| 57 | * This routine performs the initialization necessary for this manager. |
---|
| 58 | */ |
---|
[874297f3] | 59 | |
---|
[5e9b32b] | 60 | void _POSIX_Semaphore_Manager_initialization( |
---|
[39cefdd] | 61 | uint32_t maximum_semaphorees |
---|
[5e9b32b] | 62 | ); |
---|
[874297f3] | 63 | |
---|
[5e9b32b] | 64 | /* |
---|
| 65 | * _POSIX_Semaphore_Allocate |
---|
| 66 | * |
---|
| 67 | * DESCRIPTION: |
---|
| 68 | * |
---|
| 69 | * This function allocates a semaphore control block from |
---|
| 70 | * the inactive chain of free semaphore control blocks. |
---|
| 71 | */ |
---|
[874297f3] | 72 | |
---|
[503dc058] | 73 | RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void ); |
---|
[874297f3] | 74 | |
---|
[5e9b32b] | 75 | /* |
---|
| 76 | * _POSIX_Semaphore_Free |
---|
| 77 | * |
---|
| 78 | * DESCRIPTION: |
---|
| 79 | * |
---|
| 80 | * This routine frees a semaphore control block to the |
---|
| 81 | * inactive chain of free semaphore control blocks. |
---|
| 82 | */ |
---|
[874297f3] | 83 | |
---|
[503dc058] | 84 | RTEMS_INLINE_ROUTINE void _POSIX_Semaphore_Free ( |
---|
[5e9b32b] | 85 | POSIX_Semaphore_Control *the_semaphore |
---|
| 86 | ); |
---|
[874297f3] | 87 | |
---|
[5e9b32b] | 88 | /* |
---|
| 89 | * _POSIX_Semaphore_Get |
---|
| 90 | * |
---|
| 91 | * DESCRIPTION: |
---|
| 92 | * |
---|
| 93 | * This function maps semaphore IDs to semaphore control blocks. |
---|
| 94 | * If ID corresponds to a local semaphore, then it returns |
---|
| 95 | * the_semaphore control pointer which maps to ID and location |
---|
| 96 | * is set to OBJECTS_LOCAL. if the semaphore ID is global and |
---|
| 97 | * resides on a remote node, then location is set to OBJECTS_REMOTE, |
---|
| 98 | * and the_semaphore is undefined. Otherwise, location is set |
---|
| 99 | * to OBJECTS_ERROR and the_semaphore is undefined. |
---|
| 100 | */ |
---|
[874297f3] | 101 | |
---|
[503dc058] | 102 | RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Get ( |
---|
[32ba727] | 103 | sem_t *id, |
---|
[5e9b32b] | 104 | Objects_Locations *location |
---|
| 105 | ); |
---|
[874297f3] | 106 | |
---|
[5e9b32b] | 107 | /* |
---|
| 108 | * _POSIX_Semaphore_Is_null |
---|
| 109 | * |
---|
| 110 | * DESCRIPTION: |
---|
| 111 | * |
---|
| 112 | * This function returns TRUE if the_semaphore is NULL and FALSE otherwise. |
---|
| 113 | */ |
---|
[874297f3] | 114 | |
---|
[503dc058] | 115 | RTEMS_INLINE_ROUTINE boolean _POSIX_Semaphore_Is_null ( |
---|
[5e9b32b] | 116 | POSIX_Semaphore_Control *the_semaphore |
---|
| 117 | ); |
---|
| 118 | |
---|
[799c767] | 119 | /* |
---|
| 120 | * _POSIX_Semaphore_Create_support |
---|
| 121 | * |
---|
| 122 | * DESCRIPTION: |
---|
| 123 | * |
---|
| 124 | * This routine supports the sem_init and sem_open routines. |
---|
| 125 | */ |
---|
| 126 | |
---|
| 127 | int _POSIX_Semaphore_Create_support( |
---|
| 128 | const char *name, |
---|
| 129 | int pshared, |
---|
| 130 | unsigned int value, |
---|
| 131 | POSIX_Semaphore_Control **the_sem |
---|
| 132 | ); |
---|
| 133 | |
---|
[2b295183] | 134 | /* |
---|
| 135 | * _POSIX_Semaphore_Delete |
---|
| 136 | * |
---|
| 137 | * DESCRIPTION: |
---|
| 138 | * |
---|
| 139 | * This routine supports the sem_close and sem_unlink routines. |
---|
| 140 | */ |
---|
| 141 | |
---|
| 142 | void _POSIX_Semaphore_Delete( |
---|
| 143 | POSIX_Semaphore_Control *the_semaphore |
---|
| 144 | ); |
---|
| 145 | |
---|
[799c767] | 146 | /* |
---|
| 147 | * _POSIX_Semaphore_Wait_support |
---|
| 148 | * |
---|
| 149 | * DESCRIPTION: |
---|
| 150 | * |
---|
| 151 | * This routine supports the sem_wait, sem_trywait, and sem_timedwait |
---|
| 152 | * services. |
---|
| 153 | */ |
---|
| 154 | |
---|
| 155 | int _POSIX_Semaphore_Wait_support( |
---|
[0c2ec7f] | 156 | sem_t *sem, |
---|
| 157 | Core_semaphore_Blocking_option blocking, |
---|
| 158 | Watchdog_Interval timeout |
---|
[799c767] | 159 | ); |
---|
| 160 | |
---|
[5e9b32b] | 161 | /* |
---|
| 162 | * _POSIX_Semaphore_Name_to_id |
---|
| 163 | * |
---|
| 164 | * DESCRIPTION: |
---|
| 165 | * |
---|
[799c767] | 166 | * This routine performs name to id translation. |
---|
[5e9b32b] | 167 | */ |
---|
| 168 | |
---|
| 169 | int _POSIX_Semaphore_Name_to_id( |
---|
| 170 | const char *name, |
---|
[32ba727] | 171 | sem_t *id |
---|
[5e9b32b] | 172 | ); |
---|
| 173 | |
---|
[860c34e] | 174 | /* |
---|
| 175 | * _POSIX_Semaphore_Translate_core_semaphore_return_code |
---|
| 176 | * |
---|
| 177 | * DESCRIPTION: |
---|
| 178 | * |
---|
| 179 | * A support routine which converts core semaphore status codes into the |
---|
| 180 | * appropriate POSIX status values. |
---|
| 181 | */ |
---|
| 182 | |
---|
| 183 | int _POSIX_Semaphore_Translate_core_semaphore_return_code( |
---|
| 184 | CORE_semaphore_Status the_semaphore_status |
---|
| 185 | ); |
---|
| 186 | |
---|
[5e9b32b] | 187 | #include <rtems/posix/semaphore.inl> |
---|
| 188 | |
---|
| 189 | #ifdef __cplusplus |
---|
| 190 | } |
---|
| 191 | #endif |
---|
[874297f3] | 192 | |
---|
[5e9b32b] | 193 | #endif |
---|
| 194 | /* end of include file */ |
---|