source: rtems/cpukit/rtems/src/ratemontimeout.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: 3.5 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSImplClassicRateMonotonic
7 *
8 * @brief This source file contains the implementation of
9 *   _Rate_monotonic_Timeout().
10 */
11
12/*
13 *  COPYRIGHT (c) 1989-2009.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 *  COPYRIGHT (c) 2016-2017 Kuan-Hsun Chen.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 *    notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 *    notice, this list of conditions and the following disclaimer in the
25 *    documentation and/or other materials provided with the distribution.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#ifdef HAVE_CONFIG_H
41#include "config.h"
42#endif
43
44#include <rtems/rtems/ratemonimpl.h>
45
46static void _Rate_monotonic_Renew_deadline(
47  Rate_monotonic_Control *the_period,
48  ISR_lock_Context       *lock_context
49)
50{
51  uint64_t deadline;
52
53  /* stay at 0xffffffff if postponed_jobs is going to overflow */
54  if ( the_period->postponed_jobs != UINT32_MAX ) {
55    ++the_period->postponed_jobs;
56  }
57
58  the_period->state = RATE_MONOTONIC_EXPIRED;
59
60  deadline = _Watchdog_Per_CPU_insert_ticks(
61    &the_period->Timer,
62    _Per_CPU_Get(),
63    the_period->next_length
64  );
65  the_period->latest_deadline = deadline;
66
67  _Rate_monotonic_Release( the_period, lock_context );
68}
69
70void _Rate_monotonic_Timeout( Watchdog_Control *the_watchdog )
71{
72  Rate_monotonic_Control *the_period;
73  Thread_Control         *owner;
74  ISR_lock_Context        lock_context;
75  Thread_Wait_flags       wait_flags;
76
77  the_period = RTEMS_CONTAINER_OF( the_watchdog, Rate_monotonic_Control, Timer );
78  owner = the_period->owner;
79
80  _ISR_lock_ISR_disable( &lock_context );
81  _Rate_monotonic_Acquire_critical( the_period, &lock_context );
82  wait_flags = _Thread_Wait_flags_get( owner );
83
84  if (
85    ( wait_flags & THREAD_WAIT_CLASS_PERIOD ) != 0
86      && owner->Wait.return_argument == the_period
87  ) {
88    bool unblock;
89    bool success;
90
91    owner->Wait.return_argument = NULL;
92
93    success = _Thread_Wait_flags_try_change_release(
94      owner,
95      RATE_MONOTONIC_INTEND_TO_BLOCK,
96      THREAD_WAIT_STATE_READY
97    );
98    if ( success ) {
99      unblock = false;
100    } else {
101      _Assert( _Thread_Wait_flags_get( owner ) == RATE_MONOTONIC_BLOCKED );
102      _Thread_Wait_flags_set( owner, THREAD_WAIT_STATE_READY );
103      unblock = true;
104    }
105
106    _Rate_monotonic_Restart( the_period, owner, &lock_context );
107
108    if ( unblock ) {
109      _Thread_Unblock( owner );
110    }
111  } else {
112    _Rate_monotonic_Renew_deadline( the_period, &lock_context );
113  }
114}
Note: See TracBrowser for help on using the repository browser.