source: rtems/cpukit/score/src/coremutex.c @ 78b867e2

4.10
Last change on this file since 78b867e2 was 78b867e2, checked in by Gedare Bloom <gedare@…>, on 12/21/17 at 16:49:30

score: replace current and real priority with priority node

Encapsulate the current_priority and real_priority fields of
the thread control block with a Thread_Priority_node struct.
Propagate modifications throughout the tree where the two
fields are directly accessed.

Updates #3359.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  Mutex Handler
3 *
4 *  DESCRIPTION:
5 *
6 *  This package is the implementation of the Mutex Handler.
7 *  This handler provides synchronization and mutual exclusion capabilities.
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.com/license/LICENSE.
15 *
16 *  $Id$
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <rtems/system.h>
24#include <rtems/score/isr.h>
25#include <rtems/score/coremutex.h>
26#include <rtems/score/states.h>
27#include <rtems/score/thread.h>
28#include <rtems/score/threadq.h>
29
30/*PAGE
31 *
32 *  _CORE_mutex_Initialize
33 *
34 *  This routine initializes a mutex at create time and set the control
35 *  structure according to the values passed.
36 *
37 *  Input parameters:
38 *    the_mutex             - the mutex control block to initialize
39 *    the_mutex_attributes  - the mutex attributes specified at create time
40 *    initial_lock          - mutex initial lock or unlocked status
41 *
42 *  Output parameters:  NONE
43 */
44
45CORE_mutex_Status _CORE_mutex_Initialize(
46  CORE_mutex_Control           *the_mutex,
47  CORE_mutex_Attributes        *the_mutex_attributes,
48  uint32_t                      initial_lock
49)
50{
51
52/* Add this to the RTEMS environment later ?????????
53  rtems_assert( initial_lock == CORE_MUTEX_LOCKED ||
54                initial_lock == CORE_MUTEX_UNLOCKED );
55 */
56
57  the_mutex->Attributes    = *the_mutex_attributes;
58  the_mutex->lock          = initial_lock;
59  the_mutex->blocked_count = 0;
60
61  if ( initial_lock == CORE_MUTEX_LOCKED ) {
62    bool is_priority_ceiling =
63     _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes );
64
65    the_mutex->nest_count = 1;
66    the_mutex->holder     = _Thread_Executing;
67    the_mutex->holder_id  = _Thread_Executing->Object.id;
68
69    if (  is_priority_ceiling ||
70         _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
71      Priority_Control ceiling = the_mutex->Attributes.priority_ceiling;
72
73      if ( is_priority_ceiling &&
74           _Thread_Executing->Priority_node.current_priority < ceiling )
75       return CORE_MUTEX_STATUS_CEILING_VIOLATED;
76#ifdef __RTEMS_STRICT_ORDER_MUTEX__
77       _Chain_Prepend_unprotected( &_Thread_Executing->lock_mutex,
78                                   &the_mutex->queue.lock_queue );
79       the_mutex->queue.priority_before = _Thread_Executing->Priority_node.current_priority;
80#endif
81
82      _Thread_Executing->resource_count++;
83      if ( is_priority_ceiling )
84        _Thread_Change_priority( _Thread_Executing, ceiling, false );
85    }
86  } else {
87    the_mutex->nest_count = 0;
88    the_mutex->holder     = NULL;
89    the_mutex->holder_id  = 0;
90  }
91
92  _Thread_queue_Initialize(
93    &the_mutex->Wait_queue,
94    _CORE_mutex_Is_fifo( the_mutex_attributes ) ?
95      THREAD_QUEUE_DISCIPLINE_FIFO : THREAD_QUEUE_DISCIPLINE_PRIORITY,
96    STATES_WAITING_FOR_MUTEX,
97    CORE_MUTEX_TIMEOUT
98  );
99
100  return CORE_MUTEX_STATUS_SUCCESSFUL;
101}
Note: See TracBrowser for help on using the repository browser.