source: rtems/cpukit/rtems/src/ratemontimeout.c @ 1240aade

Last change on this file since 1240aade was 1240aade, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 24, 2017 at 1:37:42 PM

rtems: Fix _Rate_monotonic_Renew_deadline()

Make _Rate_monotonic_Renew_deadline() static and use proper locking in SMP
configurations.

Update #2795.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Rate Monotonic Timeout
5 *  @ingroup ClassicRateMon
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2009.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  COPYRIGHT (c) 2016 Kuan-Hsun Chen.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <rtems/rtems/ratemonimpl.h>
24
25static void _Rate_monotonic_Renew_deadline(
26  Rate_monotonic_Control *the_period,
27  Thread_Control         *owner,
28  ISR_lock_Context       *lock_context
29)
30{
31  uint64_t deadline;
32
33  ++the_period->postponed_jobs;
34  the_period->state = RATE_MONOTONIC_EXPIRED;
35
36  deadline = _Watchdog_Per_CPU_insert_relative(
37    &the_period->Timer,
38    _Per_CPU_Get(),
39    the_period->next_length
40  );
41  the_period->latest_deadline = deadline;
42
43  _Rate_monotonic_Release( the_period, lock_context );
44}
45
46void _Rate_monotonic_Timeout( Watchdog_Control *the_watchdog )
47{
48  Rate_monotonic_Control *the_period;
49  Thread_Control         *owner;
50  ISR_lock_Context        lock_context;
51  Thread_Wait_flags       wait_flags;
52
53  the_period = RTEMS_CONTAINER_OF( the_watchdog, Rate_monotonic_Control, Timer );
54  owner = the_period->owner;
55
56  _ISR_lock_ISR_disable( &lock_context );
57  _Rate_monotonic_Acquire_critical( the_period, &lock_context );
58  wait_flags = _Thread_Wait_flags_get( owner );
59
60  if (
61    ( wait_flags & THREAD_WAIT_CLASS_PERIOD ) != 0
62      && owner->Wait.return_argument == the_period
63  ) {
64    bool unblock;
65    bool success;
66
67    owner->Wait.return_argument = NULL;
68
69    success = _Thread_Wait_flags_try_change_release(
70      owner,
71      RATE_MONOTONIC_INTEND_TO_BLOCK,
72      RATE_MONOTONIC_READY_AGAIN
73    );
74    if ( success ) {
75      unblock = false;
76    } else {
77      _Assert( _Thread_Wait_flags_get( owner ) == RATE_MONOTONIC_BLOCKED );
78      _Thread_Wait_flags_set( owner, RATE_MONOTONIC_READY_AGAIN );
79      unblock = true;
80    }
81
82    _Rate_monotonic_Restart( the_period, owner, &lock_context );
83
84    if ( unblock ) {
85      _Thread_Unblock( owner );
86    }
87  } else {
88    _Rate_monotonic_Renew_deadline( the_period, owner, &lock_context );
89  }
90}
Note: See TracBrowser for help on using the repository browser.