1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Seize Mutex with Blocking |
---|
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/system.h> |
---|
22 | #include <rtems/score/isr.h> |
---|
23 | #include <rtems/score/coremuteximpl.h> |
---|
24 | #include <rtems/score/statesimpl.h> |
---|
25 | #include <rtems/score/thread.h> |
---|
26 | |
---|
27 | void _CORE_mutex_Seize_interrupt_blocking( |
---|
28 | CORE_mutex_Control *the_mutex, |
---|
29 | Thread_Control *executing, |
---|
30 | Watchdog_Interval timeout, |
---|
31 | ISR_lock_Context *lock_context |
---|
32 | ) |
---|
33 | { |
---|
34 | #if !defined(RTEMS_SMP) |
---|
35 | /* |
---|
36 | * We must disable thread dispatching here since we enable the interrupts for |
---|
37 | * priority inheritance mutexes. |
---|
38 | */ |
---|
39 | _Thread_Dispatch_disable(); |
---|
40 | #endif |
---|
41 | |
---|
42 | if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) { |
---|
43 | Thread_Control *holder = the_mutex->holder; |
---|
44 | |
---|
45 | #if !defined(RTEMS_SMP) |
---|
46 | /* |
---|
47 | * To enable interrupts here works only since exactly one executing thread |
---|
48 | * exists and only threads are allowed to seize and surrender mutexes with |
---|
49 | * the priority inheritance protocol. On SMP configurations more than one |
---|
50 | * executing thread may exist, so here we must not release the lock, since |
---|
51 | * otherwise the current holder may be no longer the holder of the mutex |
---|
52 | * once we released the lock. |
---|
53 | */ |
---|
54 | _Thread_queue_Release( &the_mutex->Wait_queue, lock_context ); |
---|
55 | #endif |
---|
56 | |
---|
57 | _Thread_Inherit_priority( holder, executing ); |
---|
58 | |
---|
59 | #if !defined(RTEMS_SMP) |
---|
60 | _Thread_queue_Acquire( &the_mutex->Wait_queue, lock_context ); |
---|
61 | #endif |
---|
62 | } |
---|
63 | |
---|
64 | _Thread_queue_Enqueue_critical( |
---|
65 | &the_mutex->Wait_queue.Queue, |
---|
66 | the_mutex->operations, |
---|
67 | executing, |
---|
68 | STATES_WAITING_FOR_MUTEX, |
---|
69 | timeout, |
---|
70 | CORE_MUTEX_TIMEOUT, |
---|
71 | lock_context |
---|
72 | ); |
---|
73 | |
---|
74 | #if !defined(RTEMS_SMP) |
---|
75 | _Thread_Dispatch_enable( _Per_CPU_Get() ); |
---|
76 | #endif |
---|
77 | } |
---|
78 | |
---|