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

Last change on this file was c4fb617, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 22:28:43

cpukit/rtems/src/[a-r]*.c: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSImplClassicEvent
7 *
8 * @brief This source file contains the implementation of
9 *   _Event_Seize() and the Event Manager multiprocessing (MP) support system
10 *   initialization.
11 */
12
13/*
14 *  COPYRIGHT (c) 1989-2008.
15 *  On-Line Applications Research Corporation (OAR).
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 *    notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 *    notice, this list of conditions and the following disclaimer in the
24 *    documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifdef HAVE_CONFIG_H
40#include "config.h"
41#endif
42
43#include <rtems/sysinit.h>
44#include <rtems/rtems/eventimpl.h>
45#include <rtems/rtems/optionsimpl.h>
46#include <rtems/rtems/statusimpl.h>
47#include <rtems/score/threadimpl.h>
48#include <rtems/score/watchdogimpl.h>
49
50rtems_status_code _Event_Seize(
51  rtems_event_set    event_in,
52  rtems_option       option_set,
53  rtems_interval     ticks,
54  rtems_event_set   *event_out,
55  Thread_Control    *executing,
56  Event_Control     *event,
57  Thread_Wait_flags  wait_class,
58  States_Control     block_state,
59  ISR_lock_Context  *lock_context
60)
61{
62  rtems_event_set    seized_events;
63  rtems_event_set    pending_events;
64  bool               success;
65  Thread_Wait_flags  intend_to_block;
66  Per_CPU_Control   *cpu_self;
67
68  pending_events = event->pending_events;
69  seized_events  = _Event_sets_Get( pending_events, event_in );
70
71  if ( !_Event_sets_Is_empty( seized_events ) &&
72       (seized_events == event_in || _Options_Is_any( option_set )) ) {
73    event->pending_events =
74      _Event_sets_Clear( pending_events, seized_events );
75    _Thread_Wait_release_default( executing, lock_context );
76    *event_out = seized_events;
77    return RTEMS_SUCCESSFUL;
78  }
79
80  if ( _Options_Is_no_wait( option_set ) ) {
81    _Thread_Wait_release_default( executing, lock_context );
82    *event_out = seized_events;
83    return RTEMS_UNSATISFIED;
84  }
85
86  intend_to_block = wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK;
87
88  /*
89   *  Note what we are waiting for BEFORE we enter the critical section.
90   *  The interrupt critical section management code needs this to be
91   *  set properly when we are marked as in the event critical section.
92   *
93   *  NOTE: Since interrupts are disabled, this isn't that much of an
94   *        issue but better safe than sorry.
95   */
96  executing->Wait.return_code     = STATUS_SUCCESSFUL;
97  executing->Wait.option          = option_set;
98  executing->Wait.count           = event_in;
99  executing->Wait.return_argument = event_out;
100  _Thread_Wait_flags_set( executing, intend_to_block );
101
102  cpu_self = _Thread_Dispatch_disable_critical( lock_context );
103  _Thread_Wait_release_default( executing, lock_context );
104
105  if ( ticks ) {
106    _Thread_Add_timeout_ticks( executing, cpu_self, ticks );
107  }
108
109  _Thread_Set_state( executing, block_state );
110
111  success = _Thread_Wait_flags_try_change_acquire(
112    executing,
113    intend_to_block,
114    wait_class | THREAD_WAIT_STATE_BLOCKED
115  );
116  if ( !success ) {
117    _Thread_Timer_remove( executing );
118    _Thread_Unblock( executing );
119  }
120
121  _Thread_Dispatch_direct( cpu_self );
122  return _Status_Get_after_wait( executing );
123}
124
125#if defined(RTEMS_MULTIPROCESSING)
126static void _Event_MP_Initialize( void )
127{
128  _MPCI_Register_packet_processor( MP_PACKET_EVENT, _Event_MP_Process_packet );
129}
130
131RTEMS_SYSINIT_ITEM(
132  _Event_MP_Initialize,
133  RTEMS_SYSINIT_CLASSIC_EVENT_MP,
134  RTEMS_SYSINIT_ORDER_MIDDLE
135);
136#endif
Note: See TracBrowser for help on using the repository browser.