Makefile.in (GTHREAD_FLAGS): New var.

* Makefile.in (GTHREAD_FLAGS): New var.
	(LIBGCC2_CFLAGS): Added $(GTHREAD_FLAGS).
	(distclean): Remove gthr-default.h.
	* configure.in: Accept dce as a thread package.
	Check for thread.h and pthread.h.
	Link gthr-default.h to appropriate thread file and set
	gthread_flags.
	(hppa1.1-*-hpux10*): If --enable-threads, use dce threads and
	include multilib definitions from pa/t-dce-thr.
	(sparc-*-solaris2*): Enable threads by default, if thread.h or
	pthread.h is found, preferring posix threads over solaris ones.
	* config/pa/t-dce-thr: New file.
	* config/pa/t-pa: Removed multilibs.
	* config/sparc/t-sol2: Ditto.
	* 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.
	* objc/thr-dce.c: New file copied from thr-decosf1.c.
	* 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.
	(eh_context_free): Call __gthread_key_dtor.

From-SVN: r17235
This commit is contained in:
Teemu Torma 1997-12-24 23:56:08 +00:00 committed by Jeff Law
parent df3b6ab30e
commit f24af81bca
16 changed files with 1228 additions and 471 deletions

View File

@ -1,3 +1,36 @@
1997-12-25 Teemu Torma <tot@trema.com>
* Makefile.in (GTHREAD_FLAGS): New var.
(LIBGCC2_CFLAGS): Added $(GTHREAD_FLAGS).
(distclean): Remove gthr-default.h.
* configure.in: Accept dce as a thread package.
Check for thread.h and pthread.h.
Link gthr-default.h to appropriate thread file and set
gthread_flags.
(hppa1.1-*-hpux10*): If --enable-threads, use dce threads and
include multilib definitions from pa/t-dce-thr.
(sparc-*-solaris2*): Enable threads by default, if thread.h or
pthread.h is found, preferring posix threads over solaris ones.
* config/pa/t-dce-thr: New file.
* config/pa/t-pa: Removed multilibs.
* config/sparc/t-sol2: Ditto.
* 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.
* objc/thr-dce.c: New file copied from thr-decosf1.c.
* 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.
(eh_context_free): Call __gthread_key_dtor.
Wed Dec 24 23:33:17 1997 Jeffrey A Law (law@cygnus.com)
* expr.h (MUST_PASS_IN_STACK): Allow target port to override.

View File

@ -206,6 +206,7 @@ host_xm_file=@host_xm_file_list@
lang_specs_files=@lang_specs_files@
lang_options_files=@lang_options_files@
GCC_THREAD_FILE=@thread_file@
GTHREAD_FLAGS=@gthread_flags@
version=@version@
mainversion=`sed -e 's/.*\"\([0-9]*\.[0-9]*\).*/\1/' < $(srcdir)/version.c`
@ -281,7 +282,7 @@ LIBGCC2 = libgcc2.a
# -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@
LIBGCC2_CFLAGS = -O2 $(LIBGCC2_INCLUDES) $(GCC_CFLAGS) $(TARGET_LIBGCC2_CFLAGS) $(LIBGCC2_DEBUG_CFLAGS) $(GTHREAD_FLAGS) -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -fexceptions @inhibit_libc@
# Additional options to use when compiling libgcc2.a.
# Some targets override this to -Iinclude
@ -2157,6 +2158,7 @@ distclean: clean bytecode.distclean lang.distclean
-rm -f config.status config.run config.cache config.bak
-rm -f Make-lang Make-hooks Make-host Make-target
-rm -f Makefile specs.h options.h *.oaux
-rm -f gthr-default.h
-rm -f */stage1 */stage2 */stage3 */stage4 */include
-rm -f c-parse.output
-rm -f *.asm

5
gcc/config/pa/t-dce-thr Normal file
View File

