RTI Connext DDS Micro  Version 2.4.11
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
osapi_mutex.h
Go to the documentation of this file.
1 /*
2  * FILE: osapi_mutex.h - Definition of mutex interface
3  *
4  * Copyright 2012-2015 Real-Time Innovations, Inc.
5  *
6  * No duplications, whole or partial, manual or electronic, may be made
7  * without express written permission. Any such copies, or
8  * revisions thereof, must display this notice unaltered.
9  * This code contains trade secrets of Real-Time Innovations, Inc.
10  *
11  * Modification History
12  * --------------------
13  * 12mar2012,tk Written
14  */
15 /*ce
16  * \file
17  * \brief Definition of mutex interface
18  */
19 #ifndef osapi_mutex_h
20 #define osapi_mutex_h
21 
22 #ifndef osapi_dll_h
23 #include "osapi/osapi_dll.h"
24 #endif
25 #ifndef osapi_types_h
26 #include "osapi/osapi_types.h"
27 #endif
28 
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 
34 /*e \defgroup OSAPI_MutexClass OSAPI Mutex
35  \ingroup OSAPIModule
36 
37  \brief Mutex API
38  */
39 
40 /*e \ingroup OSAPI_MutexClass
41  *
42  * Abstract Mutex object
43  */
44 struct OSAPI_Mutex;
45 
46 /*e \ingroup OSAPI_MutexClass
47  * The Mutex base-class
48  */
50 {
51  RTI_INT32 depth;
52  RTI_BOOL owned;
53  OSAPI_ThreadId owner;
54 };
55 
56 /*e \ingroup OSAPI_MutexClass
57  * Abstract Mutex type
58  */
59 typedef struct OSAPI_Mutex OSAPI_Mutex_T;
60 
61 #ifndef RTI_CERT
62 /*e \ingroup OSAPI_MutexClass
63  *
64  * \brief Delete a mutex.
65  *
66  * \param [in] mutex Delete a mutex created with \ref OSAPI_Mutex_new.
67  *
68  * \return RTI_TRUE on success, RTI_FALSE on failure
69  */
70 SHOULD_CHECK_RETURN OSAPIDllExport RTI_BOOL
72 #endif /* !RTI_CERT */
73 
74 /*e \ingroup OSAPI_MutexClass
75  *
76  * \brief Create a mutex.
77  *
78  * \return Pointer to a mutex in a not taken condition. NULL on failure.
79  *
80  * \sa \ref OSAPI_Mutex_delete
81  */
82 OSAPIDllExport OSAPI_Mutex_T*
83 OSAPI_Mutex_new(void);
84 
85 /*e \ingroup OSAPI_MutexClass
86  *
87  * \brief Take a mutex.
88  *
89  * \details
90  *
91  * A mutex can only be taken if it is not currently already taken
92  * by another thread; it CAN be taken if is it already taken by
93  * the same thread. In order to release a mutex, it must be
94  * given as many times a it has been taken. Note that `take` will
95  * block indefinitely.
96  *
97  * Note: the mutex is not required to support priority inversion;
98  * there is no protection against deadlocks or starvation.
99  *
100  * \param [in] self Take a mutex previously created with \ref OSAPI_Mutex_new.
101  *
102  * \return RTI_TRUE on success, RTI_FALSE on failure
103  *
104  * \sa \ref OSAPI_Mutex_give, \ref OSAPI_Mutex_new
105  *
106  */
107 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
109 
110 /*e \ingroup OSAPI_MutexClass
111  *
112  * \brief Give a mutex.
113  *
114  * \details
115  *
116  * A mutex can only be given if it is owned by the calling thread. Furthermore,
117  * it must be given as many times as it has been taken.
118  *
119  * \param [in] self Take a mutex previously created with \ref OSAPI_Mutex_new.
120  *
121  * \return RTI_TRUE on success, RTI_FALSE on failure
122  *
123  * \sa \ref OSAPI_Mutex_take, \ref OSAPI_Mutex_new
124  *
125  */
126 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
128 
129 /*e \ingroup OSAPI_MutexClass
130  *
131  * \brief Release a mutex temporarily at an arbitrary point in the code.
132  *
133  * \details
134  *
135  * The normal use of a mutex to take/return an equal number of times as part
136  * of the code-path. However, in some cases it is necessary to temporarily
137  * release a mutex (and save its state) and then later resume it.
138  *
139  * \param [in] self The mutex to release
140  * \param [out] level The current level of the mutex. This level must passed
141  * to \ref OSAPI_Mutex_resume.
142  *
143  * \return RTI_TRUE on success, RTI_FALSE on failure
144  *
145  * \sa \ref OSAPI_Mutex_take, \ref OSAPI_Mutex_new
146  *
147  */
148 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
149 OSAPI_Mutex_release(OSAPI_Mutex_T *self,RTI_UINT32 *level);
150 
151 
152 /*e \ingroup OSAPI_MutexClass
153  *
154  * \brief Resume taking a mutex passing in the corrent state.
155  *
156  * \param [in] self The mutex to resume
157  * \param [level] level The current state of the mutex, returned from
158  * \ref OSAPI_Mutex_release.
159  *
160  * \return RTI_TRUE on success, RTI_FALSE on failure
161  */
162 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
163 OSAPI_Mutex_resume(OSAPI_Mutex_T *self,RTI_UINT32 level);
164 
165 #ifdef __cplusplus
166 } /* extern "C" */
167 #endif
168 
169 
170 #endif /* osapi_mutex_h */

RTI Connext DDS Micro Version 2.4.11 Copyright © Mon Jul 23 2018 Real-Time Innovations, Inc