source: rtems/cpukit/score/include/rtems/score/apimutex.h @ 864d3475

4.115
Last change on this file since 864d3475 was 34684573, checked in by Sebastian Huber <sebastian.huber@…>, on 03/27/14 at 12:38:04

score: Use thread life protection for API mutexes

This prevents that asynchronous thread deletion can lead to an unusable
allocator or once mutex.

  • Property mode set to 100644
File size: 2.8 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_mutex_Control Mutex;
50
51  /**
52   * @brief The thread life protection state before the outer-most mutex
53   * obtain.
54   */
55  bool previous_thread_life_protection;
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
90/**
91 * @defgroup ScoreAllocatorMutex RTEMS Allocator Mutex
92 *
93 * @ingroup ScoreAPIMutex
94 *
95 * @brief Protection for all memory allocations and deallocations in RTEMS.
96 *
97 * When the APIs all use this for allocation and deallocation protection, then
98 * this possibly should be renamed and moved to a higher level in the
99 * hierarchy.
100 */
101/**@{**/
102
103/**
104 *  @brief Memory allocation mutex.
105 *
106 *  This points to the API Mutex instance used to ensure that only
107 *  one thread at a time is allocating or freeing memory.
108 */
109SCORE_EXTERN API_Mutex_Control *_RTEMS_Allocator_Mutex;
110
111static inline void _RTEMS_Lock_allocator( void )
112{
113  _API_Mutex_Lock( _RTEMS_Allocator_Mutex );
114}
115
116static inline void _RTEMS_Unlock_allocator( void )
117{
118  _API_Mutex_Unlock( _RTEMS_Allocator_Mutex );
119}
120
121SCORE_EXTERN API_Mutex_Control *_Once_Mutex;
122
123static inline void _Once_Lock( void )
124{
125  _API_Mutex_Lock( _Once_Mutex );
126}
127
128static inline void _Once_Unlock( void )
129{
130  _API_Mutex_Unlock( _Once_Mutex );
131}
132
133/** @} */
134
135#ifdef __cplusplus
136}
137#endif
138
139#endif
140/*  end of include file */
Note: See TracBrowser for help on using the repository browser.