This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: MT-safe exception and thread library
- To: hjl at lucon dot org (H.J. Lu)
- Subject: Re: MT-safe exception and thread library
- From: Teemu Torma <tot at labs dot trema dot com>
- Date: Wed, 17 Dec 1997 17:48:44 +0100
- cc: egcs at cygnus dot com, libc-linux at gnu dot org (GNU C Library)
- Reply-To: egcs at cygnus dot com
Does the following make any sense? It should combine the existing
functionality to allow compiling with -D_PTHREADS etc, or if not
defined, uses the --enable-threads and weak symbols.
I have only tested these on Solaris 2.5, with solaris and posix
threads. It seems to work. The idea is to have a function
__gthread_active_p to see if threads have actually been linked in or
not.
One dummy thing in Solaris 2.5 though. libc defines all solaris
thread symbols (thr_*) as dummy functions. thr_keycreate tries to
detect if a new key was actually created, and if not, return -1 so
that libgcc can fall back to static eh context.
I think someone should create all missing thread packages here,
since objc uses the same thread package names. Also objc/thr-decosf1
seems to be same as DCE threads, so one of the names should be
changed.
Teemu
1997-12-17 Teemu Torma <tot@trema.com>
* Makefile.in (LIBGCC2_CFLAGS): Added -DGTHREAD_FILE
* gthr.h: New file.
* gthr-single.h: New file.
* gthr-posix.h: New file.
* gthr-solaris.h: New file.
* gthr-dce.h: New file.
* libgcc-thr.h: Removed.
* frame.c: Include gthr.h instead of libgcc-thr.h.
* libgcc2.c: Include gthr.h instead of libgcc-thr.h.
(eh_context_initialize): If __gthread_once fails, use static eh
context.
Index: Makefile.in
===================================================================
RCS file: /trema/cvs/gnu/egcs/gcc/Makefile.in,v
retrieving revision 1.12
diff -c -c -3 -p -r1.12 Makefile.in
*** Makefile.in 1997/12/17 09:37:13 1.12
--- Makefile.in 1997/12/17 11:27:25
*************** LIBGCC2 = libgcc2.a
*** 281,287 ****
# -fexceptions is necessary for eh.o now that the exceptions are
# the default for g++ only.
LIBGCC2_DEBUG_CFLAGS = -g1
! LIBGCC2_CFLAGS = -O2 $(LIBGCC2_INCLUDES) $(GCC_CFLAGS) $(TARGET_LIBGCC2_CFLAGS) $(LIBGCC2_DEBUG_CFLAGS) -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -fexceptions @inhibit_libc@
# Additional options to use when compiling libgcc2.a.
# Some targets override this to -Iinclude
--- 281,287 ----
# -fexceptions is necessary for eh.o now that the exceptions are
# the default for g++ only.
LIBGCC2_DEBUG_CFLAGS = -g1
! LIBGCC2_CFLAGS = -O2 $(LIBGCC2_INCLUDES) $(GCC_CFLAGS) $(TARGET_LIBGCC2_CFLAGS) $(LIBGCC2_DEBUG_CFLAGS) -DGTHREAD_FILE=\"gthr-$(GCC_THREAD_FILE).h\" -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -fexceptions @inhibit_libc@
# Additional options to use when compiling libgcc2.a.
# Some targets override this to -Iinclude
Index: frame.c
===================================================================
RCS file: /trema/cvs/gnu/egcs/gcc/frame.c,v
retrieving revision 1.13
diff -c -c -3 -p -r1.13 frame.c
*** frame.c 1997/12/17 09:37:16 1.13
--- frame.c 1997/12/17 11:08:52
*************** Boston, MA 02111-1307, USA. */
*** 39,45 ****
#include "dwarf2.h"
#include <stddef.h>
#include "frame.h"
! #include "libgcc-thr.h"
#ifdef __GTHREAD_MUTEX_INIT
static __gthread_mutex_t object_mutex = __GTHREAD_MUTEX_INIT;
--- 39,45 ----
#include "dwarf2.h"
#include <stddef.h>
#include "frame.h"
! #include "gthr.h"
#ifdef __GTHREAD_MUTEX_INIT
static __gthread_mutex_t object_mutex = __GTHREAD_MUTEX_INIT;
Index: gthr-dce.h
===================================================================
RCS file: gthr-dce.h
diff -N gthr-dce.h
*** /dev/null Wed Dec 17 17:25:43 1997
--- gthr-dce.h Wed Dec 17 17:23:13 1997
***************
*** 0 ****
--- 1,143 ----
+
+ /* Compile this one with gcc. */
+ /* Copyright (C) 1997 Free Software Foundation, Inc.
+
+ This file is part of GNU CC.
+
+ GNU CC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU CC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU CC; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ /* As a special exception, if you link this library with other files,
+ some of which are compiled with GCC, to produce an executable,
+ this library does not by itself cause the resulting executable
+ to be covered by the GNU General Public License.
+ This exception does not however invalidate any other reasons why
+ the executable file might be covered by the GNU General Public License. */
+
+ #ifndef __gthr_dce_h
+ #define __gthr_dce_h
+
+ /* DCE threads interface.
+ DCE threads are based on POSIX threads draft 4, and many things
+ have changed since then. */
+
+ #define __GTHREADS 1
+
+ #include <pthread.h>
+
+ typedef pthread_key_t __gthread_key_t;
+ typedef pthread_once_t __gthread_once_t;
+ typedef pthread_mutex_t __gthread_mutex_t;
+
+ #define __GTHREAD_ONCE_INIT pthread_once_init
+ /* Howto define __GTHREAD_MUTEX_INIT? */
+
+ #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
+
+ #pragma weak pthread_once
+ #pragma weak pthread_once_init
+ #pragma weak pthread_key_create
+ #pragma weak pthread_key_delete
+ #pragma weak pthread_getspecific
+ #pragma weak pthread_setspecific
+ #pragma weak pthread_create
+
+ #pragma weak pthread_mutex_lock
+ #pragma weak pthread_mutex_trylock
+ #pragma weak pthread_mutex_unlock
+
+ static void *__gthread_active_ptr = &pthread_create;
+
+ static inline int
+ __gthread_active_p ()
+ {
+ return __gthread_active_ptr != 0;
+ }
+
+ #else /* not SUPPORTS_WEAK */
+
+ static inline int
+ __gthread_active_p ()
+ {
+ return 1;
+ }
+
+ #endif /* SUPPORTS_WEAK */
+
+ static inline int
+ __gthread_once (__gthread_once_t *once, void (*func) ())
+ {
+ if (__gthread_active_p ())
+ return pthread_once (once, func);
+ else
+ return -1;
+ }
+
+ static inline int
+ __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
+ {
+ return pthread_keycreate (key, dtor);
+ }
+
+ static inline int
+ __gthread_key_delete (__gthread_key_t key)
+ {
+ return pthread_key_delete (key);
+ }
+
+ static inline void *
+ __gthread_getspecific (__gthread_key_t key)
+ {
+ void *ptr;
+ if (pthread_getspecific (key, &ptr) == 0)
+ return ptr;
+ else
+ return 0;
+ }
+
+ static inline int
+ __gthread_setspecific (__gthread_key_t key, const void *ptr)
+ {
+ return pthread_setspecific (key, (void *) ptr);
+ }
+
+ static inline int
+ __gthread_mutex_lock (__gthread_mutex_t *mutex)
+ {
+ if (__gthread_active_p ())
+ return pthread_mutex_lock (mutex);
+ else
+ return 0;
+ }
+
+ static inline int
+ __gthread_mutex_trylock (__gthread_mutex_t *mutex)
+ {
+ if (__gthread_active_p ())
+ return pthread_mutex_trylock (mutex);
+ else
+ return 0;
+ }
+
+ static inline int
+ __gthread_mutex_unlock (__gthread_mutex_t *mutex)
+ {
+ if (__gthread_active_p ())
+ return pthread_mutex_unlock (mutex);
+ else
+ return 0;
+ }
+
+ #endif /* not __gthr_dce_h */
Index: gthr-posix.h
===================================================================
RCS file: gthr-posix.h
diff -N gthr-posix.h
*** /dev/null Wed Dec 17 17:25:43 1997
--- gthr-posix.h Wed Dec 17 17:22:59 1997
***************
*** 0 ****
--- 1,137 ----
+ /* Threads compatibily routines for libgcc2. */
+ /* Compile this one with gcc. */
+ /* Copyright (C) 1997 Free Software Foundation, Inc.
+
+ This file is part of GNU CC.
+
+ GNU CC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU CC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU CC; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ /* As a special exception, if you link this library with other files,
+ some of which are compiled with GCC, to produce an executable,
+ this library does not by itself cause the resulting executable
+ to be covered by the GNU General Public License.
+ This exception does not however invalidate any other reasons why
+ the executable file might be covered by the GNU General Public License. */
+
+ #ifndef __gthr_posix_h
+ #define __gthr_posix_h
+
+ /* POSIX threads specific definitions.
+ Easy, since the interface is just one-to-one mapping. */
+
+ #define __GTHREADS 1
+
+ #include <pthread.h>
+
+ typedef pthread_key_t __gthread_key_t;
+ typedef pthread_once_t __gthread_once_t;
+ typedef pthread_mutex_t __gthread_mutex_t;
+
+ #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
+ #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
+
+ #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
+
+ #pragma weak pthread_once
+ #pragma weak pthread_key_create
+ #pragma weak pthread_key_delete
+ #pragma weak pthread_getspecific
+ #pragma weak pthread_setspecific
+ #pragma weak pthread_create
+
+ #pragma weak pthread_mutex_lock
+ #pragma weak pthread_mutex_trylock
+ #pragma weak pthread_mutex_unlock
+
+ static void *__gthread_active_ptr = &pthread_create;
+
+ static inline int
+ __gthread_active_p ()
+ {
+ return __gthread_active_ptr != 0;
+ }
+
+ #else /* not SUPPORTS_WEAK */
+
+ static inline int
+ __gthread_active_p ()
+ {
+ return 1;
+ }
+
+ #endif /* SUPPORTS_WEAK */
+
+ static inline int
+ __gthread_once (__gthread_once_t *once, void (*func) ())
+ {
+ if (__gthread_active_p ())
+ return pthread_once (once, func);
+ else
+ return -1;
+ }
+
+ static inline int
+ __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
+ {
+ return pthread_key_create (key, dtor);
+ }
+
+ static inline int
+ __gthread_key_delete (__gthread_key_t key)
+ {
+ return pthread_key_delete (key);
+ }
+
+ static inline void *
+ __gthread_getspecific (__gthread_key_t key)
+ {
+ return pthread_getspecific (key);
+ }
+
+ static inline int
+ __gthread_setspecific (__gthread_key_t key, const void *ptr)
+ {
+ return pthread_setspecific (key, ptr);
+ }
+
+ static inline int
+ __gthread_mutex_lock (__gthread_mutex_t *mutex)
+ {
+ if (__gthread_active_p ())
+ return pthread_mutex_lock (mutex);
+ else
+ return 0;
+ }
+
+ static inline int
+ __gthread_mutex_trylock (__gthread_mutex_t *mutex)
+ {
+ if (__gthread_active_p ())
+ return pthread_mutex_trylock (mutex);
+ else
+ return 0;
+ }
+
+ static inline int
+ __gthread_mutex_unlock (__gthread_mutex_t *mutex)
+ {
+ if (__gthread_active_p ())
+ return pthread_mutex_unlock (mutex);
+ else
+ return 0;
+ }
+
+ #endif /* not __gthr_posix_h */
Index: gthr-single.h
===================================================================
RCS file: gthr-single.h
diff -N gthr-single.h
*** /dev/null Wed Dec 17 17:25:43 1997
--- gthr-single.h Wed Dec 17 12:01:59 1997
***************
*** 0 ****
--- 1,62 ----
+ /* Threads compatibily routines for libgcc2. */
+ /* Compile this one with gcc. */
+ /* Copyright (C) 1997 Free Software Foundation, Inc.
+
+ This file is part of GNU CC.
+
+ GNU CC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU CC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU CC; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ /* As a special exception, if you link this library with other files,
+ some of which are compiled with GCC, to produce an executable,
+ this library does not by itself cause the resulting executable
+ to be covered by the GNU General Public License.
+ This exception does not however invalidate any other reasons why
+ the executable file might be covered by the GNU General Public License. */
+
+ #ifndef __gthr_single_h
+ #define __gthr_single_h
+
+ /* Just provide compatibility for mutex handling. */
+
+ typedef int __gthread_mutex_t;
+
+ #define __GTHREAD_MUTEX_INIT 0
+
+ static inline int
+ __gthread_active_p ()
+ {
+ return 0;
+ }
+
+ static inline int
+ __gthread_mutex_lock (__gthread_mutex_t *mutex)
+ {
+ return 0;
+ }
+
+ static inline int
+ __gthread_mutex_trylock (__gthread_mutex_t *mutex)
+ {
+ return 0;
+ }
+
+ static inline int
+ __gthread_mutex_unlock (__gthread_mutex_t *mutex)
+ {
+ return 0;
+ }
+
+ #endif /* not __gthr_single_h */
Index: gthr-solaris.h
===================================================================
RCS file: gthr-solaris.h
diff -N gthr-solaris.h
*** /dev/null Wed Dec 17 17:25:43 1997
--- gthr-solaris.h Wed Dec 17 17:23:08 1997
***************
*** 0 ****
--- 1,172 ----
+ /* Threads compatibily routines for libgcc2. */
+ /* Compile this one with gcc. */
+ /* Copyright (C) 1997 Free Software Foundation, Inc.
+
+ This file is part of GNU CC.
+
+ GNU CC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU CC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU CC; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ /* As a special exception, if you link this library with other files,
+ some of which are compiled with GCC, to produce an executable,
+ this library does not by itself cause the resulting executable
+ to be covered by the GNU General Public License.
+ This exception does not however invalidate any other reasons why
+ the executable file might be covered by the GNU General Public License. */
+
+ #ifndef __gthr_solaris_h
+ #define __gthr_solaris_h
+
+ /* Solaris threads as found in Solaris 2.[456].
+ Actually these are Unix International (UI) threads, but I don't
+ know if anyone else implements these. */
+
+ #define __GTHREADS 1
+
+ #include <thread.h>
+ #include <errno.h>
+
+ typedef thread_key_t __gthread_key_t;
+ typedef struct
+ {
+ mutex_t mutex;
+ int once;
+ } __gthread_once_t;
+ typedef mutex_t __gthread_mutex_t;
+
+ #define __GTHREAD_ONCE_INIT { DEFAULTMUTEX, 0 }
+ #define __GTHREAD_MUTEX_INIT DEFAULTMUTEX
+
+ #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
+
+ #pragma weak thr_keycreate
+ #pragma weak thr_getspecific
+ #pragma weak thr_setspecific
+ #pragma weak thr_create
+
+ #pragma weak mutex_lock
+ #pragma weak mutex_trylock
+ #pragma weak mutex_unlock
+
+ /* This will not actually work in Solaris 2.5, since libc contains
+ dummy symbols of all thr_* routines. */
+
+ static void *__gthread_active_ptr = &thr_create;
+
+ static inline int
+ __gthread_active_p ()
+ {
+ return __gthread_active_ptr != 0;
+ }
+
+ #else /* not SUPPORTS_WEAK */
+
+ static inline int
+ __gthread_active_p ()
+ {
+ return 1;
+ }
+
+ #endif /* SUPPORTS_WEAK */
+
+ static inline int
+ __gthread_once (__gthread_once_t *once, void (*func) ())
+ {
+ if (! __gthread_active_p ())
+ return -1;
+
+ if (once == 0 || func == 0)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (once->once == 0)
+ {
+ if (mutex_lock (&once->mutex) != 0)
+ return -1;
+ if (once->once == 0)
+ {
+ (*func) ();
+ once->once ++;
+ }
+ mutex_unlock (&once->mutex);
+ }
+ return 0;
+ }
+
+ static inline int
+ __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
+ {
+ /* Solaris 2.5 contains thr_* routines no-op in libc, so test if we actually
+ got a reasonable key value, and if not, fail. */
+ *key = -1;
+ if (thr_keycreate (key, dtor) == -1 || *key == -1)
+ return -1;
+ else
+ return 0;
+ }
+
+ static inline int
+ __gthread_key_delete (__gthread_key_t key)
+ {
+ /* Not possible. */
+ return -1;
+ }
+
+ static inline void *
+ __gthread_getspecific (__gthread_key_t key)
+ {
+ void *ptr;
+ if (thr_getspecific (key, &ptr) == 0)
+ return ptr;
+ else
+ return 0;
+ }
+
+ static inline int
+ __gthread_setspecific (__gthread_key_t key, const void *ptr)
+ {
+ return thr_setspecific (key, (void *) ptr);
+ }
+
+ static inline int
+ __gthread_mutex_lock (__gthread_mutex_t *mutex)
+ {
+ if (__gthread_active_p ())
+ return mutex_lock (mutex);
+ else
+ return 0;
+ }
+
+ static inline int
+ __gthread_mutex_trylock (__gthread_mutex_t *mutex)
+ {
+ if (__gthread_active_p ())
+ return mutex_trylock (mutex);
+ else
+ return 0;
+ }
+
+ static inline int
+ __gthread_mutex_unlock (__gthread_mutex_t *mutex)
+ {
+ if (__gthread_active_p ())
+ return mutex_unlock (mutex);
+ else
+ return 0;
+ }
+
+ #endif /* not __gthr_solaris_h */
Index: gthr.h
===================================================================
RCS file: gthr.h
diff -N gthr.h
*** /dev/null Wed Dec 17 17:25:43 1997
--- gthr.h Wed Dec 17 17:22:47 1997
***************
*** 0 ****
--- 1,94 ----
+ /* Threads compatibily routines for libgcc2. */
+ /* Compile this one with gcc. */
+ /* Copyright (C) 1997 Free Software Foundation, Inc.
+
+ This file is part of GNU CC.
+
+ GNU CC is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU CC is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU CC; see the file COPYING. If not, write to
+ the Free Software Foundation, 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+ /* As a special exception, if you link this library with other files,
+ some of which are compiled with GCC, to produce an executable,
+ this library does not by itself cause the resulting executable
+ to be covered by the GNU General Public License.
+ This exception does not however invalidate any other reasons why
+ the executable file might be covered by the GNU General Public License. */
+
+ #ifndef __gthr_h
+ #define __gthr_h
+
+ /* If this file is compiled with threads support, it must
+ #define __GTHREADS 1
+ to indicate that threads support is present. Also it has define
+ function
+ int __gthread_active_p ()
+ that returns 1 if thread system is active, 0 if not.
+
+ The threads interface must define the following types:
+ __gthread_key_t
+ __gthread_once_t
+ __gthread_mutex_t
+
+ The threads interface must define the following macros:
+
+ __GTHREAD_ONCE_INIT
+ to initialize __gthread_once_t
+ __GTHREAD_MUTEX_INIT
+ to initialize __gthread_mutex_t to get a fast
+ non-recursive mutex.
+
+ The threads interface must define the following static functions:
+
+ int __gthread_once (__gthread_once_t *once, void (*func) ())
+
+ int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
+ int __gthread_key_delete (__gthread_key_t key)
+
+ void *__gthread_getspecific (__gthread_key_t key)
+ int __gthread_setspecific (__gthread_key_t key, const void *ptr)
+
+ int __gthread_mutex_lock (__gthread_mutex_t *mutex);
+ int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
+ int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
+
+ All functions returning int should return 0 on success, -1 on error.
+
+ Currently supported threads packages are
+ POSIX threads with -D_PTHREADS
+ DCE threads with -D_DCE_THREADS
+ Solaris/UI threads with -D_SOLARIS_THREADS
+ */
+
+ /* Check first for thread specific defines. */
+ #if _PTHREADS
+ #include "gthr-posix.h"
+ #elif _DCE_THREADS
+ #include "gthr-dce.h"
+ #elif _SOLARIS_THREADS
+ #include "gthr-solaris.h"
+
+ /* Include GTHREAD_FILE if one is defined. */
+ #elif defined (GTHREAD_FILE) && SUPPORTS_WEAK
+ #ifndef GTHREAD_USE_WEAK
+ #define GTHREAD_USE_WEAK 1
+ #endif
+ #include GTHREAD_FILE
+
+ /* Fallback to single thread definitions. */
+ #else
+ #include "gthr-single.h"
+ #endif
+
+ #endif /* not __gthr_h */
Index: libgcc-thr.h
===================================================================
RCS file: libgcc-thr.h
diff -N libgcc-thr.h
*** /tmp/cvsAAAa0047j Wed Dec 17 17:35:18 1997
--- /dev/null Wed Dec 17 17:25:43 1997
***************
*** 1,321 ****
- /* Threads compatibily routines for libgcc2. */
- /* Compile this one with gcc. */
- /* Copyright (C) 1997 Free Software Foundation, Inc.
-
- This file is part of GNU CC.
-
- GNU CC is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- GNU CC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNU CC; see the file COPYING. If not, write to
- the Free Software Foundation, 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
- /* As a special exception, if you link this library with other files,
- some of which are compiled with GCC, to produce an executable,
- this library does not by itself cause the resulting executable
- to be covered by the GNU General Public License.
- This exception does not however invalidate any other reasons why
- the executable file might be covered by the GNU General Public License. */
-
- #ifndef __libgcc_thr_h
- #define __libgcc_thr_h
-
- /* If this file is compiled with threads support, it must
- #define __GTHREADS 1
- to indicate that threads support is present.
-
- The threads interface must define the following types:
- __gthread_key_t
- __gthread_once_t
- __gthread_mutex_t
-
- The threads interface must define the following macros:
-
- __GTHREAD_ONCE_INIT
- to initialize __gthread_once_t
- __GTHREAD_MUTEX_INIT
- to initialize __gthread_mutex_t to get a fast
- non-recursive mutex.
-
- The threads interface must define the following static functions:
-
- int __gthread_once (__gthread_once_t *once, void (*func) ())
-
- int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
- int __gthread_key_delete (__gthread_key_t key)
-
- void *__gthread_getspecific (__gthread_key_t key)
- int __gthread_setspecific (__gthread_key_t key, const void *ptr)
-
- int __gthread_mutex_lock (__gthread_mutex_t *mutex);
- int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
- int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
-
- All functions returning int should return 0 on success, -1 on error.
-
- Currently supported threads packages are
- POSIX threads with -D_PTHREADS
- DCE threads with -D_DCE_THREADS
- Solaris/UI threads with -D_SOLARIS_THREADS
- */
-
- #if _PTHREADS
- /* POSIX threads specific definitions.
- Easy, since the interface is just one-to-one mapping. */
-
- #define __GTHREADS 1
-
- #include <pthread.h>
-
- typedef pthread_key_t __gthread_key_t;
- typedef pthread_once_t __gthread_once_t;
- typedef pthread_mutex_t __gthread_mutex_t;
-
- #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
- #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
-
- static inline int
- __gthread_once (__gthread_once_t *once, void (*func) ())
- {
- return pthread_once (once, func);
- }
-
- static inline int
- __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
- {
- return pthread_key_create (key, dtor);
- }
-
- static inline int
- __gthread_key_delete (__gthread_key_t key)
- {
- return pthread_key_delete (key);
- }
-
- static inline void *
- __gthread_getspecific (__gthread_key_t key)
- {
- return pthread_getspecific (key);
- }
-
- static inline int
- __gthread_setspecific (__gthread_key_t key, const void *ptr)
- {
- return pthread_setspecific (key, ptr);
- }
-
- static inline int
- __gthread_mutex_lock (__gthread_mutex_t *mutex)
- {
- return pthread_mutex_lock (mutex);
- }
-
- static inline int
- __gthread_mutex_trylock (__gthread_mutex_t *mutex)
- {
- return pthread_mutex_trylock (mutex);
- }
-
- static inline int
- __gthread_mutex_unlock (__gthread_mutex_t *mutex)
- {
- return pthread_mutex_unlock (mutex);
- }
-
- #elif _DCE_THREADS
- /* DCE threads interface.
- DCE threads are based on POSIX threads draft 4, and many things
- have changed since then. */
-
- #define __GTHREADS 1
-
- #include <pthread.h>
-
- typedef pthread_key_t __gthread_key_t;
- typedef pthread_once_t __gthread_once_t;
- typedef pthread_mutex_t __gthread_mutex_t;
-
- #define __GTHREAD_ONCE_INIT pthread_once_init
- /* Howto define __GTHREAD_MUTEX_INIT? */
-
- static inline int
- __gthread_once (__gthread_once_t *once, void (*func) ())
- {
- return pthread_once (once, func);
- }
-
- static inline int
- __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
- {
- return pthread_keycreate (key, dtor);
- }
-
- static inline int
- __gthread_key_delete (__gthread_key_t key)
- {
- return pthread_key_delete (key);
- }
-
- static inline void *
- __gthread_getspecific (__gthread_key_t key)
- {
- void *ptr;
- if (pthread_getspecific (key, &ptr) == 0)
- return ptr;
- else
- return 0;
- }
-
- static inline int
- __gthread_setspecific (__gthread_key_t key, const void *ptr)
- {
- return pthread_setspecific (key, (void *) ptr);
- }
-
- static inline int
- __gthread_mutex_lock (__gthread_mutex_t *mutex)
- {
- return pthread_mutex_lock (mutex);
- }
-
- static inline int
- __gthread_mutex_trylock (__gthread_mutex_t *mutex)
- {
- return pthread_mutex_trylock (mutex);
- }
-
- static inline int
- __gthread_mutex_unlock (__gthread_mutex_t *mutex)
- {
- return pthread_mutex_unlock (mutex);
- }
-
- #elif _SOLARIS_THREADS
- /* Solaris threads as found in Solaris 2.[456].
- Actually these are Unix International (UI) threads, but I don't
- know if anyone else implements these. */
-
- #define __GTHREADS 1
-
- #include <thread.h>
- #include <errno.h>
-
- typedef thread_key_t __gthread_key_t;
- typedef struct
- {
- mutex_t mutex;
- int once;
- } __gthread_once_t;
- typedef mutex_t __gthread_mutex_t;
-
- #define __GTHREAD_ONCE_INIT { DEFAULTMUTEX, 0 }
- #define __GTHREAD_MUTEX_INIT DEFAULTMUTEX
-
- static inline int
- __gthread_once (__gthread_once_t *once, void (*func) ())
- {
- if (once == 0 || func == 0)
- {
- errno = EINVAL;
- return -1;
- }
-
- if (once->once == 0)
- {
- if (mutex_lock (&once->mutex) != 0)
- return -1;
- if (once->once == 0)
- {
- (*func) ();
- once->once ++;
- }
- mutex_unlock (&once->mutex);
- }
- return 0;
- }
-
- static inline int
- __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
- {
- return thr_keycreate (key, dtor);
- }
-
- static inline int
- __gthread_key_delete (__gthread_key_t key)
- {
- /* Not possible. */
- return -1;
- }
-
- static inline void *
- __gthread_getspecific (__gthread_key_t key)
- {
- void *ptr;
- if (thr_getspecific (key, &ptr) == 0)
- return ptr;
- else
- return 0;
- }
-
- static inline int
- __gthread_setspecific (__gthread_key_t key, const void *ptr)
- {
- return thr_setspecific (key, (void *) ptr);
- }
-
- static inline int
- __gthread_mutex_lock (__gthread_mutex_t *mutex)
- {
- return mutex_lock (mutex);
- }
-
- static inline int
- __gthread_mutex_trylock (__gthread_mutex_t *mutex)
- {
- return mutex_trylock (mutex);
- }
-
- static inline int
- __gthread_mutex_unlock (__gthread_mutex_t *mutex)
- {
- return mutex_unlock (mutex);
- }
-
- #else /* no threads */
-
- /* Just provide compatibility for mutex handling. */
-
- typedef int __gthread_mutex_t;
-
- #define __GTHREAD_MUTEX_INIT 0
-
- static inline int
- __gthread_mutex_lock (__gthread_mutex_t *mutex)
- {
- return 0;
- }
-
- static inline int
- __gthread_mutex_trylock (__gthread_mutex_t *mutex)
- {
- return 0;
- }
-
- static inline int
- __gthread_mutex_unlock (__gthread_mutex_t *mutex)
- {
- return 0;
- }
-
- #endif /* no threads */
-
- #endif /* not __libgcc_thr_h */
--- 0 ----
Index: libgcc2.c
===================================================================
RCS file: /trema/cvs/gnu/egcs/gcc/libgcc2.c,v
retrieving revision 1.16
diff -c -c -3 -p -r1.16 libgcc2.c
*** libgcc2.c 1997/12/17 09:37:18 1.16
--- libgcc2.c 1997/12/17 11:08:48
*************** int _exit_dummy_decl = 0; /* prevent com
*** 2962,2968 ****
#ifdef L_eh
! #include "libgcc-thr.h"
/* Shared exception handling support routines. */
--- 2962,2968 ----
#ifdef L_eh
! #include "gthr.h"
/* Shared exception handling support routines. */
*************** eh_context_initialize ()
*** 3091,3097 ****
#if __GTHREADS
static __gthread_once_t once = __GTHREAD_ONCE_INIT;
! __gthread_once (&once, eh_threads_initialize);
#else /* no __GTHREADS */
--- 3091,3101 ----
#if __GTHREADS
static __gthread_once_t once = __GTHREAD_ONCE_INIT;
! if (__gthread_once (&once, eh_threads_initialize) == -1)
! {
! /* Use static version of EH context. */
! get_eh_context = &eh_context_static;
! }
#else /* no __GTHREADS */