* Re: MT-safe exception and thread library
@ 1997-12-20 7:08 Andrew Zabolotny
0 siblings, 0 replies; 10+ messages in thread
From: Andrew Zabolotny @ 1997-12-20 7:08 UTC (permalink / raw)
To: egcs
On Wed, 17 Dec 1997 13:48:26 +0100, Teemu Torma wrote:
> One more thing: the flag. How about -fthreads instead of -threads?
>And what if there are multiple thread libraries? There are, at
>least in Solaris 2.5.
I'm not sure if this is applicable, but OS/2 resolves this following way
(since `93 or `94):
In target makefile fragment:
# Allow multi-threaded/single-threaded libraries
MULTILIB_OPTIONS = Zmt
MULTILIB_DIRNAMES = mt st
MULTILIB_MATCHES = Zmt=Zmts Zmt=Zmtd
MULTILIB_EXCEPTIONS =
MULTILIB_EXTRA_OPTS =
and with a few changes to
-----------------------------------------------------------
diff -rcwB pgcc-1.0/gcc/genmultilib pgcc-1.0-emx/gcc/genmultilib
*** pgcc-1.0/gcc/genmultilib Mon Aug 11 18:57:08 1997
--- pgcc-1.0-emx/gcc/genmultilib Mon Dec 8 23:08:38 1997
***************
*** 35,40 ****
--- 35,43 ----
# elements in the second list are separated by spaces. If the second
# argument is empty, the option names will be used as the directory
# names.
+ # If number of elements in second argument is bigger than number of
options
+ # in the first argument, the n+1'th element is used as default directory
+ # name (i.e. when no one of options specified in argument 1 was used)
# The optional third argument is a list of options which are
# identical. The elements in the list are separated by spaces. Each
***************
*** 164,169 ****
--- 167,178 ----
done
fi
+ # See if default directory was specified
+ if [ -n "$1" ]; then
+ defaultdir="$1"
+ else
+ defaultdir="."
+ fi
# We need another recursive shell script to correctly handle positive
# matches. If we are invoked as
# genmultilib "opt1 opt2" "" "opt1=nopt1 opt2=nopt2"
***************
*** 203,209 ****
done
done
optout=`echo ${optout} | sed -e 's/^ //'`
! echo "\". ${optout};\","
# Work over the list of combinations. We have to translate each one
# to use the directory names rather than the option names, we have to
--- 212,218 ----
done
done
optout=`echo ${optout} | sed -e 's/^ //'`
! echo "\"${defaultdir} ${optout};\","
# Work over the list of combinations. We have to translate each one
# to use the directory names rather than the option names, we have to
-----------------------------the end----------------------------
It also would be nice to define some symbol (OS/2 defines __MT__ -- are
there other standards? If yes, it would be The Right Thing {tm} to define
some unique symbol everywhere (on all platforms), and all other symbols
depending on target platform) when using -mthreads (this is needed, for
example C headers checks it for a thread-aware errno). And it looks stupid
to me to make three (four counting OS/2`s -Zmt/-Zst) different switches
for same thing - producing a threaded program. There should be only one
switch, I think -fthreads looks best. I think this switch should be
unified ASAP, since later changing the switch may affect much more
makefiles.
>pthread library. Similiary, -threads would do the same thing with
>a platform-specific threads library.
-fthreads should define the preprocessor symbol and link agains
thread-aware C libraries, the thread library itself
can be as well linked with something like -lthreads.
Greetings,
_\ndy@teamOS/2
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MT-safe exception and thread library
1997-12-16 12:25 H.J. Lu
1997-12-17 1:11 ` Teemu Torma
[not found] ` <199712170910.KAA25862.cygnus.egcs@baht.labs.trema.com>
@ 1997-12-17 10:10 ` Teemu Torma
1997-12-17 8:57 ` H.J. Lu
2 siblings, 1 reply; 10+ messages in thread
From: Teemu Torma @ 1997-12-17 10:10 UTC (permalink / raw)
To: H.J. Lu; +Cc: egcs, GNU C Library
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 ****
\f
#ifdef L_eh
! #include "libgcc-thr.h"
/* Shared exception handling support routines. */
--- 2962,2968 ----
\f
#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 */
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MT-safe exception and thread library
1997-12-17 10:10 ` Teemu Torma
@ 1997-12-17 8:57 ` H.J. Lu
0 siblings, 0 replies; 10+ messages in thread
From: H.J. Lu @ 1997-12-17 8:57 UTC (permalink / raw)
To: Teemu Torma; +Cc: egcs, libc-linux
>
> 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 will be gone for 3 weeks. I will try it when I come back.
Thanks.
H.J.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MT-safe exception and thread library
1997-12-17 1:11 ` Teemu Torma
1997-12-17 4:30 ` Andrey Slepuhin
@ 1997-12-17 6:10 ` Ulrich Drepper
1 sibling, 0 replies; 10+ messages in thread
From: Ulrich Drepper @ 1997-12-17 6:10 UTC (permalink / raw)
To: Teemu Torma; +Cc: egcs, GNU C Library
Teemu Torma <tot@Trema.COM> writes:
> It is not nice to use multilibs, but I am not sure if using weak
> symbols is that straightforward. One problem that may arise is
> that MT code should usually be compiled with some preprocessor
> options (-D_REENTRANT for example), which also changes some other
> things, at least how "errno" is defined.
No, a corect environment must not depend on -D_REENTRANT being
defined. This is absolutely no problem if you use glibc on an ELF
system and therefore HJ's proposal is the only acceptable for these
systems.
-- Uli
---------------. drepper at gnu.org ,-. Rubensstrasse 5
Ulrich Drepper \ ,-------------------' \ 76149 Karlsruhe/Germany
Cygnus Solutions `--' drepper at cygnus.com `------------------------
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MT-safe exception and thread library
1997-12-17 2:52 ` Jason Merrill
1997-12-17 4:48 ` Teemu Torma
@ 1997-12-17 4:59 ` Andrey Slepuhin
1 sibling, 0 replies; 10+ messages in thread
From: Andrey Slepuhin @ 1997-12-17 4:59 UTC (permalink / raw)
To: egcs
Jason Merrill wrote:
>
> One more thing: the flag. How about -fthreads instead of -threads?
Or -mthreads which is already present for some targets to force
the use of thread-safe versions of libc and crt0.o.
(or -fthreads should force -mthreads?)
Andrey.
^ permalink raw reply [flat|nested] 10+ messages in thread
* MT-safe exception and thread library
1997-12-17 2:52 ` Jason Merrill
@ 1997-12-17 4:48 ` Teemu Torma
1997-12-17 4:59 ` Andrey Slepuhin
1 sibling, 0 replies; 10+ messages in thread
From: Teemu Torma @ 1997-12-17 4:48 UTC (permalink / raw)
To: egcs
From: Jason Merrill <jason@cygnus.com>
Date: 17 Dec 1997 02:52:12 -0800
One more thing: the flag. How about -fthreads instead of -threads?
And what if there are multiple thread libraries? There are, at
least in Solaris 2.5.
Personally I would prefer the flag to define all necessary pre-processor symbols and link against right libraries. So -pthreads (or whatever
the name would be) would do the right thing in all platforms to use
pthread library. Similiary, -threads would do the same thing with
a platform-specific threads library. I don't know if there are
any other standards that would deserve an own flag.
Just some random thoughts.
Teemu
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MT-safe exception and thread library
1997-12-17 1:11 ` Teemu Torma
@ 1997-12-17 4:30 ` Andrey Slepuhin
1997-12-17 6:10 ` Ulrich Drepper
1 sibling, 0 replies; 10+ messages in thread
From: Andrey Slepuhin @ 1997-12-17 4:30 UTC (permalink / raw)
To: egcs
Teemu Torma wrote:
>
> From: hjl@lucon.org (H.J. Lu)
> Date: Tue, 16 Dec 1997 11:29:29 -0800 (PST)
>
> I am not sure if I like the multilibs for the Thread-safe EH support.
> That may be a problem for glibc. I'd like to see an option for a
> single libgcc.a with the the Thread-safe EH support using weak
> symols. I think it should work with gcc on platforms with weak
> support. We can use SUPPORTS_WEAK to detect it. It should be
> very easy to do.
>
> It is not nice to use multilibs, but I am not sure if using weak
> symbols is that straightforward. One problem that may arise is
> that MT code should usually be compiled with some preprocessor
> options (-D_REENTRANT for example), which also changes some other
> things, at least how "errno" is defined. It may or may not cause
> problems in libgcc.
I agree that using weak symbols also may cause problems, but
anyway on my AIX box (which don't support weak symbols) I have
12 (!!!) different libraries with multilib enabled, so I must
to hack configuration files manually to disable cpu-specific
libraries, so it would be better to separate thread-specific
configuration options.
Andrey.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: MT-safe exception and thread library
[not found] ` <199712170910.KAA25862.cygnus.egcs@baht.labs.trema.com>
@ 1997-12-17 2:52 ` Jason Merrill
1997-12-17 4:48 ` Teemu Torma
1997-12-17 4:59 ` Andrey Slepuhin
0 siblings, 2 replies; 10+ messages in thread
From: Jason Merrill @ 1997-12-17 2:52 UTC (permalink / raw)
To: egcs
One more thing: the flag. How about -fthreads instead of -threads?
Jason
^ permalink raw reply [flat|nested] 10+ messages in thread
* MT-safe exception and thread library
1997-12-16 12:25 H.J. Lu
@ 1997-12-17 1:11 ` Teemu Torma
1997-12-17 4:30 ` Andrey Slepuhin
1997-12-17 6:10 ` Ulrich Drepper
[not found] ` <199712170910.KAA25862.cygnus.egcs@baht.labs.trema.com>
1997-12-17 10:10 ` Teemu Torma
2 siblings, 2 replies; 10+ messages in thread
From: Teemu Torma @ 1997-12-17 1:11 UTC (permalink / raw)
To: egcs; +Cc: GNU C Library
From: hjl@lucon.org (H.J. Lu)
Date: Tue, 16 Dec 1997 11:29:29 -0800 (PST)
I am not sure if I like the multilibs for the Thread-safe EH support.
That may be a problem for glibc. I'd like to see an option for a
single libgcc.a with the the Thread-safe EH support using weak
symols. I think it should work with gcc on platforms with weak
support. We can use SUPPORTS_WEAK to detect it. It should be
very easy to do.
It is not nice to use multilibs, but I am not sure if using weak
symbols is that straightforward. One problem that may arise is
that MT code should usually be compiled with some preprocessor
options (-D_REENTRANT for example), which also changes some other
things, at least how "errno" is defined. It may or may not cause
problems in libgcc.
Teemu
^ permalink raw reply [flat|nested] 10+ messages in thread
* MT-safe exception and thread library
@ 1997-12-16 12:25 H.J. Lu
1997-12-17 1:11 ` Teemu Torma
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: H.J. Lu @ 1997-12-16 12:25 UTC (permalink / raw)
To: egcs; +Cc: GNU C Library
I am glad to see the Thread-safe EH support in egcs 971215. There is
already configure support for thread in libobjc.a. Can libgcc also use
it also? Basically, configure defines "thread_file", which can be
single, posix, mach, win32, solaris, irix. It shouldn't be hard to
add DCE. libgcc-thr.h can be linked to libgcc-$thread_file.h
so that --enable-threads will enable the Thread-safe EH support
and set the right thread file.
I am not sure if I like the multilibs for the Thread-safe EH support.
That may be a problem for glibc. I'd like to see an option for a
single libgcc.a with the the Thread-safe EH support using weak
symols. I think it should work with gcc on platforms with weak
support. We can use SUPPORTS_WEAK to detect it. It should be
very easy to do.
Thanks.
--
H.J. Lu (hjl@gnu.org)
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~1997-12-20 7:08 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-20 7:08 MT-safe exception and thread library Andrew Zabolotny
-- strict thread matches above, loose matches on Subject: below --
1997-12-16 12:25 H.J. Lu
1997-12-17 1:11 ` Teemu Torma
1997-12-17 4:30 ` Andrey Slepuhin
1997-12-17 6:10 ` Ulrich Drepper
[not found] ` <199712170910.KAA25862.cygnus.egcs@baht.labs.trema.com>
1997-12-17 2:52 ` Jason Merrill
1997-12-17 4:48 ` Teemu Torma
1997-12-17 4:59 ` Andrey Slepuhin
1997-12-17 10:10 ` Teemu Torma
1997-12-17 8:57 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).