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 | #define POSIX_MUTEX_NO_PROTOCOL_TQ_OPERATIONS &_Thread_queue_Operations_FIFO |
---|
32 | |
---|
33 | /** |
---|
34 | * @brief Supported POSIX mutex protocols. |
---|
35 | * |
---|
36 | * Must be in synchronization with POSIX_Mutex_Control::protocol. |
---|
37 | */ |
---|
38 | typedef enum { |
---|
39 | POSIX_MUTEX_NO_PROTOCOL, |
---|
40 | POSIX_MUTEX_PRIORITY_INHERIT, |
---|
41 | POSIX_MUTEX_PRIORITY_CEILING |
---|
42 | } POSIX_Mutex_Protocol; |
---|
43 | |
---|
44 | /** |
---|
45 | * The following defines the information control block used to manage |
---|
46 | * this class of objects. |
---|
47 | */ |
---|
48 | extern Objects_Information _POSIX_Mutex_Information; |
---|
49 | |
---|
50 | /** |
---|
51 | * The default mutex attributes structure. |
---|
52 | */ |
---|
53 | extern pthread_mutexattr_t _POSIX_Mutex_Default_attributes; |
---|
54 | |
---|
55 | RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Acquire_critical( |
---|
56 | POSIX_Mutex_Control *the_mutex, |
---|
57 | Thread_queue_Context *queue_context |
---|
58 | ) |
---|
59 | { |
---|
60 | _CORE_mutex_Acquire_critical( |
---|
61 | &the_mutex->Mutex.Recursive.Mutex, |
---|
62 | queue_context |
---|
63 | ); |
---|
64 | } |
---|
65 | |
---|
66 | RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Release( |
---|
67 | POSIX_Mutex_Control *the_mutex, |
---|
68 | Thread_queue_Context *queue_context |
---|
69 | ) |
---|
70 | { |
---|
71 | _CORE_mutex_Release( |
---|
72 | &the_mutex->Mutex.Recursive.Mutex, |
---|
73 | queue_context |
---|
74 | ); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * @brief POSIX Mutex Allocate |
---|
79 | * |
---|
80 | * This function allocates a mutexes control block from |
---|
81 | * the inactive chain of free mutexes control blocks. |
---|
82 | */ |
---|
83 | RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void ) |
---|
84 | { |
---|
85 | return (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information ); |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * @brief POSIX Mutex Free |
---|
90 | * |
---|
91 | * This routine frees a mutexes control block to the |
---|
92 | * inactive chain of free mutexes control blocks. |
---|
93 | */ |
---|
94 | RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Free( |
---|
95 | POSIX_Mutex_Control *the_mutex |
---|
96 | ) |
---|
97 | { |
---|
98 | _Objects_Free( &_POSIX_Mutex_Information, &the_mutex->Object ); |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | /** |
---|
103 | * @brief POSIX Mutex Lock Support Method |
---|
104 | * |
---|
105 | * A support routine which implements guts of the blocking, non-blocking, and |
---|
106 | * timed wait version of mutex lock. |
---|
107 | */ |
---|
108 | int _POSIX_Mutex_Lock_support( |
---|
109 | pthread_mutex_t *mutex, |
---|
110 | bool blocking, |
---|
111 | Watchdog_Interval timeout |
---|
112 | ); |
---|
113 | |
---|
114 | /** |
---|
115 | * @brief POSIX Mutex Get (Interrupt Disable) |
---|
116 | * |
---|
117 | * A support routine which translates the mutex id into a local pointer. |
---|
118 | * As a side-effect, it may create the mutex. |
---|
119 | * |
---|
120 | * @note: This version of the method uses an interrupt critical section. |
---|
121 | */ |
---|
122 | POSIX_Mutex_Control *_POSIX_Mutex_Get( |
---|
123 | pthread_mutex_t *mutex, |
---|
124 | Thread_queue_Context *queue_context |
---|
125 | ); |
---|
126 | |
---|
127 | RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Get_no_protection( |
---|
128 | const pthread_mutex_t *mutex |
---|
129 | ) |
---|
130 | { |
---|
131 | return (POSIX_Mutex_Control *) _Objects_Get_no_protection( |
---|
132 | (Objects_Id) *mutex, |
---|
133 | &_POSIX_Mutex_Information |
---|
134 | ); |
---|
135 | } |
---|
136 | |
---|
137 | #ifdef __cplusplus |
---|
138 | } |
---|
139 | #endif |
---|
140 | |
---|
141 | #endif |
---|
142 | /* end of include file */ |
---|
143 | |
---|