1/*
2 Copyright (c) 2011-2016 mingw-w64 project
3
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files (the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 DEALINGS IN THE SOFTWARE.
21*/
22
23/*
24 * Parts of this library are derived by:
25 *
26 * Posix Threads library for Microsoft Windows
27 *
28 * Use at own risk, there is no implied warranty to this code.
29 * It uses undocumented features of Microsoft Windows that can change
30 * at any time in the future.
31 *
32 * (C) 2010 Lockless Inc.
33 * All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without modification,
36 * are permitted provided that the following conditions are met:
37 *
38 *
39 * * Redistributions of source code must retain the above copyright notice,
40 * this list of conditions and the following disclaimer.
41 * * Redistributions in binary form must reproduce the above copyright notice,
42 * this list of conditions and the following disclaimer in the documentation
43 * and/or other materials provided with the distribution.
44 * * Neither the name of Lockless Inc. nor the names of its contributors may be
45 * used to endorse or promote products derived from this software without
46 * specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AN
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
50 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
51 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
52 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
53 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
55 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
56 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
57 * OF THE POSSIBILITY OF SUCH DAMAGE.
58 */
59
60#ifndef WIN_PTHREADS_PTHREAD_COMPAT_H
61#define WIN_PTHREADS_PTHREAD_COMPAT_H
62
63#if defined(__cplusplus) && __cplusplus >= 201103L
64#define WINPTHREADS_STATIC_ASSERT(expr, msg) static_assert ((expr), msg)
65#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
66#define WINPTHREADS_STATIC_ASSERT(expr, msg) static_assert ((expr), msg)
67#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
68#define WINPTHREADS_STATIC_ASSERT(expr, msg) _Static_assert ((expr), msg)
69#else
70#define WINPTHREADS_STATIC_ASSERT(expr, msg) extern int winpthreads_static_assert[((expr) ? 1 : -1)]
71#endif
72
73#if defined(_USE_32BIT_TIME_T)
74#define WINPTHREADS_TIME_BITS 32
75#else
76#define WINPTHREADS_TIME_BITS 64
77#endif
78
79#ifndef WINPTHREAD_API
80 /**
81 * Allow `WINPTHREAD_STATIC` to override `WINPTHREADS_USE_DLLIMPORT`.
82 */
83# if defined(WINPTHREADS_USE_DLLIMPORT) && !defined(WINPTHREAD_STATIC)
84# define WINPTHREAD_API __declspec(dllimport)
85# else
86# define WINPTHREAD_API
87# endif
88#endif
89
90#ifndef __clockid_t_defined
91typedef int clockid_t;
92#define __clockid_t_defined 1
93#endif /* __clockid_t_defined */
94
95#ifndef _MODE_T_
96#define _MODE_T_
97typedef unsigned short mode_t;
98#endif
99
100/* Error-codes. */
101#ifndef ETIMEDOUT
102#define ETIMEDOUT 138
103#endif
104#ifndef ENOTSUP
105#define ENOTSUP 129
106#endif
107#ifndef EWOULDBLOCK
108#define EWOULDBLOCK 140
109#endif
110
111#ifdef __GNUC__
112
113#define WINPTHREADS_INLINE __inline__
114#define WINPTHREADS_ALWAYS_INLINE __inline__ __attribute__((__always_inline__))
115#define WINPTHREADS_ATTRIBUTE(X) __attribute__(X)
116#define WINPTHREADS_SECTION(X) __section__(X)
117
118#elif _MSC_VER
119
120/**
121 * If package which includes this header file is using autoconf and calls
122 * AC_TYPE_PID_T macro, the check for pid_t will fail and it will define pid_t
123 * as a macro in config.h - this eventually results in compilation error.
124 *
125 * Luckily, it defines it to the same base type, so we can simply undefine it.
126 */
127#ifdef _WIN64
128#ifdef pid_t
129WINPTHREADS_STATIC_ASSERT (sizeof (pid_t) == sizeof(__int64), "pid_t is defined as a macro with mismatching base type");
130#undef pid_t
131#endif
132typedef __int64 pid_t;
133#else
134#ifdef pid_t
135WINPTHREADS_STATIC_ASSERT (sizeof (pid_t) == sizeof(int), "pid_t is defined as a macro with mismatching base type");
136#undef pid_t
137#endif
138typedef int pid_t;
139#endif
140
141#define WINPTHREADS_INLINE __inline
142#define WINPTHREADS_ALWAYS_INLINE __inline __forceinline
143#define WINPTHREADS_ATTRIBUTE(X) __declspec X
144#define WINPTHREADS_SECTION(X) allocate(X)
145
146#endif
147
148#ifndef WINPTHREAD_CLOCK_DECL
149# ifdef __cplusplus
150# define WINPTHREAD_CLOCK_DECL WINPTHREADS_ALWAYS_INLINE
151# else
152# define WINPTHREAD_CLOCK_DECL static WINPTHREADS_ALWAYS_INLINE
153# endif
154#endif
155
156#ifndef WINPTHREAD_COND_DECL
157# ifdef __cplusplus
158# define WINPTHREAD_COND_DECL WINPTHREADS_ALWAYS_INLINE
159# else
160# define WINPTHREAD_COND_DECL static WINPTHREADS_ALWAYS_INLINE
161# endif
162#endif
163
164#ifndef WINPTHREAD_MUTEX_DECL
165# ifdef __cplusplus
166# define WINPTHREAD_MUTEX_DECL WINPTHREADS_ALWAYS_INLINE
167# else
168# define WINPTHREAD_MUTEX_DECL static WINPTHREADS_ALWAYS_INLINE
169# endif
170#endif
171
172#ifndef WINPTHREAD_NANOSLEEP_DECL
173# ifdef __cplusplus
174# define WINPTHREAD_NANOSLEEP_DECL WINPTHREADS_ALWAYS_INLINE
175# else
176# define WINPTHREAD_NANOSLEEP_DECL static WINPTHREADS_ALWAYS_INLINE
177# endif
178#endif
179
180#ifndef WINPTHREAD_RWLOCK_DECL
181# ifdef __cplusplus
182# define WINPTHREAD_RWLOCK_DECL WINPTHREADS_ALWAYS_INLINE
183# else
184# define WINPTHREAD_RWLOCK_DECL static WINPTHREADS_ALWAYS_INLINE
185# endif
186#endif
187
188#ifndef WINPTHREAD_SEM_DECL
189# ifdef __cplusplus
190# define WINPTHREAD_SEM_DECL WINPTHREADS_ALWAYS_INLINE
191# else
192# define WINPTHREAD_SEM_DECL static WINPTHREADS_ALWAYS_INLINE
193# endif
194#endif
195
196#ifndef WINPTHREAD_THREAD_DECL
197# ifdef __cplusplus
198# define WINPTHREAD_THREAD_DECL WINPTHREADS_ALWAYS_INLINE
199# else
200# define WINPTHREAD_THREAD_DECL static WINPTHREADS_ALWAYS_INLINE
201# endif
202#endif
203
204#endif