RTEMS
eventseize.c
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 1989-2008.
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 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include <rtems/sysinit.h>
23 #include <rtems/rtems/eventimpl.h>
25 #include <rtems/rtems/statusimpl.h>
26 #include <rtems/score/threadimpl.h>
28 
29 rtems_status_code _Event_Seize(
30  rtems_event_set event_in,
31  rtems_option option_set,
32  rtems_interval ticks,
33  rtems_event_set *event_out,
34  Thread_Control *executing,
35  Event_Control *event,
36  Thread_Wait_flags wait_class,
37  States_Control block_state,
38  ISR_lock_Context *lock_context
39 )
40 {
41  rtems_event_set seized_events;
42  rtems_event_set pending_events;
43  bool success;
44  Thread_Wait_flags intend_to_block;
45  Per_CPU_Control *cpu_self;
46 
47  pending_events = event->pending_events;
48  seized_events = _Event_sets_Get( pending_events, event_in );
49 
50  if ( !_Event_sets_Is_empty( seized_events ) &&
51  (seized_events == event_in || _Options_Is_any( option_set )) ) {
52  event->pending_events =
53  _Event_sets_Clear( pending_events, seized_events );
54  _Thread_Wait_release_default( executing, lock_context );
55  *event_out = seized_events;
56  return RTEMS_SUCCESSFUL;
57  }
58 
59  if ( _Options_Is_no_wait( option_set ) ) {
60  _Thread_Wait_release_default( executing, lock_context );
61  *event_out = seized_events;
62  return RTEMS_UNSATISFIED;
63  }
64 
65  intend_to_block = wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK;
66 
67  /*
68  * Note what we are waiting for BEFORE we enter the critical section.
69  * The interrupt critical section management code needs this to be
70  * set properly when we are marked as in the event critical section.
71  *
72  * NOTE: Since interrupts are disabled, this isn't that much of an
73  * issue but better safe than sorry.
74  */
75  executing->Wait.return_code = STATUS_SUCCESSFUL;
76  executing->Wait.option = option_set;
77  executing->Wait.count = event_in;
78  executing->Wait.return_argument = event_out;
79  _Thread_Wait_flags_set( executing, intend_to_block );
80 
81  cpu_self = _Thread_Dispatch_disable_critical( lock_context );
82  _Thread_Wait_release_default( executing, lock_context );
83 
84  if ( ticks ) {
85  _Thread_Add_timeout_ticks( executing, cpu_self, ticks );
86  }
87 
88  _Thread_Set_state( executing, block_state );
89 
91  executing,
92  intend_to_block,
93  wait_class | THREAD_WAIT_STATE_BLOCKED
94  );
95  if ( !success ) {
96  _Thread_Timer_remove( executing );
97  _Thread_Unblock( executing );
98  }
99 
100  _Thread_Dispatch_direct( cpu_self );
101  return _Status_Get_after_wait( executing );
102 }
103 
104 #if defined(RTEMS_MULTIPROCESSING)
105 static void _Event_MP_Initialize( void )
106 {
107  _MPCI_Register_packet_processor( MP_PACKET_EVENT, _Event_MP_Process_packet );
108 }
109 
110 RTEMS_SYSINIT_ITEM(
111  _Event_MP_Initialize,
112  RTEMS_SYSINIT_CLASSIC_EVENT_MP,
113  RTEMS_SYSINIT_ORDER_MIDDLE
114 );
115 #endif
static __inline__ void _Thread_Unblock(Thread_Control *the_thread)
Unblocks the thread.
Definition: threadimpl.h:965
static __inline__ void _Thread_Add_timeout_ticks(Thread_Control *the_thread, Per_CPU_Control *cpu, Watchdog_Interval ticks)
Adds timeout ticks to the thread.
Definition: threadimpl.h:2405
Thread_Wait_information Wait
Definition: thread.h:767
void _Thread_Dispatch_direct(Per_CPU_Control *cpu_self)
Directly do a thread dispatch.
Inlined Routines in the Watchdog Handler.
uint32_t rtems_option
This type is used to represent an option set.
Definition: options.h:121
This status code indicates that the request was not satisfied.
Definition: status.h:154
uint32_t return_code
Definition: thread.h:413
static __inline__ bool _Thread_Wait_flags_try_change_acquire(Thread_Control *the_thread, Thread_Wait_flags expected_flags, Thread_Wait_flags desired_flags)
Tries to change the thread wait flags with acquire semantics.
Definition: threadimpl.h:2300
RTEMS_INLINE_ROUTINE bool _Options_Is_any(rtems_option option_set)
Checks if the RTEMS_EVENT_ANY option is enabled in OPTION_SET.
Definition: optionsimpl.h:53
Classic Options Implementation.
RTEMS_INLINE_ROUTINE bool _Options_Is_no_wait(rtems_option option_set)
Checks if the RTEMS_NO_WAIT option is enabled in option_set.
Definition: optionsimpl.h:40
Classic Event Manager Implementation.
uint32_t States_Control
Definition: states.h:46
This status code indicates successful completion.
Definition: status.h:86
static __inline__ Per_CPU_Control * _Thread_Dispatch_disable_critical(const ISR_lock_Context *lock_context)
Disables thread dispatching inside a critical section (interrupts disabled).
static __inline__ void _Thread_Wait_flags_set(Thread_Control *the_thread, Thread_Wait_flags flags)
Sets the thread&#39;s wait flags.
Definition: threadimpl.h:2196
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
unsigned int Thread_Wait_flags
This type is able to contain several flags used to control the wait class and state of a thread...
Definition: thread.h:383
Per CPU Core Structure.
Definition: percpu.h:347
static __inline__ void _Thread_Timer_remove(Thread_Control *the_thread)
Remove the watchdog timer from the thread.
Definition: threadimpl.h:2456
Classic Status Implementation.
static __inline__ rtems_event_set _Event_sets_Get(rtems_event_set the_event_set, rtems_event_set the_event_condition)
Returns the events in event_condition that are set in event_set.
Definition: eventimpl.h:113
#define THREAD_WAIT_STATE_BLOCKED
Indicates that the thread completed the blocking operation.
Definition: threadimpl.h:2156
States_Control _Thread_Set_state(Thread_Control *the_thread, States_Control state)
Sets the specified thread state.
static __inline__ rtems_event_set _Event_sets_Clear(rtems_event_set the_event_set, rtems_event_set the_mask)
Removes the events in mask from the event_set passed in.
Definition: eventimpl.h:127
Watchdog_Interval rtems_interval
This type is used to represent clock tick intervals.
Definition: types.h:90
static __inline__ bool _Event_sets_Is_empty(rtems_event_set the_event_set)
Checks if on events are posted in the event_set.
Definition: eventimpl.h:86
Inlined Routines from the Thread Handler.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
uint32_t rtems_event_set
This integer type can hold an event set of up to 32 events represented as a bit field.
Definition: event.h:94
#define THREAD_WAIT_STATE_INTEND_TO_BLOCK
Indicates that the thread begins with the blocking operation.
Definition: threadimpl.h:2151
static __inline__ void _Thread_Wait_release_default(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Releases the thread wait default lock and restores the previous interrupt status. ...
Definition: threadimpl.h:1734