source: rtems/cpukit/score/include/rtems/score/apimutex.h @ 6c2b8a4b

5
Last change on this file since 6c2b8a4b was 6c2b8a4b, checked in by Sebastian Huber <sebastian.huber@…>, on 11/29/17 at 05:23:27

score: Use self-contained API mutex

Use a self-contained recursive mutex for API_Mutex_Control. The API
mutexes are protected against asynchronous thread cancellation.

Add dedicated mutexes for libatomic and TOD.

Close #2629.
Close #2630.

  • Property mode set to 100644
File size: 2.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/thread.h>
22
23#include <sys/lock.h>
24
25/**
26 * @defgroup ScoreAPIMutex API Mutex Handler
27 *
28 * @ingroup Score
29 *
30 * @brief Provides routines to ensure mutual exclusion on API level.
31 */
32/**@{**/
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/**
39 * @brief Control block used to manage each API mutex.
40 */
41typedef struct {
42  /**
43   * A recursive mutex.
44   */
45  struct _Mutex_recursive_Control Mutex;
46
47  /**
48   * @brief The thread life protection state before the outer-most mutex
49   * obtain.
50   */
51  Thread_Life_state previous_thread_life_state;
52} API_Mutex_Control;
53
54/**
55 * @brief Statically initialize an API mutex.
56 */
57#define API_MUTEX_INITIALIZER( name ) \
58  { _MUTEX_RECURSIVE_NAMED_INITIALIZER( name ), 0 }
59
60/**
61 * @brief Acquires the specified API mutex.
62 *
63 * @param[in] mutex The API mutex.
64 */
65void _API_Mutex_Lock( API_Mutex_Control *mutex );
66
67/**
68 * @brief Releases the specified API mutex.
69 *
70 * @param[in] mutex The API mutex.
71 */
72void _API_Mutex_Unlock( API_Mutex_Control *mutex );
73
74/**
75 * @brief Checks if the specified API mutex is owned by the executing thread.
76 *
77 * @param[in] mutex The API mutex.
78 */
79bool _API_Mutex_Is_owner( const API_Mutex_Control *mutex );
80
81/** @} */
82
83/**
84 * @defgroup ScoreAllocatorMutex RTEMS Allocator Mutex
85 *
86 * @ingroup ScoreAPIMutex
87 *
88 * @brief Protection for all memory allocations and deallocations in RTEMS.
89 *
90 * When the APIs all use this for allocation and deallocation protection, then
91 * this possibly should be renamed and moved to a higher level in the
92 * hierarchy.
93 */
94/**@{**/
95
96void _RTEMS_Lock_allocator( void );
97
98void _RTEMS_Unlock_allocator( void );
99
100bool _RTEMS_Allocator_is_owner( void );
101
102/** @} */
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif
109/*  end of include file */
Note: See TracBrowser for help on using the repository browser.