source: rtems/cpukit/score/src/coremutex.c @ 8ae37323

4.115
Last change on this file since 8ae37323 was 4edf348c, checked in by Sebastian Huber <sebastian.huber@…>, on 05/22/14 at 07:31:13

score: PR2179: Fix initially locked PCP mutexes

Elevate the priority of the creating task to the ceiling priority in
case a semaphore is created as initially locked.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Initialize a Core Mutex
5 *  @ingroup ScoreMutex
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
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/thread.h>
25
26CORE_mutex_Status _CORE_mutex_Initialize(
27  CORE_mutex_Control           *the_mutex,
28  Thread_Control               *executing,
29  const CORE_mutex_Attributes  *the_mutex_attributes,
30  bool                          initially_locked
31)
32{
33
34/* Add this to the RTEMS environment later ?????????
35  rtems_assert( initial_lock == CORE_MUTEX_LOCKED ||
36                initial_lock == CORE_MUTEX_UNLOCKED );
37 */
38
39  the_mutex->Attributes    = *the_mutex_attributes;
40
41  if ( initially_locked ) {
42    the_mutex->nest_count = 1;
43    the_mutex->holder     = executing;
44    if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
45         _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
46      Priority_Control ceiling = the_mutex->Attributes.priority_ceiling;
47
48      /*
49       * The mutex initialization is only protected by the allocator lock in
50       * general.  Disable thread dispatching before the priority check to
51       * prevent interference with priority inheritance.
52       */
53      _Thread_Disable_dispatch();
54
55      if ( executing->current_priority < ceiling ) {
56        _Thread_Enable_dispatch();
57        return CORE_MUTEX_STATUS_CEILING_VIOLATED;
58      }
59
60#ifdef __RTEMS_STRICT_ORDER_MUTEX__
61       _Chain_Prepend_unprotected( &executing->lock_mutex,
62                                   &the_mutex->queue.lock_queue );
63       the_mutex->queue.priority_before = executing->current_priority;
64#endif
65
66      executing->resource_count++;
67
68      _Thread_Change_priority( executing, ceiling, false );
69      _Thread_Enable_dispatch();
70    }
71  } else {
72    the_mutex->nest_count = 0;
73    the_mutex->holder     = NULL;
74  }
75
76  _Thread_queue_Initialize(
77    &the_mutex->Wait_queue,
78    _CORE_mutex_Is_fifo( the_mutex_attributes ) ?
79      THREAD_QUEUE_DISCIPLINE_FIFO : THREAD_QUEUE_DISCIPLINE_PRIORITY,
80    STATES_WAITING_FOR_MUTEX,
81    CORE_MUTEX_TIMEOUT
82  );
83
84  return CORE_MUTEX_STATUS_SUCCESSFUL;
85}
Note: See TracBrowser for help on using the repository browser.