PortAudio  2.0
pa_pthread_util.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * PortAudio Portable Real-Time Audio Library
4  * Latest Version at: http://www.portaudio.com
5  *
6  * Based on the Open Source API proposed by Ross Bencina
7  * Copyright (c) 1999-2024 Ross Bencina, Phil Burk
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 
44 #ifndef PA_PTHREAD_UTIL_H
45 #define PA_PTHREAD_UTIL_H
46 
47 #include <time.h> /* timespec, clock_gettime */
48 #include <sys/types.h> /* clockid_t */
49 #if !(defined(WIN32) || defined(_WIN32))
50 #include <sys/time.h> /* gettimeofday on macos */
51 #endif
52 #include <pthread.h>
53 
54 #ifdef __cplusplus
55 extern "C"
56 {
57 #endif /* __cplusplus */
58 
59 /*
60  Use the presence of CLOCK_REALTIME as a proxy for the availability of
61  pthread_condattr_setclock, pthread_condattr_getclock and clock_gettime.
62 
63  Otherewise use a fallback path.
64 
65  On Apple, stick with default unix time using gettimeofday,
66  since CLOCK_MONOTONIC is known to be buggy:
67  https://discussions.apple.com/thread/253778121?sortBy=best
68 
69  And clock_gettime is not available pre-Sierra:
70  https://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x
71  https://stackoverflow.com/a/21352348
72 */
73 #if defined(CLOCK_REALTIME) && !defined(__APPLE__)
74 #define PAUTIL_USE_POSIX_ADVANCED_REALTIME 1
75 #else
76 #define PAUTIL_USE_POSIX_ADVANCED_REALTIME 0
77 #endif
78 
79 #if PAUTIL_USE_POSIX_ADVANCED_REALTIME
80 
81 #define PaUtilClockId clockid_t
82 
83 #else
84 
85 #define PaUtilClockId int /* dummy type */
86 
87 #endif
88 
92 PaUtilClockId PaPthreadUtil_NegotiateCondAttrClock( pthread_condattr_t *cattr );
93 
99 int PaPthreadUtil_GetTime( PaUtilClockId clockId, struct timespec *ts );
100 
101 #ifdef __cplusplus
102 }
103 #endif /* __cplusplus */
104 #endif
PaUtilClockId PaPthreadUtil_NegotiateCondAttrClock(pthread_condattr_t *cattr)
Definition: pa_pthread_util.c:49
int PaPthreadUtil_GetTime(PaUtilClockId clockId, struct timespec *ts)
Definition: pa_pthread_util.c:85
#define PaUtilClockId
Definition: pa_pthread_util.h:85