@ -0,0 +1,5 @@
MULTILIB_OPTIONS = threads
MULTILIB_DIRNAMES = threads
LIBGCC = stmp-multilib
INSTALL_LIBGCC = install-multilib

View File

@ -16,9 +16,3 @@ ee_fp.asm: $(srcdir)/config/pa/ee_fp.asm
cp $(srcdir)/config/pa/ee_fp.asm .
TARGET_LIBGCC2_CFLAGS = -fPIC
MULTILIB_OPTIONS = threads
MULTILIB_DIRNAMES = threads
LIBGCC = stmp-multilib
INSTALL_LIBGCC = install-multilib

View File

@ -5,13 +5,6 @@ LIBGCC1 =
CROSS_LIBGCC1 =
LIBGCC1_TEST =
MULTILIB_OPTIONS = threads
MULTILIB_DIRNAMES = threads
MULTILIB_MATCHES = threads=pthreads
LIBGCC = stmp-multilib
INSTALL_LIBGCC = install-multilib
# gmon build rule:
gmon.o: $(srcdir)/config/sparc/gmon-sol2.c $(GCC_PASSES) $(CONFIG_H) stmp-int-hdrs
$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(INCLUDES) \

362
gcc/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -114,7 +114,7 @@ case x${enable_threads} in
thread_file=''
;;
xdecosf1 | xirix | xmach | xos2 | xposix | xpthreads | xsingle | \
xsolaris | xwin32)
xsolaris | xwin32 | xdce)
thread_file=$enable_threads
;;
*)
@ -147,6 +147,10 @@ AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS(limits.h stddef.h string.h strings.h stdlib.h time.h fcntl.h unistd.h sys/file.h sys/time.h sys/resource.h sys/param.h sys/times.h varargs.h sys/varargs.h)
# Check for thread headers.
AC_CHECK_HEADER(thread.h, [have_thread_h=yes], [have_thread_h=])
AC_CHECK_HEADER(pthread.h, [have_pthread_h=yes], [have_pthread_h=])
# Use <inttypes.h> only if it exists,
# doesn't clash with <sys/types.h>, and declares intmax_t.
AC_MSG_CHECKING(for inttypes.h)
@ -637,10 +641,18 @@ for machine in $build $host $target; do
tm_file="${tm_file} pa/pa-hpux.h pa/pa-hpux10.h"
xm_file=pa/xm-pahpux.h
xmake_file=pa/x-pa-hpux
tmake_file=pa/t-pa
if [[ x$gas = xyes ]]
then
tm_file="${tm_file} pa/pa-gas.h"
fi
if [[ x$enable_threads = x ]]; then
enable_threads=$have_pthread_h
fi
if [[ x$enable_threads = xyes ]]; then
thread_file='dce'
tmake_file="${tmake_file} pa/t-dce-thr"
fi
install_headers_dir=install-headers-cpio
use_collect2=yes
;;
@ -2480,8 +2492,18 @@ for machine in $build $host $target; do
fixincludes=fixinc.svr4
float_format=i128
broken_install=yes
if [[ x$enable_threads = xyes ]]; then
if [[ x${enable_threads} = x ]]; then
enable_threads=$have_pthread_h
if [[ x${enable_threads} = x ]]; then
enable_threads=$have_thread_h
fi
fi
if [[ x${enable_threads} = xyes ]]; then
if [[ x${have_pthread_h} = xyes ]]; then
thread_file='posix'
else
thread_file='solaris'
fi
fi
;;
sparc-*-sunos4.0*)
@ -3078,6 +3100,15 @@ do
esac
done
# Make gthr-default.h if we have a thread file.
gthread_flags=
if [[ $thread_file != single ]]; then
rm -f gthr-default.h
$symbolic_link gthr-${thread_file}.h gthr-default.h
gthread_flags=-DHAVE_GTHR_DEFAULT
fi
AC_SUBST(gthread_flags)
# Make empty files to contain the specs and options for each language.
# Then add #include lines to for a compiler that has specs and/or options.

View File

