source: rtems/cpukit/score/include/rtems/score/apimutex.h @ 0b713f89

5
Last change on this file since 0b713f89 was 0b713f89, checked in by Sebastian Huber <sebastian.huber@…>, on 05/30/16 at 04:59:55

score: Rework CORE inherit priority mutex

Provide dedicated seize and surrender methods for inherit priority
mutexes. This eliminates CORE_mutex_Attributes.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreAPIMutex
5 *
6 * @brief API Mutex Handler API
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2008.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#ifndef _RTEMS_SCORE_APIMUTEX_H
19#define _RTEMS_SCORE_APIMUTEX_H
20
21#include <rtems/score/coremutex.h>
22#include <rtems/score/object.h>
23
24/**
25 * @defgroup ScoreAPIMutex API Mutex Handler
26 *
27 * @ingroup Score
28 *
29 * @brief Provides routines to ensure mutual exclusion on API level.
30 */
31/**@{**/
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/**
38 * @brief Control block used to manage each API mutex.
39 */
40typedef struct {
41  /**
42   * @brief Allows each API Mutex to be a full-fledged RTEMS object.
43   */
44  Objects_Control Object;
45
46  /**
47   * Contains the SuperCore mutex information.
48   */
49  CORE_recursive_mutex_Control Mutex;
50
51  /**
52   * @brief The thread life protection state before the outer-most mutex
53   * obtain.
54   */
55  Thread_Life_state previous_thread_life_state;
56} API_Mutex_Control;
57
58/**
59 *  @brief Initialization for the API Mutexe Handler.
60 *
61 *  The value @a maximum_mutexes is the maximum number of API mutexes that may
62 *  exist at any time.
63 *
64 *  @param[in] maximum_mutexes is the maximum number of API mutexes.
65 */
66void _API_Mutex_Initialization( uint32_t maximum_mutexes );
67
68/**
69 * @brief Allocates an API mutex from the inactive set and returns it in
70 * @a mutex.
71 */
72void _API_Mutex_Allocate( API_Mutex_Control **mutex );
73
74/**
75 * @brief Acquires the specified API mutex.
76 *
77 * @param[in] mutex The API mutex.
78 */
79void _API_Mutex_Lock( API_Mutex_Control *mutex );
80
81/**
82 * @brief Releases the specified API mutex.
83 *
84 * @param[in] mutex The API mutex.
85 */
86void _API_Mutex_Unlock( API_Mutex_Control *mutex );
87
88/**
89 * @brief Checks if the specified API mutex is owned by the executing thread.
90 *
91 * @param[in] mutex The API mutex.
92 */
93bool _API_Mutex_Is_owner( const API_Mutex_Control *mutex );
94
95/** @} */
96
97/**
98 * @defgroup ScoreAllocatorMutex RTEMS Allocator Mutex
99 *
100 * @ingroup ScoreAPIMutex
101 *
102 * @brief Protection for all memory allocations and deallocations in RTEMS.
103 *
104 * When the APIs all use this for allocation and deallocation protection, then
105 * this possibly should be renamed and moved to a higher level in the
106 * hierarchy.
107 */
108/**@{**/
109
110/**
111 *  @brief Memory allocation mutex.
112 *
113 *  This points to the API Mutex instance used to ensure that only
114 *  one thread at a time is allocating or freeing memory.
115 */
116extern API_Mutex_Control *_RTEMS_Allocator_Mutex;
117
118static inline void _RTEMS_Lock_allocator( void )
119{
120  _API_Mutex_Lock( _RTEMS_Allocator_Mutex );
121}
122
123static inline void _RTEMS_Unlock_allocator( void )
124{
125  _API_Mutex_Unlock( _RTEMS_Allocator_Mutex );
126}
127
128static inline bool _RTEMS_Allocator_is_owner( void )
129{
130  return _API_Mutex_Is_owner( _RTEMS_Allocator_Mutex );
131}
132
133extern API_Mutex_Control *_Once_Mutex;
134
135static inline void _Once_Lock( void )
136{
137  _API_Mutex_Lock( _Once_Mutex );
138}
139
140static inline void _Once_Unlock( void )
141{
142  _API_Mutex_Unlock( _Once_Mutex );
143}
144
145/** @} */
146
147#ifdef __cplusplus
148}
149#endif
150
151#endif
152/*  end of include file */
Note: See TracBrowser for help on using the repository browser.