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

5
Last change on this file since bf2a53d2 was bf2a53d2, checked in by Sebastian Huber <sebastian.huber@…>, on 10/14/17 at 13:14:53

score: Rename watchdog variants

Rename PER_CPU_WATCHDOG_RELATIVE in PER_CPU_WATCHDOG_MONOTONIC to
highlight the corresponding POSIX CLOCK_MONOTONIC.

Rename PER_CPU_WATCHDOG_ABSOLUTE in PER_CPU_WATCHDOG_REALTIME to
highlight the corresponding POSIX CLOCK_REALTIME.

Update #3117.
Update #3182.

  • 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_Timer_insert_monotonic(
85      executing,
86      cpu_self,
87      _Thread_Timeout,
88      ticks
89    );
90  }
91
92  _Thread_Set_state( executing, block_state );
93
94  success = _Thread_Wait_flags_try_change_acquire(
95    executing,
96    intend_to_block,
97    wait_class | THREAD_WAIT_STATE_BLOCKED
98  );
99  if ( !success ) {
100    _Thread_Timer_remove( executing );
101    _Thread_Unblock( executing );
102  }
103
104  _Thread_Dispatch_enable( cpu_self );
105  return _Status_Get_after_wait( executing );
106}
107
108#if defined(RTEMS_MULTIPROCESSING)
109static void _Event_Manager_initialization( void )
110{
111  _MPCI_Register_packet_processor( MP_PACKET_EVENT, _Event_MP_Process_packet );
112}
113
114RTEMS_SYSINIT_ITEM(
115  _Event_Manager_initialization,
116  RTEMS_SYSINIT_CLASSIC_EVENT,
117  RTEMS_SYSINIT_ORDER_MIDDLE
118);
119#endif
Note: See TracBrowser for help on using the repository browser.