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

5
Last change on this file since d79df38 was d79df38, checked in by Sebastian Huber <sebastian.huber@…>, on 07/26/16 at 08:34:21

score: Add deadlock detection

The mutex objects use the owner field of the thread queues for the mutex
owner. Use this and add a deadlock detection to
_Thread_queue_Enqueue_critical() for thread queues with an owner.

Update #2412.
Update #2556.
Close #2765.

  • Property mode set to 100644
File size: 2.9 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#include <rtems/score/watchdog.h>
25
26Status_Control _CORE_mutex_Seize_slow(
27  CORE_mutex_Control   *the_mutex,
28  Thread_Control       *executing,
29  Thread_Control       *owner,
30  bool                  wait,
31  Thread_queue_Context *queue_context
32)
33{
34  if ( !wait ) {
35    _CORE_mutex_Release( the_mutex, queue_context );
36    return STATUS_UNAVAILABLE;
37  }
38
39#if !defined(RTEMS_SMP)
40  /*
41   * We must disable thread dispatching here since we enable the interrupts for
42   * priority inheritance mutexes.
43   */
44  _Thread_Dispatch_disable();
45
46  /*
47   * To enable interrupts here works only since exactly one executing thread
48   * exists and only threads are allowed to seize and surrender mutexes with
49   * the priority inheritance protocol.  On SMP configurations more than one
50   * executing thread may exist, so here we must not release the lock, since
51   * otherwise the current owner may be no longer the owner of the mutex
52   * once we released the lock.
53   */
54  _CORE_mutex_Release( the_mutex, queue_context );
55#endif
56
57#if defined(RTEMS_SMP)
58  _Thread_queue_Context_set_expected_level( queue_context, 1 );
59#else
60  _ISR_lock_ISR_disable( &queue_context->Lock_context );
61  _CORE_mutex_Acquire_critical( the_mutex, queue_context );
62  _Thread_queue_Context_set_expected_level( queue_context, 2 );
63#endif
64
65  _Thread_queue_Context_set_deadlock_callout(
66    queue_context,
67    _Thread_queue_Deadlock_status
68  );
69
70  _Thread_queue_Enqueue_critical(
71    &the_mutex->Wait_queue.Queue,
72    CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
73    executing,
74    STATES_WAITING_FOR_MUTEX,
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
85Status_Control _CORE_mutex_Seize_no_protocol_slow(
86  CORE_mutex_Control            *the_mutex,
87  const Thread_queue_Operations *operations,
88  Thread_Control                *executing,
89  bool                           wait,
90  Thread_queue_Context          *queue_context
91)
92{
93  if ( wait ) {
94    _Thread_queue_Context_set_expected_level( queue_context, 1 );
95    _Thread_queue_Context_set_deadlock_callout(
96      queue_context,
97      _Thread_queue_Deadlock_status
98    );
99    _Thread_queue_Enqueue_critical(
100      &the_mutex->Wait_queue.Queue,
101      operations,
102      executing,
103      STATES_WAITING_FOR_MUTEX,
104      queue_context
105    );
106    return _Thread_Wait_get_status( executing );
107  } else {
108    _CORE_mutex_Release( the_mutex, queue_context );
109    return STATUS_UNAVAILABLE;
110  }
111}
Note: See TracBrowser for help on using the repository browser.