source: rtems/cpukit/rtems/src/eventseize.c @ 66cb142

Last change on this file since 66cb142 was ed24ed4e, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 8, 2018 at 9:47:16 AM

Use _Thread_Dispatch_direct()

Use _Thread_Dispatch_direct() for operations that block the executing
thread. This ensures that we get a fatal error
(INTERNAL_ERROR_BAD_THREAD_DISPATCH_DISABLE_LEVEL) if we try to block in
an invalid context, e.g. during system start or an interrupt handler.

  • Property mode set to 100644
File size: 3.2 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/rtems/statusimpl.h>
25#include <rtems/score/threadimpl.h>
26#include <rtems/score/watchdogimpl.h>
27
28rtems_status_code _Event_Seize(
29  rtems_event_set    event_in,
30  rtems_option       option_set,
31  rtems_interval     ticks,
32  rtems_event_set   *event_out,
33  Thread_Control    *executing,
34  Event_Control     *event,
35  Thread_Wait_flags  wait_class,
36  States_Control     block_state,
37  ISR_lock_Context  *lock_context
38)
39{
40  rtems_event_set    seized_events;
41  rtems_event_set    pending_events;
42  bool               success;
43  Thread_Wait_flags  intend_to_block;
44  Per_CPU_Control   *cpu_self;
45
46  pending_events = event->pending_events;
47  seized_events  = _Event_sets_Get( pending_events, event_in );
48
49  if ( !_Event_sets_Is_empty( seized_events ) &&
50       (seized_events == event_in || _Options_Is_any( option_set )) ) {
51    event->pending_events =
52      _Event_sets_Clear( pending_events, seized_events );
53    _Thread_Wait_release_default( executing, lock_context );
54    *event_out = seized_events;
55    return RTEMS_SUCCESSFUL;
56  }
57
58  if ( _Options_Is_no_wait( option_set ) ) {
59    _Thread_Wait_release_default( executing, lock_context );
60    *event_out = seized_events;
61    return RTEMS_UNSATISFIED;
62  }
63
64  intend_to_block = wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK;
65
66  /*
67   *  Note what we are waiting for BEFORE we enter the critical section.
68   *  The interrupt critical section management code needs this to be
69   *  set properly when we are marked as in the event critical section.
70   *
71   *  NOTE: Since interrupts are disabled, this isn't that much of an
72   *        issue but better safe than sorry.
73   */
74  executing->Wait.return_code     = STATUS_SUCCESSFUL;
75  executing->Wait.option          = option_set;
76  executing->Wait.count           = event_in;
77  executing->Wait.return_argument = event_out;
78  _Thread_Wait_flags_set( executing, intend_to_block );
79
80  cpu_self = _Thread_Dispatch_disable_critical( lock_context );
81  _Thread_Wait_release_default( executing, lock_context );
82
83  if ( ticks ) {
84    _Thread_Add_timeout_ticks( executing, cpu_self, ticks );
85  }
86
87  _Thread_Set_state( executing, block_state );
88
89  success = _Thread_Wait_flags_try_change_acquire(
90    executing,
91    intend_to_block,
92    wait_class | THREAD_WAIT_STATE_BLOCKED
93  );
94  if ( !success ) {
95    _Thread_Timer_remove( executing );
96    _Thread_Unblock( executing );
97  }
98
99  _Thread_Dispatch_direct( cpu_self );
100  return _Status_Get_after_wait( executing );
101}
102
103#if defined(RTEMS_MULTIPROCESSING)
104static void _Event_Manager_initialization( void )
105{
106  _MPCI_Register_packet_processor( MP_PACKET_EVENT, _Event_MP_Process_packet );
107}
108
109RTEMS_SYSINIT_ITEM(
110  _Event_Manager_initialization,
111  RTEMS_SYSINIT_CLASSIC_EVENT,
112  RTEMS_SYSINIT_ORDER_MIDDLE
113);
114#endif
Note: See TracBrowser for help on using the repository browser.