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

4.115
Last change on this file since d5423295 was d5423295, checked in by Sebastian Huber <sebastian.huber@…>, on 05/18/15 at 09:09:14

score: _Thread_Dispatch_disable_critical()

Thread dispatching is disabled in case interrupts are disabled. To get
an accurate thread dispatch disabled time it is important to use the
interrupt disabled instant in case a transition from an interrupt
disabled section to a thread dispatch level section happens.

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