@ -39,7 +39,7 @@ Boston, MA 02111-1307, USA. */
#include "dwarf2.h"
#include <stddef.h>
#include "frame.h"
#include "libgcc-thr.h"
#include "gthr.h"
#ifdef __GTHREAD_MUTEX_INIT
static __gthread_mutex_t object_mutex = __GTHREAD_MUTEX_INIT;

150
gcc/gthr-dce.h Normal file
View File

@ -0,0 +1,150 @@
/* 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_dtor (__gthread_key_t key, void *ptr)
{
/* Nothing needed. */
return 0;
}
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 */

147
gcc/gthr-posix.h Normal file
View File

@ -0,0 +1,147 @@
/* 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_dtor (__gthread_key_t key, void *ptr)
{
/* Just reset the key value to zero. */
if (ptr)
return pthread_setspecific (key, 0);
else
return 0;
}
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 */

62
gcc/gthr-single.h Normal file
View File

@ -0,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 */

179
gcc/gthr-solaris.h Normal file
View File

@ -0,0 +1,179 @@
/* 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_dtor (__gthread_key_t key, void *ptr)
{
/* Nothing needed. */
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 */

96
gcc/gthr.h Normal file
View File

@ -0,0 +1,96 @@
/* 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)
int __gthread_key_dtor (__gthread_key_t key, void *ptr)
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 SUPPORTS_WEAK && HAVE_GTHR_DEFAULT
#ifndef GTHREAD_USE_WEAK
#define GTHREAD_USE_WEAK 1
#endif
#include "gthr-default.h"
/* Fallback to single thread definitions. */
#else
#include "gthr-single.h"
#endif
#endif /* not __gthr_h */

View File

@ -1,321 +0,0 @@
/* 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 */

View File

@ -2965,7 +2965,7 @@ int _exit_dummy_decl = 0; /* prevent compiler & linker warnings */
#ifdef L_eh
#include "libgcc-thr.h"
#include "gthr.h"
/* Shared exception handling support routines. */
@ -3038,6 +3038,7 @@ static __gthread_key_t eh_context_key;
static void
eh_context_free (void *ptr)
{
__gthread_key_dtor (eh_context_key, ptr);
if (ptr)
free (ptr);
}
@ -3094,7 +3095,11 @@ eh_context_initialize ()
#if __GTHREADS
static __gthread_once_t once = __GTHREAD_ONCE_INIT;
__gthread_once (&once, eh_threads_initialize);
if (__gthread_once (&once, eh_threads_initialize) == -1)
{
/* Use static version of EH context. */
get_eh_context = &eh_context_static;
}
#else /* no __GTHREADS */

281
gcc/objc/thr-dce.c Normal file
View File

