source: rtems/cpukit/score/include/rtems/score/coremutex.h @ 03e89287

4.115
Last change on this file since 03e89287 was 03e89287, checked in by Sebastian Huber <sebastian.huber@…>, on 03/27/14 at 13:46:31

score: Delete CORE_mutex_Control::lock

The holder field is enough to determine if a mutex is locked or not.

This leads also to better error status codes in case a
rtems_semaphore_release() is done for a mutex without having the
ownership.

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief CORE Mutex API
5 *
6 * This include file contains all the constants and structures associated with
7 * the Mutex Handler.  A mutex is an enhanced version of the standard Dijkstra
8 * binary semaphore used to provide synchronization and mutual exclusion
9 * capabilities.
10 */
11
12/*
13 *  COPYRIGHT (c) 1989-2011.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.org/license/LICENSE.
19 */
20
21#ifndef _RTEMS_SCORE_COREMUTEX_H
22#define _RTEMS_SCORE_COREMUTEX_H
23
24#include <rtems/score/thread.h>
25#include <rtems/score/threadq.h>
26#include <rtems/score/priority.h>
27#include <rtems/score/watchdog.h>
28#include <rtems/score/interr.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/**
35 *  @defgroup ScoreMutex Mutex Handler
36 *
37 *  @ingroup Score
38 *
39 *  This handler encapsulates functionality which provides the foundation
40 *  Mutex services used in all of the APIs supported by RTEMS.
41 */
42/**@{*/
43
44/**
45 *  @brief The blocking disciplines for a mutex.
46 *
47 *  This enumerated type defines the blocking disciplines for a mutex.
48 */
49typedef enum {
50  /** This specifies that threads will wait for the mutex in FIFO order. */
51  CORE_MUTEX_DISCIPLINES_FIFO,
52  /** This specifies that threads will wait for the mutex in priority order.  */
53  CORE_MUTEX_DISCIPLINES_PRIORITY,
54  /** This specifies that threads will wait for the mutex in priority order.
55   *  Additionally, the Priority Inheritance Protocol will be in effect.
56   */
57  CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT,
58  /** This specifies that threads will wait for the mutex in priority order.
59   *  Additionally, the Priority Ceiling Protocol will be in effect.
60   */
61  CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING
62}   CORE_mutex_Disciplines;
63
64/**
65 *  @brief The possible behaviors for lock nesting.
66 *
67 *  This enumerated type defines the possible behaviors for
68 *  lock nesting.
69 */
70typedef enum {
71  /**
72   *    This sequence has no blocking or errors:
73   *
74   *         + lock(m)
75   *         + lock(m)
76   *         + unlock(m)
77   *         + unlock(m)
78   */
79  CORE_MUTEX_NESTING_ACQUIRES,
80#if defined(RTEMS_POSIX_API)
81  /**
82   *    This sequence returns an error at the indicated point:
83   *
84   *        + lock(m)
85   *        + lock(m)   - already locked error
86   *        + unlock(m)
87   */
88  CORE_MUTEX_NESTING_IS_ERROR,
89#endif
90  /**
91   *    This sequence performs as indicated:
92   *        + lock(m)
93   *        + lock(m)   - deadlocks or timeouts
94   *        + unlock(m) - releases
95   */
96  CORE_MUTEX_NESTING_BLOCKS
97}  CORE_mutex_Nesting_behaviors;
98
99/**
100 *  @brief The control block used to manage attributes of each mutex.
101 *
102 *  The following defines the control block used to manage the
103 *  attributes of each mutex.
104 */
105typedef struct {
106  /** This field determines what the behavior of this mutex instance will
107   *  be when attempting to acquire the mutex when it is already locked.
108   */
109  CORE_mutex_Nesting_behaviors lock_nesting_behavior;
110  /** When this field is true, then only the thread that locked the mutex
111   *  is allowed to unlock it.
112   */
113  bool                         only_owner_release;
114  /** This field indicates whether threads waiting on the mutex block in
115   *  FIFO or priority order.
116   */
117  CORE_mutex_Disciplines       discipline;
118  /** This field contains the ceiling priority to be used if that protocol
119   *  is selected.
120   */
121  Priority_Control             priority_ceiling;
122}   CORE_mutex_Attributes;
123
124#ifdef __RTEMS_STRICT_ORDER_MUTEX__
125/**
126 * @brief The control block to manage lock chain of priority inheritance mutex.
127 *
128 * The following defines the control block used to manage lock chain of
129 * priority inheritance mutex.
130 */
131  typedef struct{
132    /** This field is a chian of locked mutex by a thread,new mutex will
133     *  be added to the head of queue, and the mutex which will be released
134     *  must be the head of queue.
135     */
136    Chain_Node                lock_queue;
137    /** This field is the priority of thread before locking this mutex
138     *
139     */
140    Priority_Control          priority_before;
141  }  CORE_mutex_order_list;
142#endif
143
144/**
145 *  @brief Control block used to manage each mutex.
146 *
147 *  The following defines the control block used to manage each mutex.
148 */
149typedef struct {
150  /** This field is the Waiting Queue used to manage the set of tasks
151   *  which are blocked waiting to lock the mutex.
152   */
153  Thread_queue_Control    Wait_queue;
154  /** This element is the set of attributes which define this instance's
155   *  behavior.
156   */
157  CORE_mutex_Attributes   Attributes;
158  /** This element contains the number of times the mutex has been acquired
159   *  nested.  This must be zero (0) before the mutex is actually unlocked.
160   */
161  uint32_t                nest_count;
162  /** This element points to the thread which is currently holding this mutex.
163   *  The holder is the last thread to successfully lock the mutex and which
164   *  has not unlocked it.  If the thread is not locked, there is no holder.
165   */
166  Thread_Control         *holder;
167#ifdef __RTEMS_STRICT_ORDER_MUTEX__
168  /** This field is used to manipulate the priority inheritance mutex queue*/
169  CORE_mutex_order_list   queue;
170#endif
171
172}   CORE_mutex_Control;
173
174/**@}*/
175
176#ifdef __cplusplus
177}
178#endif
179
180#endif
181/*  end of include file */
Note: See TracBrowser for help on using the repository browser.