1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Support Call to function Enables Locking of Mutex Object |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/posix/muteximpl.h> |
---|
22 | #include <rtems/posix/posixapi.h> |
---|
23 | |
---|
24 | Status_Control _POSIX_Mutex_Seize_slow( |
---|
25 | POSIX_Mutex_Control *the_mutex, |
---|
26 | const Thread_queue_Operations *operations, |
---|
27 | Thread_Control *executing, |
---|
28 | const struct timespec *abstime, |
---|
29 | Thread_queue_Context *queue_context |
---|
30 | ) |
---|
31 | { |
---|
32 | if ( (uintptr_t) abstime != POSIX_MUTEX_ABSTIME_TRY_LOCK ) { |
---|
33 | _Thread_queue_Context_set_thread_state( |
---|
34 | queue_context, |
---|
35 | STATES_WAITING_FOR_MUTEX |
---|
36 | ); |
---|
37 | _Thread_queue_Context_set_deadlock_callout( |
---|
38 | queue_context, |
---|
39 | _Thread_queue_Deadlock_status |
---|
40 | ); |
---|
41 | _Thread_queue_Enqueue( |
---|
42 | &the_mutex->Recursive.Mutex.Queue.Queue, |
---|
43 | operations, |
---|
44 | executing, |
---|
45 | queue_context |
---|
46 | ); |
---|
47 | return _Thread_Wait_get_status( executing ); |
---|
48 | } else { |
---|
49 | _POSIX_Mutex_Release( the_mutex, queue_context ); |
---|
50 | return STATUS_UNAVAILABLE; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | int _POSIX_Mutex_Lock_support( |
---|
55 | pthread_mutex_t *mutex, |
---|
56 | const struct timespec *abstime, |
---|
57 | Thread_queue_Enqueue_callout enqueue_callout |
---|
58 | ) |
---|
59 | { |
---|
60 | POSIX_Mutex_Control *the_mutex; |
---|
61 | unsigned long flags; |
---|
62 | Thread_queue_Context queue_context; |
---|
63 | Thread_Control *executing; |
---|
64 | Status_Control status; |
---|
65 | |
---|
66 | the_mutex = _POSIX_Mutex_Get( mutex ); |
---|
67 | POSIX_MUTEX_VALIDATE_OBJECT( the_mutex, flags ); |
---|
68 | |
---|
69 | executing = _POSIX_Mutex_Acquire( the_mutex, &queue_context ); |
---|
70 | _Thread_queue_Context_set_enqueue_callout( &queue_context, enqueue_callout); |
---|
71 | _Thread_queue_Context_set_timeout_argument( &queue_context, abstime ); |
---|
72 | |
---|
73 | switch ( _POSIX_Mutex_Get_protocol( flags ) ) { |
---|
74 | case POSIX_MUTEX_PRIORITY_CEILING: |
---|
75 | status = _POSIX_Mutex_Ceiling_seize( |
---|
76 | the_mutex, |
---|
77 | flags, |
---|
78 | executing, |
---|
79 | abstime, |
---|
80 | &queue_context |
---|
81 | ); |
---|
82 | break; |
---|
83 | case POSIX_MUTEX_NO_PROTOCOL: |
---|
84 | status = _POSIX_Mutex_Seize( |
---|
85 | the_mutex, |
---|
86 | flags, |
---|
87 | POSIX_MUTEX_NO_PROTOCOL_TQ_OPERATIONS, |
---|
88 | executing, |
---|
89 | abstime, |
---|
90 | &queue_context |
---|
91 | ); |
---|
92 | break; |
---|
93 | default: |
---|
94 | _Assert( |
---|
95 | _POSIX_Mutex_Get_protocol( flags ) == POSIX_MUTEX_PRIORITY_INHERIT |
---|
96 | ); |
---|
97 | status = _POSIX_Mutex_Seize( |
---|
98 | the_mutex, |
---|
99 | flags, |
---|
100 | POSIX_MUTEX_PRIORITY_INHERIT_TQ_OPERATIONS, |
---|
101 | executing, |
---|
102 | abstime, |
---|
103 | &queue_context |
---|
104 | ); |
---|
105 | break; |
---|
106 | } |
---|
107 | |
---|
108 | return _POSIX_Get_error( status ); |
---|
109 | } |
---|