source: rtems/cpukit/rtems/src/ratemontimeout.c @ d78d529

5
Last change on this file since d78d529 was ee0e4135, checked in by Sebastian Huber <sebastian.huber@…>, on 08/04/16 at 08:20:29

score: Fix a release/cancel job race condition

Split up the potential thread priority change in the scheduler
release/cancel job operation. Protect the rate monotonic period state
with a dedicated SMP lock. This avoids a race condition during
_Rate_monotonic_Timeout() while _Rate_monotonic_Cancel() is called on
another processor.

  • Property mode set to 100644
File size: 1.7 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 *  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/rtems/ratemonimpl.h>
22
23void _Rate_monotonic_Timeout( Watchdog_Control *the_watchdog )
24{
25  Rate_monotonic_Control *the_period;
26  Thread_Control         *owner;
27  ISR_lock_Context        lock_context;
28  Thread_Wait_flags       wait_flags;
29
30  the_period = RTEMS_CONTAINER_OF( the_watchdog, Rate_monotonic_Control, Timer );
31  owner = the_period->owner;
32
33  _ISR_lock_ISR_disable( &lock_context );
34  _Rate_monotonic_Acquire_critical( the_period, &lock_context );
35  wait_flags = _Thread_Wait_flags_get( owner );
36
37  if (
38    ( wait_flags & THREAD_WAIT_CLASS_PERIOD ) != 0
39      && owner->Wait.return_argument == the_period
40  ) {
41    bool unblock;
42    bool success;
43
44    owner->Wait.return_argument = NULL;
45
46    success = _Thread_Wait_flags_try_change_release(
47      owner,
48      RATE_MONOTONIC_INTEND_TO_BLOCK,
49      RATE_MONOTONIC_READY_AGAIN
50    );
51    if ( success ) {
52      unblock = false;
53    } else {
54      _Assert( _Thread_Wait_flags_get( owner ) == RATE_MONOTONIC_BLOCKED );
55      _Thread_Wait_flags_set( owner, RATE_MONOTONIC_READY_AGAIN );
56      unblock = true;
57    }
58
59    _Rate_monotonic_Restart( the_period, owner, &lock_context );
60
61    if ( unblock ) {
62      _Thread_Unblock( owner );
63    }
64  } else {
65    the_period->state = RATE_MONOTONIC_EXPIRED;
66    _Rate_monotonic_Release( the_period, &lock_context );
67  }
68}
Note: See TracBrowser for help on using the repository browser.