source: rtems/cpukit/rtems/src/eventseize.c @ ef6f8a83

5
Last change on this file since ef6f8a83 was 03b900d, checked in by Sebastian Huber <sebastian.huber@…>, on 02/18/16 at 07:36:26

score: Replace watchdog handler implementation

Use a red-black tree instead of delta chains.

Close #2344.
Update #2554.
Update #2555.
Close #2606.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Event Manager Initialization
5 * @ingroup ClassicEvent Events
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
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/sysinit.h>
22#include <rtems/rtems/eventimpl.h>
23#include <rtems/rtems/optionsimpl.h>
24#include <rtems/score/threadimpl.h>
25#include <rtems/score/watchdogimpl.h>
26
27/*
28 *  INTERRUPT LATENCY:
29 *    available
30 *    wait
31 *    check sync
32 */
33
34void _Event_Seize(
35  rtems_event_set    event_in,
36  rtems_option       option_set,
37  rtems_interval     ticks,
38  rtems_event_set   *event_out,
39  Thread_Control    *executing,
40  Event_Control     *event,
41  Thread_Wait_flags  wait_class,
42  States_Control     block_state,
43  ISR_lock_Context  *lock_context
44)
45{
46  rtems_event_set    seized_events;
47  rtems_event_set    pending_events;
48  bool               success;
49  Thread_Wait_flags  intend_to_block;
50  Per_CPU_Control   *cpu_self;
51
52  executing->Wait.return_code = RTEMS_SUCCESSFUL;
53
54  pending_events = event->pending_events;
55  seized_events  = _Event_sets_Get( pending_events, event_in );
56
57  if ( !_Event_sets_Is_empty( seized_events ) &&
58       (seized_events == event_in || _Options_Is_any( option_set )) ) {
59    event->pending_events =
60      _Event_sets_Clear( pending_events, seized_events );
61    _Thread_Lock_release_default( executing, lock_context );
62    *event_out = seized_events;
63    return;
64  }
65
66  if ( _Options_Is_no_wait( option_set ) ) {
67    _Thread_Lock_release_default( executing, lock_context );
68    executing->Wait.return_code = RTEMS_UNSATISFIED;
69    *event_out = seized_events;
70    return;
71  }
72
73  intend_to_block = wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK;
74
75  /*
76   *  Note what we are waiting for BEFORE we enter the critical section.
77   *  The interrupt critical section management code needs this to be
78   *  set properly when we are marked as in the event critical section.
79   *
80   *  NOTE: Since interrupts are disabled, this isn't that much of an
81   *        issue but better safe than sorry.
82   */
83  executing->Wait.option          = option_set;
84  executing->Wait.count           = event_in;
85  executing->Wait.return_argument = event_out;
86  _Thread_Wait_flags_set( executing, intend_to_block );
87
88  cpu_self = _Thread_Dispatch_disable_critical( lock_context );
89  _Thread_Lock_release_default( executing, lock_context );
90
91  if ( ticks ) {
92    _Thread_Wait_set_timeout_code( executing, RTEMS_TIMEOUT );
93    _Thread_Timer_insert_relative(
94      executing,
95      cpu_self,
96      _Thread_Timeout,
97      ticks
98    );
99  }
100
101  _Thread_Set_state( executing, block_state );
102
103  /*
104   * See _Event_Surrender() and _Thread_Timeout(), corresponding atomic
105   * variable is Thread_Control::Wait::flags.
106   */
107  _Atomic_Fence( ATOMIC_ORDER_ACQUIRE );
108
109  success = _Thread_Wait_flags_try_change(
110    executing,
111    intend_to_block,
112    wait_class | THREAD_WAIT_STATE_BLOCKED
113  );
114  if ( !success ) {
115    _Thread_Timer_remove( executing );
116    _Thread_Unblock( executing );
117  }
118
119  _Thread_Dispatch_enable( cpu_self );
120}
121
122#if defined(RTEMS_MULTIPROCESSING)
123static void _Event_Manager_initialization( void )
124{
125  _MPCI_Register_packet_processor( MP_PACKET_EVENT, _Event_MP_Process_packet );
126}
127
128RTEMS_SYSINIT_ITEM(
129  _Event_Manager_initialization,
130  RTEMS_SYSINIT_CLASSIC_EVENT,
131  RTEMS_SYSINIT_ORDER_MIDDLE
132);
133#endif
Note: See TracBrowser for help on using the repository browser.