1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Surrender the Mutex |
---|
5 | * @ingroup ScoreMutex |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2006. |
---|
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/score/coremuteximpl.h> |
---|
22 | |
---|
23 | Status_Control _CORE_mutex_Surrender_slow( |
---|
24 | CORE_mutex_Control *the_mutex, |
---|
25 | Thread_Control *executing, |
---|
26 | Thread_queue_Heads *heads, |
---|
27 | bool keep_priority, |
---|
28 | Thread_queue_Context *queue_context |
---|
29 | ) |
---|
30 | { |
---|
31 | if ( heads != NULL ) { |
---|
32 | const Thread_queue_Operations *operations; |
---|
33 | Thread_Control *new_owner; |
---|
34 | bool unblock; |
---|
35 | |
---|
36 | operations = CORE_MUTEX_TQ_OPERATIONS; |
---|
37 | new_owner = ( *operations->first )( heads ); |
---|
38 | |
---|
39 | _CORE_mutex_Set_owner( the_mutex, new_owner ); |
---|
40 | |
---|
41 | unblock = _Thread_queue_Extract_locked( |
---|
42 | &the_mutex->Wait_queue.Queue, |
---|
43 | operations, |
---|
44 | new_owner, |
---|
45 | queue_context |
---|
46 | ); |
---|
47 | |
---|
48 | #if defined(RTEMS_MULTIPROCESSING) |
---|
49 | if ( _Objects_Is_local_id( new_owner->Object.id ) ) |
---|
50 | #endif |
---|
51 | { |
---|
52 | ++new_owner->resource_count; |
---|
53 | _Thread_queue_Boost_priority( &the_mutex->Wait_queue.Queue, new_owner ); |
---|
54 | } |
---|
55 | |
---|
56 | _Thread_queue_Unblock_critical( |
---|
57 | unblock, |
---|
58 | &the_mutex->Wait_queue.Queue, |
---|
59 | new_owner, |
---|
60 | &queue_context->Lock_context |
---|
61 | ); |
---|
62 | } else { |
---|
63 | _CORE_mutex_Release( the_mutex, queue_context ); |
---|
64 | } |
---|
65 | |
---|
66 | if ( !keep_priority ) { |
---|
67 | Per_CPU_Control *cpu_self; |
---|
68 | |
---|
69 | cpu_self = _Thread_Dispatch_disable(); |
---|
70 | _Thread_Restore_priority( executing ); |
---|
71 | _Thread_Dispatch_enable( cpu_self ); |
---|
72 | } |
---|
73 | |
---|
74 | return STATUS_SUCCESSFUL; |
---|
75 | } |
---|