|
| 1 | +/* Copyright (C) 1997-2023 Free Software Foundation, Inc. |
| 2 | +
|
| 3 | +This file is part of GCC. |
| 4 | +
|
| 5 | +GCC is free software; you can redistribute it and/or modify it under |
| 6 | +the terms of the GNU General Public License as published by the Free |
| 7 | +Software Foundation; either version 3, or (at your option) any later |
| 8 | +version. |
| 9 | +
|
| 10 | +GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | +for more details. |
| 14 | +
|
| 15 | +Under Section 7 of GPL version 3, you are granted additional |
| 16 | +permissions described in the GCC Runtime Library Exception, version |
| 17 | +3.1, as published by the Free Software Foundation. |
| 18 | +
|
| 19 | +You should have received a copy of the GNU General Public License and |
| 20 | +a copy of the GCC Runtime Library Exception along with this program; |
| 21 | +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 22 | +<http://www.gnu.org/licenses/>. */ |
| 23 | + |
| 24 | +/* gthr.h API implementation in terms of ISO C11 threads.h */ |
| 25 | + |
| 26 | +#ifndef _GLIBCXX_GCC_GTHR_C11_H |
| 27 | +#define _GLIBCXX_GCC_GTHR_C11_H |
| 28 | + |
| 29 | +#define __GTHREADS 1 |
| 30 | +#define __GTHREADS_CXX0X 1 |
| 31 | +#define __GTHREAD_ONCE_INIT ONCE_FLAG_INIT |
| 32 | + |
| 33 | +#define _GTHREAD_USE_MUTEX_TIMEDLOCK 1 |
| 34 | + |
| 35 | +#undef __GTHREAD_MUTEX_INIT |
| 36 | +#define _GTHREAD_USE_MUTEX_INIT_FUNC 1 |
| 37 | +#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function |
| 38 | + |
| 39 | +#undef __GTHREAD_RECURSIVE_MUTEX_INIT |
| 40 | +#define _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC 1 |
| 41 | +#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function |
| 42 | + |
| 43 | +#define __GTHREAD_HAS_COND 1 |
| 44 | +#undef __GTHREAD_COND_INIT |
| 45 | +#define _GTHREAD_USE_COND_INIT_FUNC 1 |
| 46 | +#define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function |
| 47 | + |
| 48 | +#define _GLIBCXX_THREAD_ABI_COMPAT 1 |
| 49 | +#define _GLIBCXX_HAS_GTHREADS 1 |
| 50 | +#define _GLIBCXX_USE_THRD_SLEEP 1 |
| 51 | + |
| 52 | +#include <threads.h> |
| 53 | +#include <time.h> |
| 54 | + |
| 55 | +typedef thrd_t __gthread_t; |
| 56 | +typedef tss_t __gthread_key_t; |
| 57 | +typedef once_flag __gthread_once_t; |
| 58 | +typedef mtx_t __gthread_mutex_t; |
| 59 | +typedef mtx_t __gthread_recursive_mutex_t; |
| 60 | +typedef cnd_t __gthread_cond_t; |
| 61 | +typedef struct timespec __gthread_time_t; |
| 62 | + |
| 63 | +static inline int __gthread_active_p(void) |
| 64 | +{ |
| 65 | + return 1; |
| 66 | +} |
| 67 | + |
| 68 | +static inline int |
| 69 | +__gthread_create (__gthread_t *__threadid, void *(*__func) (void*), |
| 70 | + void *__args) |
| 71 | +{ |
| 72 | + return thrd_create(__threadid, (thrd_start_t)__func, __args) != thrd_success; |
| 73 | +} |
| 74 | + |
| 75 | +static inline int |
| 76 | +__gthread_join (__gthread_t __threadid, void **__value_ptr) |
| 77 | +{ |
| 78 | + return thrd_join(__threadid, (int *)__value_ptr) != thrd_success; |
| 79 | +} |
| 80 | + |
| 81 | +static inline int |
| 82 | +__gthread_detach (__gthread_t __threadid) |
| 83 | +{ |
| 84 | + return thrd_detach(__threadid) != thrd_success; |
| 85 | +} |
| 86 | + |
| 87 | +static inline int |
| 88 | +__gthread_equal (__gthread_t __t1, __gthread_t __t2) |
| 89 | +{ |
| 90 | + return thrd_equal(__t1, __t2); |
| 91 | +} |
| 92 | + |
| 93 | +static inline __gthread_t |
| 94 | +__gthread_self (void) |
| 95 | +{ |
| 96 | + return thrd_current(); |
| 97 | +} |
| 98 | + |
| 99 | +static inline int |
| 100 | +__gthread_yield (void) |
| 101 | +{ |
| 102 | + (void)thrd_yield(); |
| 103 | + return 0; |
| 104 | +} |
| 105 | + |
| 106 | +static inline int |
| 107 | +__gthread_once (__gthread_once_t *__once, void (*__func) (void)) |
| 108 | +{ |
| 109 | + call_once(__once, __func); |
| 110 | + return 0; |
| 111 | +} |
| 112 | + |
| 113 | +static inline int |
| 114 | +__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *)) |
| 115 | +{ |
| 116 | + return tss_create(__key, __dtor) != thrd_success; |
| 117 | +} |
| 118 | + |
| 119 | +static inline int |
| 120 | +__gthread_key_delete (__gthread_key_t __key) |
| 121 | +{ |
| 122 | + tss_delete(__key); |
| 123 | + return 0; |
| 124 | +} |
| 125 | + |
| 126 | +static inline void * |
| 127 | +__gthread_getspecific (__gthread_key_t __key) |
| 128 | +{ |
| 129 | + return tss_get(__key); |
| 130 | +} |
| 131 | + |
| 132 | +static inline int |
| 133 | +__gthread_setspecific (__gthread_key_t __key, const void *__ptr) |
| 134 | +{ |
| 135 | + return tss_set(__key, (void *)__ptr) != thrd_success; |
| 136 | +} |
| 137 | + |
| 138 | +static inline void |
| 139 | +__gthread_mutex_init_function (__gthread_mutex_t *__mutex) |
| 140 | +{ |
| 141 | + (void)mtx_init(__mutex, mtx_plain); |
| 142 | +} |
| 143 | + |
| 144 | +static inline int |
| 145 | +__gthread_mutex_destroy (__gthread_mutex_t *__mutex) |
| 146 | +{ |
| 147 | + mtx_destroy(__mutex); |
| 148 | + return 0; |
| 149 | +} |
| 150 | + |
| 151 | +static inline int |
| 152 | +__gthread_mutex_lock (__gthread_mutex_t *__mutex) |
| 153 | +{ |
| 154 | + return mtx_lock(__mutex) != thrd_success; |
| 155 | +} |
| 156 | + |
| 157 | +static inline int |
| 158 | +__gthread_mutex_trylock (__gthread_mutex_t *__mutex) |
| 159 | +{ |
| 160 | + return mtx_trylock(__mutex) != thrd_success; |
| 161 | +} |
| 162 | + |
| 163 | +static inline int |
| 164 | +__gthread_mutex_timedlock (__gthread_mutex_t *__mutex, |
| 165 | + const __gthread_time_t *__abs_timeout) |
| 166 | +{ |
| 167 | + return mtx_timedlock(__mutex, __abs_timeout) != thrd_success; |
| 168 | +} |
| 169 | + |
| 170 | +static inline int |
| 171 | +__gthread_mutex_unlock (__gthread_mutex_t *__mutex) |
| 172 | +{ |
| 173 | + return mtx_unlock(__mutex) != thrd_success; |
| 174 | +} |
| 175 | + |
| 176 | +static inline int |
| 177 | +__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex) |
| 178 | +{ |
| 179 | + return mtx_init(__mutex, mtx_recursive) != thrd_success; |
| 180 | +} |
| 181 | + |
| 182 | +static inline int |
| 183 | +__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex) |
| 184 | +{ |
| 185 | + return mtx_lock(__mutex) != thrd_success; |
| 186 | +} |
| 187 | + |
| 188 | +static inline int |
| 189 | +__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex) |
| 190 | +{ |
| 191 | + return mtx_trylock(__mutex) != thrd_success; |
| 192 | +} |
| 193 | + |
| 194 | +static inline int |
| 195 | +__gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex, |
| 196 | + const __gthread_time_t *__abs_timeout) |
| 197 | +{ |
| 198 | + return __gthread_mutex_timedlock (__mutex, __abs_timeout); |
| 199 | +} |
| 200 | + |
| 201 | +static inline int |
| 202 | +__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) |
| 203 | +{ |
| 204 | + return __gthread_mutex_unlock (__mutex); |
| 205 | +} |
| 206 | + |
| 207 | +static inline int |
| 208 | +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex) |
| 209 | +{ |
| 210 | + return __gthread_mutex_destroy (__mutex); |
| 211 | +} |
| 212 | + |
| 213 | +static inline void |
| 214 | +__gthread_cond_init_function (__gthread_cond_t *__cond) |
| 215 | +{ |
| 216 | + (void)cnd_init(__cond); |
| 217 | +} |
| 218 | + |
| 219 | +static inline int |
| 220 | +__gthread_cond_broadcast (__gthread_cond_t *__cond) |
| 221 | +{ |
| 222 | + return cnd_broadcast(__cond) != thrd_success; |
| 223 | +} |
| 224 | + |
| 225 | +static inline int |
| 226 | +__gthread_cond_signal (__gthread_cond_t *__cond) |
| 227 | +{ |
| 228 | + return cnd_signal(__cond) != thrd_success; |
| 229 | +} |
| 230 | + |
| 231 | +static inline int |
| 232 | +__gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex) |
| 233 | +{ |
| 234 | + return cnd_wait(__cond, __mutex) != thrd_success; |
| 235 | +} |
| 236 | + |
| 237 | +static inline int |
| 238 | +__gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex, |
| 239 | + const __gthread_time_t *__abs_timeout) |
| 240 | +{ |
| 241 | + return cnd_timedwait(__cond, __mutex, __abs_timeout) != thrd_success; |
| 242 | +} |
| 243 | + |
| 244 | +static inline int |
| 245 | +__gthread_cond_wait_recursive (__gthread_cond_t *__cond, |
| 246 | + __gthread_recursive_mutex_t *__mutex) |
| 247 | +{ |
| 248 | + return __gthread_cond_wait (__cond, __mutex); |
| 249 | +} |
| 250 | + |
| 251 | +static inline int |
| 252 | +__gthread_cond_destroy (__gthread_cond_t* __cond) |
| 253 | +{ |
| 254 | + cnd_destroy(__cond); |
| 255 | + return 0; |
| 256 | +} |
| 257 | + |
| 258 | +#endif /* ! _GLIBCXX_GCC_GTHR_C11_H */ |
0 commit comments