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 | |
---|
10 | /* COPYRIGHT (c) 1989-2013. |
---|
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 |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef _RTEMS_POSIX_MUTEXIMPL_H |
---|
19 | #define _RTEMS_POSIX_MUTEXIMPL_H |
---|
20 | |
---|
21 | #include <rtems/posix/mutex.h> |
---|
22 | #include <rtems/score/coremuteximpl.h> |
---|
23 | |
---|
24 | #include <errno.h> |
---|
25 | #include <pthread.h> |
---|
26 | |
---|
27 | #ifdef __cplusplus |
---|
28 | extern "C" { |
---|
29 | #endif |
---|
30 | |
---|
31 | /** |
---|
32 | * The following defines the information control block used to manage |
---|
33 | * this class of objects. |
---|
34 | */ |
---|
35 | extern Objects_Information _POSIX_Mutex_Information; |
---|
36 | |
---|
37 | /** |
---|
38 | * The default mutex attributes structure. |
---|
39 | */ |
---|
40 | extern pthread_mutexattr_t _POSIX_Mutex_Default_attributes; |
---|
41 | |
---|
42 | /** |
---|
43 | * This array contains a mapping from Score Mutex return codes to |
---|
44 | * POSIX return codes. |
---|
45 | */ |
---|
46 | extern const int _POSIX_Mutex_Return_codes[CORE_MUTEX_STATUS_LAST + 1]; |
---|
47 | |
---|
48 | /** |
---|
49 | * @brief POSIX Mutex Allocate |
---|
50 | * |
---|
51 | * This function allocates a mutexes control block from |
---|
52 | * the inactive chain of free mutexes control blocks. |
---|
53 | */ |
---|
54 | RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void ) |
---|
55 | { |
---|
56 | return (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information ); |
---|
57 | } |
---|
58 | |
---|
59 | /** |
---|
60 | * @brief POSIX Mutex Free |
---|
61 | * |
---|
62 | * This routine frees a mutexes control block to the |
---|
63 | * inactive chain of free mutexes control blocks. |
---|
64 | */ |
---|
65 | RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Free( |
---|
66 | POSIX_Mutex_Control *the_mutex |
---|
67 | ) |
---|
68 | { |
---|
69 | _CORE_mutex_Destroy( &the_mutex->Mutex ); |
---|
70 | _Objects_Free( &_POSIX_Mutex_Information, &the_mutex->Object ); |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | /** |
---|
75 | * @brief POSIX Mutex Lock Support Method |
---|
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 | /** |
---|
87 | * @brief Convert Score mutex status codes into POSIX status values |
---|
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 |
---|
96 | * complete immediately because the resource was unavailable. |
---|
97 | * @retval EDEADLK Mutex status code indicates that an attempt was made to |
---|
98 | * relock a mutex for which nesting is not configured. |
---|
99 | * @retval EPERM Mutex status code indicates that an attempt was made to |
---|
100 | * release a mutex by a thread other than the thread which locked it. |
---|
101 | * @retval EINVAL Mutex status code indicates that the thread was blocked |
---|
102 | * waiting for an operation to complete and the mutex was deleted. |
---|
103 | * @retval ETIMEDOUT Mutex status code indicates that the calling task was |
---|
104 | * willing to block but the operation was unable to complete |
---|
105 | * within the time allotted because the resource never became |
---|
106 | * available. |
---|
107 | */ |
---|
108 | RTEMS_INLINE_ROUTINE int _POSIX_Mutex_Translate_core_mutex_return_code( |
---|
109 | CORE_mutex_Status the_mutex_status |
---|
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 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * @brief POSIX Mutex Get (Thread Dispatch Disable) |
---|
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 | * |
---|
128 | * @note This version of the method uses a dispatching critical section. |
---|
129 | */ |
---|
130 | POSIX_Mutex_Control *_POSIX_Mutex_Get ( |
---|
131 | pthread_mutex_t *mutex, |
---|
132 | Objects_Locations *location |
---|
133 | ); |
---|
134 | |
---|
135 | /** |
---|
136 | * @brief POSIX Mutex Get (Interrupt Disable) |
---|
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 | * |
---|
141 | * @note: This version of the method uses an interrupt critical section. |
---|
142 | */ |
---|
143 | POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable( |
---|
144 | pthread_mutex_t *mutex, |
---|
145 | ISR_lock_Context *lock_context |
---|
146 | ); |
---|
147 | |
---|
148 | #ifdef __cplusplus |
---|
149 | } |
---|
150 | #endif |
---|
151 | |
---|
152 | #endif |
---|
153 | /* end of include file */ |
---|
154 | |
---|