source: rtems/cpukit/score/src/coremutex.c @ cb8d3e7

4.115
Last change on this file since cb8d3e7 was cb8d3e7, checked in by Sebastian Huber <sebastian.huber@…>, on 03/27/14 at 07:04:10

score: Delete CORE_mutex_Control::blocked_count

  • Property mode set to 100644
File size: 2.1 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  uint32_t                      initial_lock
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  the_mutex->lock          = initial_lock;
41
42  if ( initial_lock == CORE_MUTEX_LOCKED ) {
43    the_mutex->nest_count = 1;
44    the_mutex->holder     = executing;
45    the_mutex->holder_id  = executing->Object.id;
46    if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
47         _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
48
49      if ( executing->current_priority <
50             the_mutex->Attributes.priority_ceiling )
51       return CORE_MUTEX_STATUS_CEILING_VIOLATED;
52#ifdef __RTEMS_STRICT_ORDER_MUTEX__
53       _Chain_Prepend_unprotected( &executing->lock_mutex,
54                                   &the_mutex->queue.lock_queue );
55       the_mutex->queue.priority_before = executing->current_priority;
56#endif
57
58      executing->resource_count++;
59    }
60  } else {
61    the_mutex->nest_count = 0;
62    the_mutex->holder     = NULL;
63    the_mutex->holder_id  = 0;
64  }
65
66  _Thread_queue_Initialize(
67    &the_mutex->Wait_queue,
68    _CORE_mutex_Is_fifo( the_mutex_attributes ) ?
69      THREAD_QUEUE_DISCIPLINE_FIFO : THREAD_QUEUE_DISCIPLINE_PRIORITY,
70    STATES_WAITING_FOR_MUTEX,
71    CORE_MUTEX_TIMEOUT
72  );
73
74  return CORE_MUTEX_STATUS_SUCCESSFUL;
75}
Note: See TracBrowser for help on using the repository browser.