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

5
Last change on this file since dafa5d88 was dafa5d88, checked in by Sebastian Huber <sebastian.huber@…>, on 09/03/15 at 08:27:16

score: Implement priority boosting

  • Property mode set to 100644
File size: 2.4 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/system.h>
22#include <rtems/score/isr.h>
23#include <rtems/score/coremuteximpl.h>
24#include <rtems/score/statesimpl.h>
25#include <rtems/score/thread.h>
26
27#if defined(__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__)
28void _CORE_mutex_Seize(
29  CORE_mutex_Control  *_the_mutex,
30  Thread_Control      *_executing,
31  Objects_Id           _id,
32  bool                 _wait,
33  Watchdog_Interval    _timeout,
34  ISR_Level            _level
35)
36{
37  _CORE_mutex_Seize_body(
38    _the_mutex,
39    _executing,
40    _id,
41    _wait,
42    _timeout,
43    _level
44  );
45}
46#endif
47
48void _CORE_mutex_Seize_interrupt_blocking(
49  CORE_mutex_Control  *the_mutex,
50  Thread_Control      *executing,
51  Watchdog_Interval    timeout,
52  ISR_lock_Context    *lock_context
53)
54{
55#if !defined(RTEMS_SMP)
56  /*
57   * We must disable thread dispatching here since we enable the interrupts for
58   * priority inheritance mutexes.
59   */
60  _Thread_Dispatch_disable();
61#endif
62
63  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
64    Thread_Control *holder = the_mutex->holder;
65
66#if !defined(RTEMS_SMP)
67    /*
68     * To enable interrupts here works only since exactly one executing thread
69     * exists and only threads are allowed to seize and surrender mutexes with
70     * the priority inheritance protocol.  On SMP configurations more than one
71     * executing thread may exist, so here we must not release the lock, since
72     * otherwise the current holder may be no longer the holder of the mutex
73     * once we released the lock.
74     */
75    _Thread_queue_Release( &the_mutex->Wait_queue, lock_context );
76#endif
77
78    _Thread_Inherit_priority( holder, executing );
79
80#if !defined(RTEMS_SMP)
81    _Thread_queue_Acquire( &the_mutex->Wait_queue, lock_context );
82#endif
83  }
84
85  _Thread_queue_Enqueue_critical(
86    &the_mutex->Wait_queue.Queue,
87    the_mutex->Wait_queue.operations,
88    executing,
89    STATES_WAITING_FOR_MUTEX,
90    timeout,
91    CORE_MUTEX_TIMEOUT,
92    lock_context
93  );
94
95#if !defined(RTEMS_SMP)
96  _Thread_Dispatch_enable( _Per_CPU_Get() );
97#endif
98}
99
Note: See TracBrowser for help on using the repository browser.