1 | /* |
---|
2 | * Event Manager |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2008. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #if HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems/rtems/event.h> |
---|
17 | |
---|
18 | /* |
---|
19 | * INTERRUPT LATENCY: |
---|
20 | * available |
---|
21 | * wait |
---|
22 | * check sync |
---|
23 | */ |
---|
24 | |
---|
25 | void _Event_Seize( |
---|
26 | rtems_event_set event_in, |
---|
27 | rtems_option option_set, |
---|
28 | rtems_interval ticks, |
---|
29 | rtems_event_set *event_out, |
---|
30 | Thread_Control *executing, |
---|
31 | Event_Control *event, |
---|
32 | Thread_blocking_operation_States *sync_state, |
---|
33 | States_Control wait_state |
---|
34 | ) |
---|
35 | { |
---|
36 | rtems_event_set seized_events; |
---|
37 | rtems_event_set pending_events; |
---|
38 | ISR_Level level; |
---|
39 | Thread_blocking_operation_States current_sync_state; |
---|
40 | |
---|
41 | executing->Wait.return_code = RTEMS_SUCCESSFUL; |
---|
42 | |
---|
43 | _ISR_Disable( level ); |
---|
44 | pending_events = event->pending_events; |
---|
45 | seized_events = _Event_sets_Get( pending_events, event_in ); |
---|
46 | |
---|
47 | if ( !_Event_sets_Is_empty( seized_events ) && |
---|
48 | (seized_events == event_in || _Options_Is_any( option_set )) ) { |
---|
49 | event->pending_events = |
---|
50 | _Event_sets_Clear( pending_events, seized_events ); |
---|
51 | _ISR_Enable( level ); |
---|
52 | *event_out = seized_events; |
---|
53 | return; |
---|
54 | } |
---|
55 | |
---|
56 | if ( _Options_Is_no_wait( option_set ) ) { |
---|
57 | _ISR_Enable( level ); |
---|
58 | executing->Wait.return_code = RTEMS_UNSATISFIED; |
---|
59 | *event_out = seized_events; |
---|
60 | return; |
---|
61 | } |
---|
62 | |
---|
63 | /* |
---|
64 | * Note what we are waiting for BEFORE we enter the critical section. |
---|
65 | * The interrupt critical section management code needs this to be |
---|
66 | * set properly when we are marked as in the event critical section. |
---|
67 | * |
---|
68 | * NOTE: Since interrupts are disabled, this isn't that much of an |
---|
69 | * issue but better safe than sorry. |
---|
70 | */ |
---|
71 | executing->Wait.option = option_set; |
---|
72 | executing->Wait.count = event_in; |
---|
73 | executing->Wait.return_argument = event_out; |
---|
74 | |
---|
75 | *sync_state = THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED; |
---|
76 | |
---|
77 | _ISR_Enable( level ); |
---|
78 | |
---|
79 | if ( ticks ) { |
---|
80 | _Watchdog_Initialize( |
---|
81 | &executing->Timer, |
---|
82 | _Event_Timeout, |
---|
83 | executing->Object.id, |
---|
84 | NULL |
---|
85 | ); |
---|
86 | _Watchdog_Insert_ticks( &executing->Timer, ticks ); |
---|
87 | } |
---|
88 | |
---|
89 | _Thread_Set_state( executing, wait_state ); |
---|
90 | |
---|
91 | _ISR_Disable( level ); |
---|
92 | |
---|
93 | current_sync_state = *sync_state; |
---|
94 | *sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED; |
---|
95 | if ( current_sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) { |
---|
96 | _ISR_Enable( level ); |
---|
97 | return; |
---|
98 | } |
---|
99 | |
---|
100 | /* |
---|
101 | * An interrupt completed the thread's blocking request. |
---|
102 | * The blocking thread was satisfied by an ISR or timed out. |
---|
103 | * |
---|
104 | * WARNING! Entering with interrupts disabled and returning with interrupts |
---|
105 | * enabled! |
---|
106 | */ |
---|
107 | _Thread_blocking_operation_Cancel( current_sync_state, executing, level ); |
---|
108 | } |
---|