190075Sobrien/* Threads compatibility routines for libgcc2.  */
250397Sobrien/* Compile this one with gcc.  */
3169689Skan/* Copyright (C) 1997, 1998, 2004 Free Software Foundation, Inc.
450397Sobrien
590075SobrienThis file is part of GCC.
650397Sobrien
790075SobrienGCC is free software; you can redistribute it and/or modify it under
890075Sobrienthe terms of the GNU General Public License as published by the Free
990075SobrienSoftware Foundation; either version 2, or (at your option) any later
1090075Sobrienversion.
1150397Sobrien
1290075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1390075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or
1490075SobrienFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1590075Sobrienfor more details.
1650397Sobrien
1750397SobrienYou should have received a copy of the GNU General Public License
1890075Sobrienalong with GCC; see the file COPYING.  If not, write to the Free
19169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20169689Skan02110-1301, USA.  */
2150397Sobrien
2250397Sobrien/* As a special exception, if you link this library with other files,
2350397Sobrien   some of which are compiled with GCC, to produce an executable,
2450397Sobrien   this library does not by itself cause the resulting executable
2550397Sobrien   to be covered by the GNU General Public License.
2650397Sobrien   This exception does not however invalidate any other reasons why
2750397Sobrien   the executable file might be covered by the GNU General Public License.  */
2850397Sobrien
2990075Sobrien#ifndef GCC_GTHR_H
3090075Sobrien#define GCC_GTHR_H
3150397Sobrien
32169689Skan#ifndef HIDE_EXPORTS
33169689Skan#pragma GCC visibility push(default)
34169689Skan#endif
35169689Skan
3650397Sobrien/* If this file is compiled with threads support, it must
3750397Sobrien       #define __GTHREADS 1
3850397Sobrien   to indicate that threads support is present.  Also it has define
39117395Skan   function
4050397Sobrien     int __gthread_active_p ()
4150397Sobrien   that returns 1 if thread system is active, 0 if not.
4250397Sobrien
4350397Sobrien   The threads interface must define the following types:
4450397Sobrien     __gthread_key_t
4550397Sobrien     __gthread_once_t
4650397Sobrien     __gthread_mutex_t
47169689Skan     __gthread_recursive_mutex_t
4850397Sobrien
4950397Sobrien   The threads interface must define the following macros:
5050397Sobrien
5150397Sobrien     __GTHREAD_ONCE_INIT
5250397Sobrien     		to initialize __gthread_once_t
5350397Sobrien     __GTHREAD_MUTEX_INIT
5450397Sobrien     		to initialize __gthread_mutex_t to get a fast
5550397Sobrien		non-recursive mutex.
5652284Sobrien     __GTHREAD_MUTEX_INIT_FUNCTION
5790075Sobrien     		some systems can't initialize a mutex without a
5852284Sobrien		function call.  On such systems, define this to a
5952284Sobrien		function which looks like this:
6052284Sobrien		  void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
6152284Sobrien		Don't define __GTHREAD_MUTEX_INIT in this case
62169689Skan     __GTHREAD_RECURSIVE_MUTEX_INIT
63169689Skan     __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
64169689Skan     		as above, but for a recursive mutex.
6550397Sobrien
6650397Sobrien   The threads interface must define the following static functions:
6750397Sobrien
6850397Sobrien     int __gthread_once (__gthread_once_t *once, void (*func) ())
6950397Sobrien
7050397Sobrien     int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
7150397Sobrien     int __gthread_key_delete (__gthread_key_t key)
7250397Sobrien
7350397Sobrien     void *__gthread_getspecific (__gthread_key_t key)
7450397Sobrien     int __gthread_setspecific (__gthread_key_t key, const void *ptr)
7550397Sobrien
7650397Sobrien     int __gthread_mutex_lock (__gthread_mutex_t *mutex);
7750397Sobrien     int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
7850397Sobrien     int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
7950397Sobrien
80169689Skan     int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex);
81169689Skan     int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex);
82169689Skan     int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex);
83169689Skan
8450397Sobrien   All functions returning int should return zero on success or the error
8550397Sobrien   number.  If the operation is not supported, -1 is returned.
8650397Sobrien
8750397Sobrien   Currently supported threads packages are
88169689Skan     TPF threads with -D__tpf__
89169689Skan     POSIX/Unix98 threads with -D_PTHREADS
90169689Skan     POSIX/Unix95 threads with -D_PTHREADS95
9150397Sobrien     DCE threads with -D_DCE_THREADS
9250397Sobrien     Solaris/UI threads with -D_SOLARIS_THREADS
9350397Sobrien*/
9450397Sobrien
9590075Sobrien/* Check first for thread specific defines.  */
96169689Skan#if defined (__tpf__)
97169689Skan#include "gthr-tpf.h"
98169689Skan#elif _PTHREADS
9950397Sobrien#include "gthr-posix.h"
100169689Skan#elif _PTHREADS95
101169689Skan#include "gthr-posix95.h"
10250397Sobrien#elif _DCE_THREADS
10350397Sobrien#include "gthr-dce.h"
10450397Sobrien#elif _SOLARIS_THREADS
10550397Sobrien#include "gthr-solaris.h"
10650397Sobrien
10790075Sobrien/* Include GTHREAD_FILE if one is defined.  */
10850397Sobrien#elif defined(HAVE_GTHR_DEFAULT)
10950397Sobrien#if SUPPORTS_WEAK
11050397Sobrien#ifndef GTHREAD_USE_WEAK
11150397Sobrien#define GTHREAD_USE_WEAK 1
11250397Sobrien#endif
11350397Sobrien#endif
11450397Sobrien#include "gthr-default.h"
11550397Sobrien
11690075Sobrien/* Fallback to single thread definitions.  */
11750397Sobrien#else
11850397Sobrien#include "gthr-single.h"
11950397Sobrien#endif
12050397Sobrien
121169689Skan#ifndef HIDE_EXPORTS
122169689Skan#pragma GCC visibility pop
123169689Skan#endif
124169689Skan
12590075Sobrien#endif /* ! GCC_GTHR_H */
126