113187Smchung/* Threads compatibility routines for libgcc2. */ 213187Smchung/* Compile this one with gcc. */ 313187Smchung/* Copyright (C) 1997-2015 Free Software Foundation, Inc. 413187Smchung 513187SmchungThis file is part of GCC. 613187Smchung 713187SmchungGCC is free software; you can redistribute it and/or modify it under 813187Smchungthe terms of the GNU General Public License as published by the Free 913187SmchungSoftware Foundation; either version 3, or (at your option) any later 1013187Smchungversion. 1113187Smchung 1213187SmchungGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1313187SmchungWARRANTY; without even the implied warranty of MERCHANTABILITY or 1413187SmchungFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1513187Smchungfor more details. 1613187Smchung 1713187SmchungUnder Section 7 of GPL version 3, you are granted additional 1813187Smchungpermissions described in the GCC Runtime Library Exception, version 1913187Smchung3.1, as published by the Free Software Foundation. 2013187Smchung 2113187SmchungYou should have received a copy of the GNU General Public License and 2213187Smchunga copy of the GCC Runtime Library Exception along with this program; 2313187Smchungsee the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2413187Smchung<http://www.gnu.org/licenses/>. */ 2513187Smchung 2613187Smchung#ifndef GCC_GTHR_H 2713187Smchung#define GCC_GTHR_H 2813187Smchung 2913187Smchung#ifndef HIDE_EXPORTS 3013187Smchung#pragma GCC visibility push(default) 3113187Smchung#endif 3213187Smchung 3313187Smchung/* If this file is compiled with threads support, it must 3413187Smchung #define __GTHREADS 1 3513187Smchung to indicate that threads support is present. Also it has define 3613187Smchung function 3713187Smchung int __gthread_active_p () 3813187Smchung that returns 1 if thread system is active, 0 if not. 3913187Smchung 4013187Smchung The threads interface must define the following types: 4113187Smchung __gthread_key_t 4213187Smchung __gthread_once_t 4314198Sbchristi __gthread_mutex_t 4413187Smchung __gthread_recursive_mutex_t 4513187Smchung 4613187Smchung The threads interface must define the following macros: 4713187Smchung 4813187Smchung __GTHREAD_ONCE_INIT 4913187Smchung to initialize __gthread_once_t 5013187Smchung __GTHREAD_MUTEX_INIT 5113187Smchung to initialize __gthread_mutex_t to get a fast 5213187Smchung non-recursive mutex. 5313187Smchung __GTHREAD_MUTEX_INIT_FUNCTION 5413187Smchung to initialize __gthread_mutex_t to get a fast 5513187Smchung non-recursive mutex. 5613187Smchung Define this to a function which looks like this: 5713187Smchung void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *) 5813187Smchung Some systems can't initialize a mutex without a 5913187Smchung function call. Don't define __GTHREAD_MUTEX_INIT in this case. 6013187Smchung __GTHREAD_RECURSIVE_MUTEX_INIT 6113187Smchung __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION 6213187Smchung as above, but for a recursive mutex. 6313187Smchung 6413187Smchung The threads interface must define the following static functions: 6513187Smchung 6613187Smchung int __gthread_once (__gthread_once_t *once, void (*func) ()) 6713187Smchung 6813187Smchung int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *)) 6913187Smchung int __gthread_key_delete (__gthread_key_t key) 7013187Smchung 7113187Smchung void *__gthread_getspecific (__gthread_key_t key) 7213187Smchung int __gthread_setspecific (__gthread_key_t key, const void *ptr) 7313187Smchung 7416015Smchung int __gthread_mutex_destroy (__gthread_mutex_t *mutex); 7513187Smchung int __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex); 7613187Smchung 7713187Smchung int __gthread_mutex_lock (__gthread_mutex_t *mutex); 7813187Smchung int __gthread_mutex_trylock (__gthread_mutex_t *mutex); 7913187Smchung int __gthread_mutex_unlock (__gthread_mutex_t *mutex); 8013187Smchung 8113187Smchung int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex); 8213187Smchung int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex); 8313187Smchung int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex); 8413187Smchung 8513187Smchung The following are supported in POSIX threads only. They are required to 8613187Smchung fix a deadlock in static initialization inside libsupc++. The header file 8713187Smchung gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra 8813187Smchung features are supported. 8913187Smchung 9013187Smchung Types: 9113187Smchung __gthread_cond_t 9213187Smchung 9313187Smchung Macros: 9413187Smchung __GTHREAD_COND_INIT 9513187Smchung __GTHREAD_COND_INIT_FUNCTION 9613187Smchung 9713187Smchung Interface: 9813187Smchung int __gthread_cond_broadcast (__gthread_cond_t *cond); 9913187Smchung int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex); 10013187Smchung int __gthread_cond_wait_recursive (__gthread_cond_t *cond, 10113187Smchung __gthread_recursive_mutex_t *mutex); 10213187Smchung 10316015Smchung All functions returning int should return zero on success or the error 10416015Smchung number. If the operation is not supported, -1 is returned. 10516015Smchung 10616015Smchung If the following are also defined, you should 10713187Smchung #define __GTHREADS_CXX0X 1 10816015Smchung to enable the c++0x thread library. 10913187Smchung 11013187Smchung Types: 11113187Smchung __gthread_t 11213187Smchung __gthread_time_t 11313187Smchung 11413187Smchung Interface: 11513187Smchung int __gthread_create (__gthread_t *thread, void *(*func) (void*), 11613187Smchung void *args); 11713187Smchung int __gthread_join (__gthread_t thread, void **value_ptr); 11813187Smchung int __gthread_detach (__gthread_t thread); 11913187Smchung int __gthread_equal (__gthread_t t1, __gthread_t t2); 12013187Smchung __gthread_t __gthread_self (void); 12113187Smchung int __gthread_yield (void); 12213187Smchung 12313187Smchung int __gthread_mutex_timedlock (__gthread_mutex_t *m, 12413187Smchung const __gthread_time_t *abs_timeout); 12513187Smchung int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *m, 12613187Smchung const __gthread_time_t *abs_time); 12713187Smchung 12813187Smchung int __gthread_cond_signal (__gthread_cond_t *cond); 12913187Smchung int __gthread_cond_timedwait (__gthread_cond_t *cond, 13013187Smchung __gthread_mutex_t *mutex, 13113187Smchung const __gthread_time_t *abs_timeout); 13213187Smchung 13313187Smchung*/ 13413187Smchung 13513187Smchung#if SUPPORTS_WEAK 13616015Smchung/* The pe-coff weak support isn't fully compatible to ELF's weak. 13716015Smchung For static libraries it might would work, but as we need to deal 13813187Smchung with shared versions too, we disable it for mingw-targets. */ 13913187Smchung#ifdef __MINGW32__ 14016015Smchung#undef GTHREAD_USE_WEAK 14116015Smchung#define GTHREAD_USE_WEAK 0 14216015Smchung#endif 14316015Smchung 14413187Smchung#ifndef GTHREAD_USE_WEAK 14516015Smchung#define GTHREAD_USE_WEAK 1 14613187Smchung#endif 14713187Smchung#endif 14813187Smchung#include "gthr-default.h" 14913187Smchung 15013187Smchung#ifndef HIDE_EXPORTS 15113187Smchung#pragma GCC visibility pop 15213187Smchung#endif 15313187Smchung 15413187Smchung#endif /* ! GCC_GTHR_H */ 15513187Smchung