@ -0,0 +1,281 @@
/* GNU Objective C Runtime Thread Interface
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
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 files compiled with
GCC to produce an executable, this does not 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. */
#include <pthread.h>
#include <objc/thr.h>
#include "runtime.h"
/* Key structure for maintaining thread specific storage */
static pthread_key_t _objc_thread_storage;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__objc_init_thread_system(void)
{
/* Initialize the thread storage key */
return pthread_keycreate(&_objc_thread_storage, NULL);
}
/* Close the threads subsystem. */
int
__objc_close_thread_system(void)
{
/* Destroy the thread storage key */
/* Not implemented yet */
/* return pthread_key_delete(&_objc_thread_storage); */
return 0;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg)
{
objc_thread_t thread_id;
pthread_t new_thread_handle;
if (pthread_create(&new_thread_handle, pthread_attr_default,
(void *)func, arg) == 0)
{
/* ??? May not work! (64bit) */
thread_id = *(objc_thread_t *)&new_thread_handle;
pthread_detach(&new_thread_handle); /* Fully detach thread. */
}
else
thread_id = NULL;
return thread_id;
}
/* Set the current thread's priority. */
int
__objc_thread_set_priority(int priority)
{
int sys_priority = 0;
switch (priority)
{
case OBJC_THREAD_INTERACTIVE_PRIORITY:
sys_priority = (PRI_FG_MIN_NP + PRI_FG_MAX_NP) / 2;
break;
default:
case OBJC_THREAD_BACKGROUND_PRIORITY:
sys_priority = (PRI_BG_MIN_NP + PRI_BG_MAX_NP) / 2;
break;
case OBJC_THREAD_LOW_PRIORITY:
sys_priority = (PRI_BG_MIN_NP + PRI_BG_MAX_NP) / 2;
break;
}
/* Change the priority. */
if (pthread_setprio(pthread_self(), sys_priority) >= 0)
return 0;
else
/* Failed */
return -1;
}
/* Return the current thread's priority. */
int
__objc_thread_get_priority(void)
{
int sys_priority;
if ((sys_priority = pthread_getprio(pthread_self())) >= 0) {
if (sys_priority >= PRI_FG_MIN_NP && sys_priority <= PRI_FG_MAX_NP)
return OBJC_THREAD_INTERACTIVE_PRIORITY;
if (sys_priority >= PRI_BG_MIN_NP && sys_priority <= PRI_BG_MAX_NP)
return OBJC_THREAD_BACKGROUND_PRIORITY;
return OBJC_THREAD_LOW_PRIORITY;
}
/* Failed */
return -1;
}
/* Yield our process time to another thread. */
void
__objc_thread_yield(void)
{
pthread_yield();
}
/* Terminate the current thread. */
int
__objc_thread_exit(void)
{
/* exit the thread */
pthread_exit(&__objc_thread_exit_status);
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__objc_thread_id(void)
{
pthread_t self = pthread_self();
return (objc_thread_t) pthread_getunique_np (&self);
}
/* Sets the thread's local storage pointer. */
int
__objc_thread_set_data(void *value)
{
return pthread_setspecific(_objc_thread_storage, value);
}
/* Returns the thread's local storage pointer. */
void *
__objc_thread_get_data(void)
{
void *value = NULL;
if ( !(pthread_getspecific(_objc_thread_storage, &value)) )
return value;
return NULL;
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__objc_mutex_allocate(objc_mutex_t mutex)
{
if (pthread_mutex_init((pthread_mutex_t *)(&(mutex->backend)),
pthread_mutexattr_default))
return -1;
else
return 0;
}
/* Deallocate a mutex. */
int
__objc_mutex_deallocate(objc_mutex_t mutex)
{
if (pthread_mutex_destroy((pthread_mutex_t *)(&(mutex->backend))))
return -1;
else
return 0;
}
/* Grab a lock on a mutex. */
int
__objc_mutex_lock(objc_mutex_t mutex)
{
return pthread_mutex_lock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
if (pthread_mutex_trylock((pthread_mutex_t *)(&(mutex->backend))) != 1)
return -1;
else
return 0;
}
/* Unlock the mutex */
int
__objc_mutex_unlock(objc_mutex_t mutex)
{
return pthread_mutex_unlock((pthread_mutex_t *)(&(mutex->backend)));
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__objc_condition_allocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
if (pthread_cond_init((pthread_cond_t *)(&(condition->backend)), NULL))
return -1;
else
return 0;
*/
}
/* Deallocate a condition. */
int
__objc_condition_deallocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_destroy((pthread_cond_t *)(&(condition->backend)));
*/
}
/* Wait on the condition */
int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_wait((pthread_cond_t *)(&(condition->backend)),
(pthread_mutex_t *)(&(mutex->backend)));
*/
}
/* Wake up all threads waiting on this condition. */
int
__objc_condition_broadcast(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_broadcast((pthread_cond_t *)(&(condition->backend)));
*/
}
/* Wake up one thread waiting on this condition. */
int
__objc_condition_signal(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
/*
return pthread_cond_signal((pthread_cond_t *)(&(condition->backend)));
*/
}
/* End of File */