[f9d533a5] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief Private Inlined Routines for POSIX Mutex's. |
---|
| 5 | * |
---|
| 6 | * This include file contains the static inline implementation of the private |
---|
| 7 | * inlined routines for POSIX mutex's. |
---|
| 8 | */ |
---|
| 9 | |
---|
[4600bd7c] | 10 | /* COPYRIGHT (c) 1989-2013. |
---|
[f9d533a5] | 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
| 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 15 | * http://www.rtems.org/license/LICENSE. |
---|
[f9d533a5] | 16 | */ |
---|
| 17 | |
---|
[b8bdced1] | 18 | #ifndef _RTEMS_POSIX_MUTEXIMPL_H |
---|
| 19 | #define _RTEMS_POSIX_MUTEXIMPL_H |
---|
| 20 | |
---|
[f9d533a5] | 21 | #include <rtems/posix/mutex.h> |
---|
[20e239c2] | 22 | #include <rtems/score/coremuteximpl.h> |
---|
[f9d533a5] | 23 | |
---|
[9728ef3] | 24 | #include <errno.h> |
---|
[b8bdced1] | 25 | #include <pthread.h> |
---|
[f9d533a5] | 26 | |
---|
| 27 | #ifdef __cplusplus |
---|
| 28 | extern "C" { |
---|
| 29 | #endif |
---|
| 30 | |
---|
[4600bd7c] | 31 | /** |
---|
[f9d533a5] | 32 | * The following defines the information control block used to manage |
---|
| 33 | * this class of objects. |
---|
| 34 | */ |
---|
[9871f5dc] | 35 | extern Objects_Information _POSIX_Mutex_Information; |
---|
[f9d533a5] | 36 | |
---|
[4600bd7c] | 37 | /** |
---|
[f9d533a5] | 38 | * The default mutex attributes structure. |
---|
| 39 | */ |
---|
[9871f5dc] | 40 | extern pthread_mutexattr_t _POSIX_Mutex_Default_attributes; |
---|
[f9d533a5] | 41 | |
---|
[4600bd7c] | 42 | /** |
---|
| 43 | * This array contains a mapping from Score Mutex return codes to |
---|
| 44 | * POSIX return codes. |
---|
| 45 | */ |
---|
[9728ef3] | 46 | extern const int _POSIX_Mutex_Return_codes[CORE_MUTEX_STATUS_LAST + 1]; |
---|
| 47 | |
---|
[4600bd7c] | 48 | /** |
---|
| 49 | * @brief POSIX Mutex Allocate |
---|
[f9d533a5] | 50 | * |
---|
| 51 | * This function allocates a mutexes control block from |
---|
| 52 | * the inactive chain of free mutexes control blocks. |
---|
| 53 | */ |
---|
[4600bd7c] | 54 | RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void ) |
---|
| 55 | { |
---|
| 56 | return (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information ); |
---|
| 57 | } |
---|
[f9d533a5] | 58 | |
---|
[4600bd7c] | 59 | /** |
---|
| 60 | * @brief POSIX Mutex Free |
---|
[f9d533a5] | 61 | * |
---|
| 62 | * This routine frees a mutexes control block to the |
---|
| 63 | * inactive chain of free mutexes control blocks. |
---|
| 64 | */ |
---|
[4600bd7c] | 65 | RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Free( |
---|
[f9d533a5] | 66 | POSIX_Mutex_Control *the_mutex |
---|
[4600bd7c] | 67 | ) |
---|
| 68 | { |
---|
[02c4c441] | 69 | _CORE_mutex_Destroy( &the_mutex->Mutex ); |
---|
[4600bd7c] | 70 | _Objects_Free( &_POSIX_Mutex_Information, &the_mutex->Object ); |
---|
| 71 | } |
---|
[f9d533a5] | 72 | |
---|
| 73 | |
---|
[4600bd7c] | 74 | /** |
---|
| 75 | * @brief POSIX Mutex Lock Support Method |
---|
[f9d533a5] | 76 | * |
---|
| 77 | * A support routine which implements guts of the blocking, non-blocking, and |
---|
| 78 | * timed wait version of mutex lock. |
---|
| 79 | */ |
---|
| 80 | int _POSIX_Mutex_Lock_support( |
---|
| 81 | pthread_mutex_t *mutex, |
---|
| 82 | bool blocking, |
---|
| 83 | Watchdog_Interval timeout |
---|
| 84 | ); |
---|
| 85 | |
---|
| 86 | /** |
---|
[4600bd7c] | 87 | * @brief Convert Score mutex status codes into POSIX status values |
---|
[f9d533a5] | 88 | * |
---|
| 89 | * A support routine which converts core mutex status codes into the |
---|
| 90 | * appropriate POSIX status values. |
---|
| 91 | * |
---|
| 92 | * @param[in] the_mutex_status is the mutex status code to translate |
---|
| 93 | * |
---|
| 94 | * @retval 0 Mutex status code indicates the operation completed successfully. |
---|
| 95 | * @retval EBUSY Mutex status code indicates that the operation unable to |
---|
[4600bd7c] | 96 | * complete immediately because the resource was unavailable. |
---|
[f9d533a5] | 97 | * @retval EDEADLK Mutex status code indicates that an attempt was made to |
---|
[4600bd7c] | 98 | * relock a mutex for which nesting is not configured. |
---|
[f9d533a5] | 99 | * @retval EPERM Mutex status code indicates that an attempt was made to |
---|
[4600bd7c] | 100 | * release a mutex by a thread other than the thread which locked it. |
---|
[f9d533a5] | 101 | * @retval EINVAL Mutex status code indicates that the thread was blocked |
---|
[4600bd7c] | 102 | * waiting for an operation to complete and the mutex was deleted. |
---|
[f9d533a5] | 103 | * @retval ETIMEDOUT Mutex status code indicates that the calling task was |
---|
[4600bd7c] | 104 | * willing to block but the operation was unable to complete |
---|
| 105 | * within the time allotted because the resource never became |
---|
| 106 | * available. |
---|
[f9d533a5] | 107 | */ |
---|
[9728ef3] | 108 | RTEMS_INLINE_ROUTINE int _POSIX_Mutex_Translate_core_mutex_return_code( |
---|
[f9d533a5] | 109 | CORE_mutex_Status the_mutex_status |
---|
[9728ef3] | 110 | ) |
---|
| 111 | { |
---|
| 112 | /* |
---|
| 113 | * Internal consistency check for bad status from SuperCore |
---|
| 114 | */ |
---|
| 115 | #if defined(RTEMS_DEBUG) |
---|
| 116 | if ( the_mutex_status > CORE_MUTEX_STATUS_LAST ) |
---|
| 117 | return EINVAL; |
---|
| 118 | #endif |
---|
| 119 | return _POSIX_Mutex_Return_codes[the_mutex_status]; |
---|
| 120 | } |
---|
[f9d533a5] | 121 | |
---|
[4600bd7c] | 122 | /** |
---|
| 123 | * @brief POSIX Mutex Get (Thread Dispatch Disable) |
---|
[f9d533a5] | 124 | * |
---|
| 125 | * A support routine which translates the mutex id into a local pointer. |
---|
| 126 | * As a side-effect, it may create the mutex. |
---|
| 127 | * |
---|
[4600bd7c] | 128 | * @note This version of the method uses a dispatching critical section. |
---|
[f9d533a5] | 129 | */ |
---|
| 130 | POSIX_Mutex_Control *_POSIX_Mutex_Get ( |
---|
| 131 | pthread_mutex_t *mutex, |
---|
| 132 | Objects_Locations *location |
---|
| 133 | ); |
---|
| 134 | |
---|
[4600bd7c] | 135 | /** |
---|
| 136 | * @brief POSIX Mutex Get (Interrupt Disable) |
---|
[f9d533a5] | 137 | * |
---|
| 138 | * A support routine which translates the mutex id into a local pointer. |
---|
| 139 | * As a side-effect, it may create the mutex. |
---|
| 140 | * |
---|
[4600bd7c] | 141 | * @note: This version of the method uses an interrupt critical section. |
---|
[f9d533a5] | 142 | */ |
---|
[b8bdced1] | 143 | POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable( |
---|
| 144 | pthread_mutex_t *mutex, |
---|
| 145 | ISR_lock_Context *lock_context |
---|
[f9d533a5] | 146 | ); |
---|
| 147 | |
---|
| 148 | #ifdef __cplusplus |
---|
| 149 | } |
---|
| 150 | #endif |
---|
| 151 | |
---|
| 152 | #endif |
---|
| 153 | /* end of include file */ |
---|
| 154 | |
---|