source: rtems/cpukit/score/src/coremutexseize.c @ 93306058

5
Last change on this file since 93306058 was 93306058, checked in by Sebastian Huber <sebastian.huber@…>, on 05/27/16 at 12:43:19

score: _CORE_mutex_Check_dispatch_for_seize()

Move the safety check performed by
_CORE_mutex_Check_dispatch_for_seize() out of the performance critical
path and generalize it. Blocking on a thread queue with an unexpected
thread dispatch disabled level is illegal in all system states.

Add the expected thread dispatch disable level (which may be 1 or 2
depending on the operation) to Thread_queue_Context and use it in
_Thread_queue_Enqueue_critical().

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Seize Mutex with Blocking
5 *  @ingroup ScoreMutex
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2006.
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/score/coremuteximpl.h>
22#include <rtems/score/statesimpl.h>
23#include <rtems/score/thread.h>
24
25Status_Control _CORE_mutex_Seize_interrupt_blocking(
26  CORE_mutex_Control   *the_mutex,
27  Thread_Control       *executing,
28  Watchdog_Interval     timeout,
29  Thread_queue_Context *queue_context
30)
31{
32#if !defined(RTEMS_SMP)
33  /*
34   * We must disable thread dispatching here since we enable the interrupts for
35   * priority inheritance mutexes.
36   */
37  _Thread_Dispatch_disable();
38#endif
39
40  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
41    Thread_Control *holder = the_mutex->holder;
42
43#if !defined(RTEMS_SMP)
44    /*
45     * To enable interrupts here works only since exactly one executing thread
46     * exists and only threads are allowed to seize and surrender mutexes with
47     * the priority inheritance protocol.  On SMP configurations more than one
48     * executing thread may exist, so here we must not release the lock, since
49     * otherwise the current holder may be no longer the holder of the mutex
50     * once we released the lock.
51     */
52    _CORE_mutex_Release( the_mutex, queue_context );
53#endif
54
55    _Thread_Inherit_priority( holder, executing );
56
57#if !defined(RTEMS_SMP)
58    _ISR_lock_ISR_disable( &queue_context->Lock_context );
59    _CORE_mutex_Acquire_critical( the_mutex, queue_context );
60#endif
61  }
62
63#if defined(RTEMS_SMP)
64  _Thread_queue_Context_set_expected_level( queue_context, 1 );
65#else
66  _Thread_queue_Context_set_expected_level( queue_context, 2 );
67#endif
68
69  _Thread_queue_Enqueue_critical(
70    &the_mutex->Wait_queue.Queue,
71    the_mutex->operations,
72    executing,
73    STATES_WAITING_FOR_MUTEX,
74    timeout,
75    queue_context
76  );
77
78#if !defined(RTEMS_SMP)
79  _Thread_Dispatch_enable( _Per_CPU_Get() );
80#endif
81
82  return _Thread_Wait_get_status( executing );
83}
84
Note: See TracBrowser for help on using the repository browser.