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

5
Last change on this file since 3692095 was dce48791, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/16 at 11:37:59

score: Add Status_Control for all APIs

Unify the status codes of the Classic and POSIX API to use the new enum
Status_Control. This eliminates the Thread_Control::Wait::timeout_code
field and the timeout parameter of _Thread_queue_Enqueue_critical() and
_MPCI_Send_request_packet(). It gets rid of the status code translation
tables and instead uses simple bit operations to get the status for a
particular API. This enables translation of status code constants at
compile time. Add _Thread_Wait_get_status() to avoid direct access of
thread internal data structures.

  • 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/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_Lock_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_Lock_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_Lock_release_default( executing, lock_context );
82
83  if ( ticks ) {
84    _Thread_Timer_insert_relative(
85      executing,
86      cpu_self,
87      _Thread_Timeout,
88      ticks
89    );
90  }
91
92  _Thread_Set_state( executing, block_state );
93
94  /*
95   * See _Event_Surrender() and _Thread_Timeout(), corresponding atomic
96   * variable is Thread_Control::Wait::flags.
97   */
98  _Atomic_Fence( ATOMIC_ORDER_ACQUIRE );
99
100  success = _Thread_Wait_flags_try_change(
101    executing,
102    intend_to_block,
103    wait_class | THREAD_WAIT_STATE_BLOCKED
104  );
105  if ( !success ) {
106    _Thread_Timer_remove( executing );
107    _Thread_Unblock( executing );
108  }
109
110  _Thread_Dispatch_enable( cpu_self );
111  return _Status_Get_after_wait( executing );
112}
113
114#if defined(RTEMS_MULTIPROCESSING)
115static void _Event_Manager_initialization( void )
116{
117  _MPCI_Register_packet_processor( MP_PACKET_EVENT, _Event_MP_Process_packet );
118}
119
120RTEMS_SYSINIT_ITEM(
121  _Event_Manager_initialization,
122  RTEMS_SYSINIT_CLASSIC_EVENT,
123  RTEMS_SYSINIT_ORDER_MIDDLE
124);
125#endif
Note: See TracBrowser for help on using the repository browser.