Debian Codegraph @

external/portaudio/pa_unix_util.h

raw symbols SCIP
1 /*
2 * $Id$
3 * Portable Audio I/O Library
4 * UNIX platform-specific support functions
5 *
6 * Based on the Open Source API proposed by Ross Bencina
7 * Copyright (c) 1999-2000 Ross Bencina
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining
10 * a copy of this software and associated documentation files
11 * (the "Software"), to deal in the Software without restriction,
12 * including without limitation the rights to use, copy, modify, merge,
13 * publish, distribute, sublicense, and/or sell copies of the Software,
14 * and to permit persons to whom the Software is furnished to do so,
15 * subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 */
28
29 /*
30 * The text above constitutes the entire PortAudio license; however,
31 * the PortAudio community also makes the following non-binding requests:
32 *
33 * Any person wishing to distribute modifications to the Software is
34 * requested to send the modifications to the original developer so that
35 * they can be incorporated into the canonical version. It is also
36 * requested that these non-binding requests be included along with the
37 * license above.
38 */
39
40 /** @file
41 @ingroup unix_src
42 */
43
44 #ifndef PA_UNIX_UTIL_H
45 #define PA_UNIX_UTIL_Hcxx . . $ `external/portaudio/pa_unix_util.h:45:9`!
46
47 #include "pa_cpuload.h"cxx . . $ `<file>/external/portaudio/pa_cpuload.h`/
48 #include <assert.h>
49 #include <pthread.h>
50 #include <signal.h>
51
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif /* __cplusplus */
56
57 #define PA_MINcxx . . $ `external/portaudio/pa_unix_util.h:57:9`!(x,y) ( (x) < (y) ? (x) : (y) )
58 #define PA_MAXcxx . . $ `external/portaudio/pa_unix_util.h:58:9`!(x,y) ( (x) > (y) ? (x) : (y) )
59
60 /* Utilize GCC branch prediction for error tests */
61 #if defined __GNUC__cxx . . $ `<built-in>:8:9`! && __GNUC__cxx . . $ `<built-in>:8:9`! >= 3
62 #define UNLIKELYcxx . . $ `external/portaudio/pa_unix_util.h:62:9`!(expr) __builtin_expect( (expr), 0 )
63 #else
64 #define UNLIKELY(expr) (expr)
65 #endif
66
67 #define STRINGIZE_HELPERcxx . . $ `external/portaudio/pa_unix_util.h:67:9`!(expr) #expr
68 #define STRINGIZEcxx . . $ `external/portaudio/pa_unix_util.h:68:9`!(expr) STRINGIZE_HELPERcxx . . $ `external/portaudio/pa_unix_util.h:67:9`!(expr)
69
70 #define PA_UNLESScxx . . $ `external/portaudio/pa_unix_util.h:70:9`!(expr, code) \
71 do { \
72 if( UNLIKELYcxx . . $ `external/portaudio/pa_unix_util.h:62:9`!( (expr) == 0 ) ) \
73 { \
74 PaUtil_DebugPrint(( "Expression '" #expr "' failed in '" __FILE__ "', line: " STRINGIZEcxx . . $ `external/portaudio/pa_unix_util.h:68:9`!( __LINE__ ) "\n" )); \
75 result = (code); \
76 goto error; \
77 } \
78 } while (0);
79
80 static PaErrorcxx . . $ PaError# paUtilErr_cxx . . $ paUtilErr_.; /* Used with PA_ENSURE */
81
82 /* Check PaError */
83 #define PA_ENSUREcxx . . $ `external/portaudio/pa_unix_util.h:83:9`!(expr) \
84 do { \
85 if( UNLIKELYcxx . . $ `external/portaudio/pa_unix_util.h:62:9`!( (paUtilErr_ = (expr)) < paNoError ) ) \
86 { \
87 PaUtil_DebugPrint(( "Expression '" #expr "' failed in '" __FILE__ "', line: " STRINGIZEcxx . . $ `external/portaudio/pa_unix_util.h:68:9`!( __LINE__ ) "\n" )); \
88 result = paUtilErr_; \
89 goto error; \
90 } \
91 } while (0);
92
93 #define PA_ASSERT_CALLcxx . . $ `external/portaudio/pa_unix_util.h:93:9`!(expr, success) \
94 paUtilErr_ = (expr); \
95 assertcxx . . $ `/usr/include/assert.h:118:11`!( success == paUtilErr_ );
96
97 #define PA_ENSURE_SYSTEMcxx . . $ `external/portaudio/pa_unix_util.h:97:9`!(expr, success) \
98 do { \
99 if( UNLIKELYcxx . . $ `external/portaudio/pa_unix_util.h:62:9`!( (paUtilErr_ = (expr)) != success ) ) \
100 { \
101 /* PaUtil_SetLastHostErrorInfo should only be used in the main thread */ \
102 if( pthread_equal(pthread_self(), paUnixMainThread) ) \
103 { \
104 PaUtil_SetLastHostErrorInfo( paALSA, paUtilErr_, strerror( paUtilErr_ ) ); \
105 } \
106 PaUtil_DebugPrint( "Expression '" #expr "' failed in '" __FILE__ "', line: " STRINGIZEcxx . . $ `external/portaudio/pa_unix_util.h:68:9`!( __LINE__ ) "\n" ); \
107 result = paUnanticipatedHostError; \
108 goto error; \
109 } \
110 } while( 0 );
111
112 typedef structcxx . . $ $anonymous_type_3ce9b538b650f415_0# {
113 pthread_tcxx . . $ pthread_t# callbackThreadcxx . . $ $anonymous_type_3ce9b538b650f415_0#callbackThread.;
114 } PaUtilThreadingcxx . . $ PaUtilThreading#;
115
116 PaErrorcxx . . $ PaError# PaUtil_InitializeThreadingcxx . . $ PaUtil_InitializeThreading(afd328f9ad6bf7db).( PaUtilThreadingcxx . . $ PaUtilThreading# *threading );
117 void PaUtil_TerminateThreadingcxx . . $ PaUtil_TerminateThreading(b96ea2e7b8c18972).( PaUtilThreadingcxx . . $ PaUtilThreading# *threading );
118 PaErrorcxx . . $ PaError# PaUtil_StartThreadingcxx . . $ PaUtil_StartThreading(abc04917ba655067).( PaUtilThreadingcxx . . $ PaUtilThreading# *threading, void *(*threadRoutine)(void *), void *data );
119 PaErrorcxx . . $ PaError# PaUtil_CancelThreadingcxx . . $ PaUtil_CancelThreading(abcce7532d703cd2).( PaUtilThreadingcxx . . $ PaUtilThreading# *threading, int wait, PaErrorcxx . . $ PaError# *exitResult );
120
121 /* State accessed by utility functions */
122
123 /*
124 void PaUnix_SetRealtimeScheduling( int rt );
125
126 void PaUtil_InitializeThreading( PaUtilThreading *th, PaUtilCpuLoadMeasurer *clm );
127
128 PaError PaUtil_CreateCallbackThread( PaUtilThreading *th, void *(*CallbackThreadFunc)( void * ), PaStream *s );
129
130 PaError PaUtil_KillCallbackThread( PaUtilThreading *th, PaError *exitResult );
131
132 void PaUtil_CallbackUpdate( PaUtilThreading *th );
133 */
134
135 extern pthread_tcxx . . $ pthread_t# paUnixMainThreadcxx . . $ paUnixMainThread.;
136
137 typedef structcxx . . $ $anonymous_type_3ce9b538b650f415_1#
138 {
139 pthread_mutex_tcxx . . $ pthread_mutex_t# mtxcxx . . $ $anonymous_type_3ce9b538b650f415_1#mtx.;
140 } PaUnixMutexcxx . . $ PaUnixMutex#;
141
142 PaErrorcxx . . $ PaError# PaUnixMutex_Initializecxx . . $ PaUnixMutex_Initialize(24c0b4e4fdc01d02).( PaUnixMutexcxx . . $ PaUnixMutex#* self );
143 PaErrorcxx . . $ PaError# PaUnixMutex_Terminatecxx . . $ PaUnixMutex_Terminate(24c0b4e4fdc01d02).( PaUnixMutexcxx . . $ PaUnixMutex#* self );
144 PaErrorcxx . . $ PaError# PaUnixMutex_Lockcxx . . $ PaUnixMutex_Lock(24c0b4e4fdc01d02).( PaUnixMutexcxx . . $ PaUnixMutex#* self );
145 PaErrorcxx . . $ PaError# PaUnixMutex_Unlockcxx . . $ PaUnixMutex_Unlock(24c0b4e4fdc01d02).( PaUnixMutexcxx . . $ PaUnixMutex#* self );
146
147 typedef structcxx . . $ $anonymous_type_3ce9b538b650f415_2#
148 {
149 pthread_tcxx . . $ pthread_t# threadcxx . . $ $anonymous_type_3ce9b538b650f415_2#thread.;
150 int parentWaitingcxx . . $ $anonymous_type_3ce9b538b650f415_2#parentWaiting.;
151 int stopRequestedcxx . . $ $anonymous_type_3ce9b538b650f415_2#stopRequested.;
152 int lockedcxx . . $ $anonymous_type_3ce9b538b650f415_2#locked.;
153 PaUnixMutexcxx . . $ PaUnixMutex# mtxcxx . . $ $anonymous_type_3ce9b538b650f415_2#mtx.;
154 pthread_cond_tcxx . . $ pthread_cond_t# condcxx . . $ $anonymous_type_3ce9b538b650f415_2#cond.;
155 volatile sig_atomic_tcxx . . $ sig_atomic_t# stopRequestcxx . . $ $anonymous_type_3ce9b538b650f415_2#stopRequest.;
156 } PaUnixThreadcxx . . $ PaUnixThread#;
157
158 /** Initialize global threading state.
159 */
160 PaErrorcxx . . $ PaError# PaUnixThreading_Initializecxx . . $ PaUnixThreading_Initialize(b126dc7c1de90089).( void );
161
162 /** Perish, passing on eventual error code.
163 *
164 * A thin wrapper around pthread_exit, will automatically pass on any error code to the joining thread.
165 * If the result indicates an error, i.e. it is not equal to paNoError, this function will automatically
166 * allocate a pointer so the error is passed on with pthread_exit. If the result indicates that all is
167 * well however, only a NULL pointer will be handed to pthread_exit. Thus, the joining thread should
168 * check whether a non-NULL result pointer is obtained from pthread_join and make sure to free it.
169 * @param result: The error code to pass on to the joining thread.
170 */
171 #define PaUnixThreading_EXITcxx . . $ `external/portaudio/pa_unix_util.h:171:9`!(result) \
172 do { \
173 PaError* pres = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; \
174 if( paNoError != (result) ) \
175 { \
176 pres = malloc( sizeof (PaError) ); \
177 *pres = (result); \
178 } \
179 pthread_exit( pres ); \
180 } while (0);
181
182 /** Spawn a thread.
183 *
184 * Intended for spawning the callback thread from the main thread. This function can even block (for a certain
185 * time or indefinitely) until notified by the callback thread (using PaUnixThread_NotifyParent), which can be
186 * useful in order to make sure that callback has commenced before returning from Pa_StartStream.
187 * @param threadFunc: The function to be executed in the child thread.
188 * @param waitForChild: If not 0, wait for child thread to call PaUnixThread_NotifyParent. Less than 0 means
189 * wait for ever, greater than 0 wait for the specified time.
190 * @param rtSched: Enable realtime scheduling?
191 * @return: If timed out waiting on child, paTimedOut.
192 */
193 PaErrorcxx . . $ PaError# PaUnixThread_Newcxx . . $ PaUnixThread_New(edbe22a4b3bbd15e).( PaUnixThreadcxx . . $ PaUnixThread#* self, void* (*threadFunc)( void* ), void* threadArg, PaTimecxx . . $ PaTime# waitForChild,
194 int rtSched );
195
196 /** Terminate thread.
197 *
198 * @param wait: If true, request that background thread stop and wait until it does, else cancel it.
199 * @param exitResult: If non-null this will upon return contain the exit status of the thread.
200 */
201 PaErrorcxx . . $ PaError# PaUnixThread_Terminatecxx . . $ PaUnixThread_Terminate(d91498f3682360e8).( PaUnixThreadcxx . . $ PaUnixThread#* self, int wait, PaErrorcxx . . $ PaError#* exitResult );
202
203 /** Prepare to notify waiting parent thread.
204 *
205 * An internal lock must be held before the parent is notified in PaUnixThread_NotifyParent, call this to
206 * acquire it beforehand.
207 * @return: If parent is not waiting, paInternalError.
208 */
209 PaErrorcxx . . $ PaError# PaUnixThread_PrepareNotifycxx . . $ PaUnixThread_PrepareNotify(8d04469c9f60d75).( PaUnixThreadcxx . . $ PaUnixThread#* self );
210
211 /** Notify waiting parent thread.
212 *
213 * @return: If parent timed out waiting, paTimedOut. If parent was never waiting, paInternalError.
214 */
215 PaErrorcxx . . $ PaError# PaUnixThread_NotifyParentcxx . . $ PaUnixThread_NotifyParent(8d04469c9f60d75).( PaUnixThreadcxx . . $ PaUnixThread#* self );
216
217 /** Has the parent thread requested this thread to stop?
218 */
219 int PaUnixThread_StopRequestedcxx . . $ PaUnixThread_StopRequested(8d04469c9f60d75).( PaUnixThreadcxx . . $ PaUnixThread#* self );
220
221 #ifdef __cplusplus
222 }
223 #endif /* __cplusplus */
224 #endif