2004-09-23 22:57:25 +02:00
|
|
|
/* Threads compatibility routines for libgcc2 and libobjc.
|
|
|
|
Compile this one with gcc.
|
2019-01-01 13:31:55 +01:00
|
|
|
Copyright (C) 2004-2019 Free Software Foundation, Inc.
|
2004-09-23 22:57:25 +02:00
|
|
|
|
|
|
|
This file is part of GCC.
|
|
|
|
|
|
|
|
GCC 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
|
2009-04-09 17:00:19 +02:00
|
|
|
Software Foundation; either version 3, or (at your option) any later
|
2004-09-23 22:57:25 +02:00
|
|
|
version.
|
|
|
|
|
|
|
|
GCC 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.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
2004-09-23 22:57:25 +02:00
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2004-09-23 22:57:25 +02:00
|
|
|
|
2009-11-25 11:55:54 +01:00
|
|
|
/* TPF needs its own version of gthr-*.h because TPF always links to
|
2004-09-23 22:57:25 +02:00
|
|
|
the thread library. However, for performance reasons we still do not
|
|
|
|
want to issue thread api calls unless a check is made to see that we
|
|
|
|
are running as a thread. */
|
|
|
|
|
|
|
|
#ifndef GCC_GTHR_TPF_H
|
|
|
|
#define GCC_GTHR_TPF_H
|
|
|
|
|
|
|
|
/* POSIX threads specific definitions.
|
|
|
|
Easy, since the interface is just one-to-one mapping. */
|
|
|
|
|
|
|
|
#define __GTHREADS 1
|
|
|
|
|
|
|
|
/* Some implementations of <pthread.h> require this to be defined. */
|
|
|
|
#ifndef _REENTRANT
|
|
|
|
#define _REENTRANT 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
typedef pthread_key_t __gthread_key_t;
|
|
|
|
typedef pthread_once_t __gthread_once_t;
|
|
|
|
typedef pthread_mutex_t __gthread_mutex_t;
|
2004-10-02 02:48:44 +02:00
|
|
|
typedef pthread_mutex_t __gthread_recursive_mutex_t;
|
|
|
|
|
|
|
|
#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
|
|
|
|
#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
|
|
|
|
#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
|
|
|
|
#define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
|
|
|
|
#endif
|
2004-09-23 22:57:25 +02:00
|
|
|
|
|
|
|
#define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
|
|
|
|
#define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
|
2006-11-29 14:00:12 +01:00
|
|
|
#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
|
2004-09-23 22:57:25 +02:00
|
|
|
|
|
|
|
#define NOTATHREAD 00
|
|
|
|
#define ECBBASEPTR (unsigned long int) *(unsigned int *)0x00000514u
|
|
|
|
#define ECBPG2PTR ECBBASEPTR + 0x1000
|
2005-06-30 18:07:24 +02:00
|
|
|
#define CE2THRCPTR *((unsigned char *)(ECBPG2PTR + 16))
|
2004-09-23 22:57:25 +02:00
|
|
|
#define __tpf_pthread_active() (CE2THRCPTR != NOTATHREAD)
|
|
|
|
|
|
|
|
#if SUPPORTS_WEAK && GTHREAD_USE_WEAK
|
2005-11-09 21:57:30 +01:00
|
|
|
# define __gthrw(name) \
|
re PR other/24829 (libobjc testsuite failures)
PR other/24829
PR target/24831
* gthr-dce.h: Do not gthrw-ify pthread_once_init,
pthread_key_delete. From John David Anglin. gthrw-ify
pthread_getunique_np only if it it's not a macro. Delete
UNUSED macro.
(__gthread_objc_condition_allocate, __gthread_objc_condition_deallocate,
__gthread_objc_condition_wait, __gthread_objc_condition_broadcast,
__gthread_objc_condition_signal, __gthread_key_delete): Add
"__attribute__ ((__unused__))" to unused arguments.
(__gthread_recursive_mutex_init_function): Add missing return.
* gthr-dce.h, gthr-tpf.h, gthr-solaris.h, gthr-posix.h,
gthr-posix95.h: Use macro-based approach for name redirection
on targets missing weakref.
From-SVN: r110278
2006-01-26 23:00:28 +01:00
|
|
|
static __typeof(name) __gthrw_ ## name __attribute__ ((__weakref__(#name)));
|
|
|
|
# define __gthrw_(name) __gthrw_ ## name
|
2005-11-09 21:57:30 +01:00
|
|
|
#else
|
re PR other/24829 (libobjc testsuite failures)
PR other/24829
PR target/24831
* gthr-dce.h: Do not gthrw-ify pthread_once_init,
pthread_key_delete. From John David Anglin. gthrw-ify
pthread_getunique_np only if it it's not a macro. Delete
UNUSED macro.
(__gthread_objc_condition_allocate, __gthread_objc_condition_deallocate,
__gthread_objc_condition_wait, __gthread_objc_condition_broadcast,
__gthread_objc_condition_signal, __gthread_key_delete): Add
"__attribute__ ((__unused__))" to unused arguments.
(__gthread_recursive_mutex_init_function): Add missing return.
* gthr-dce.h, gthr-tpf.h, gthr-solaris.h, gthr-posix.h,
gthr-posix95.h: Use macro-based approach for name redirection
on targets missing weakref.
From-SVN: r110278
2006-01-26 23:00:28 +01:00
|
|
|
# define __gthrw(name)
|
|
|
|
# define __gthrw_(name) name
|
2005-11-09 21:57:30 +01:00
|
|
|
#endif
|
2004-09-23 22:57:25 +02:00
|
|
|
|
re PR other/24829 (libobjc testsuite failures)
PR other/24829
PR target/24831
* gthr-dce.h: Do not gthrw-ify pthread_once_init,
pthread_key_delete. From John David Anglin. gthrw-ify
pthread_getunique_np only if it it's not a macro. Delete
UNUSED macro.
(__gthread_objc_condition_allocate, __gthread_objc_condition_deallocate,
__gthread_objc_condition_wait, __gthread_objc_condition_broadcast,
__gthread_objc_condition_signal, __gthread_key_delete): Add
"__attribute__ ((__unused__))" to unused arguments.
(__gthread_recursive_mutex_init_function): Add missing return.
* gthr-dce.h, gthr-tpf.h, gthr-solaris.h, gthr-posix.h,
gthr-posix95.h: Use macro-based approach for name redirection
on targets missing weakref.
From-SVN: r110278
2006-01-26 23:00:28 +01:00
|
|
|
__gthrw(pthread_once)
|
|
|
|
__gthrw(pthread_key_create)
|
|
|
|
__gthrw(pthread_key_delete)
|
|
|
|
__gthrw(pthread_getspecific)
|
|
|
|
__gthrw(pthread_setspecific)
|
|
|
|
__gthrw(pthread_create)
|
2004-09-23 22:57:25 +02:00
|
|
|
|
re PR other/24829 (libobjc testsuite failures)
PR other/24829
PR target/24831
* gthr-dce.h: Do not gthrw-ify pthread_once_init,
pthread_key_delete. From John David Anglin. gthrw-ify
pthread_getunique_np only if it it's not a macro. Delete
UNUSED macro.
(__gthread_objc_condition_allocate, __gthread_objc_condition_deallocate,
__gthread_objc_condition_wait, __gthread_objc_condition_broadcast,
__gthread_objc_condition_signal, __gthread_key_delete): Add
"__attribute__ ((__unused__))" to unused arguments.
(__gthread_recursive_mutex_init_function): Add missing return.
* gthr-dce.h, gthr-tpf.h, gthr-solaris.h, gthr-posix.h,
gthr-posix95.h: Use macro-based approach for name redirection
on targets missing weakref.
From-SVN: r110278
2006-01-26 23:00:28 +01:00
|
|
|
__gthrw(pthread_mutex_lock)
|
|
|
|
__gthrw(pthread_mutex_trylock)
|
|
|
|
__gthrw(pthread_mutex_unlock)
|
2006-11-29 14:00:12 +01:00
|
|
|
__gthrw(pthread_mutexattr_init)
|
|
|
|
__gthrw(pthread_mutexattr_settype)
|
|
|
|
__gthrw(pthread_mutexattr_destroy)
|
|
|
|
__gthrw(pthread_mutex_init)
|
2008-03-01 11:46:31 +01:00
|
|
|
__gthrw(pthread_mutex_destroy)
|
2004-09-23 22:57:25 +02:00
|
|
|
|
|
|
|
static inline int
|
|
|
|
__gthread_active_p (void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_once (__gthread_once_t *__once, void (*__func) (void))
|
2004-09-23 22:57:25 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthrw_(pthread_once) (__once, __func);
|
2004-09-23 22:57:25 +02:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
|
2004-09-23 22:57:25 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthrw_(pthread_key_create) (__key, __dtor);
|
2004-09-23 22:57:25 +02:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_key_delete (__gthread_key_t __key)
|
2004-09-23 22:57:25 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthrw_(pthread_key_delete) (__key);
|
2004-09-23 22:57:25 +02:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_getspecific (__gthread_key_t __key)
|
2004-09-23 22:57:25 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthrw_(pthread_getspecific) (__key);
|
2004-09-23 22:57:25 +02:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_setspecific (__gthread_key_t __key, const void *__ptr)
|
2004-09-23 22:57:25 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthrw_(pthread_setspecific) (__key, __ptr);
|
2004-09-23 22:57:25 +02:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-03-01 11:46:31 +01:00
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_mutex_destroy (__gthread_mutex_t *__mutex)
|
2008-03-01 11:46:31 +01:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthrw_(pthread_mutex_destroy) (__mutex);
|
2008-03-01 11:46:31 +01:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-23 22:57:25 +02:00
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_mutex_lock (__gthread_mutex_t *__mutex)
|
2004-09-23 22:57:25 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthrw_(pthread_mutex_lock) (__mutex);
|
2004-09-23 22:57:25 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_mutex_trylock (__gthread_mutex_t *__mutex)
|
2004-09-23 22:57:25 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthrw_(pthread_mutex_trylock) (__mutex);
|
2004-09-23 22:57:25 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_mutex_unlock (__gthread_mutex_t *__mutex)
|
2004-09-23 22:57:25 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthrw_(pthread_mutex_unlock) (__mutex);
|
2004-09-23 22:57:25 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-10-02 02:48:44 +02:00
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
|
2004-10-02 02:48:44 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthread_mutex_lock (__mutex);
|
2004-10-02 02:48:44 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
|
2004-10-02 02:48:44 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthread_mutex_trylock (__mutex);
|
2004-10-02 02:48:44 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
|
2004-10-02 02:48:44 +02:00
|
|
|
{
|
|
|
|
if (__tpf_pthread_active ())
|
2009-02-16 13:19:34 +01:00
|
|
|
return __gthread_mutex_unlock (__mutex);
|
2004-10-02 02:48:44 +02:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-29 14:00:12 +01:00
|
|
|
static inline int
|
2009-02-16 13:19:34 +01:00
|
|
|
__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
|
2009-11-25 11:55:54 +01:00
|
|
|
{
|
2006-11-29 14:00:12 +01:00
|
|
|
if (__tpf_pthread_active ())
|
|
|
|
{
|
2009-02-16 13:19:34 +01:00
|
|
|
pthread_mutexattr_t __attr;
|
|
|
|
int __r;
|
|
|
|
|
|
|
|
__r = __gthrw_(pthread_mutexattr_init) (&__attr);
|
|
|
|
if (!__r)
|
|
|
|
__r = __gthrw_(pthread_mutexattr_settype) (&__attr,
|
|
|
|
PTHREAD_MUTEX_RECURSIVE);
|
|
|
|
if (!__r)
|
|
|
|
__r = __gthrw_(pthread_mutex_init) (__mutex, &__attr);
|
|
|
|
if (!__r)
|
|
|
|
__r = __gthrw_(pthread_mutexattr_destroy) (&__attr);
|
|
|
|
return __r;
|
2006-11-29 14:00:12 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-02 22:22:32 +02:00
|
|
|
static inline int
|
|
|
|
__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
|
|
|
|
{
|
|
|
|
return __gthread_mutex_destroy (__mutex);
|
|
|
|
}
|
2006-11-29 14:00:12 +01:00
|
|
|
|
2004-09-23 22:57:25 +02:00
|
|
|
#endif /* ! GCC_GTHR_TPF_H */
|