aboutsummaryrefslogtreecommitdiff
path: root/libgcc/gthr-posix.h
diff options
context:
space:
mode:
Diffstat (limited to 'libgcc/gthr-posix.h')
-rw-r--r--libgcc/gthr-posix.h138
1 files changed, 87 insertions, 51 deletions
diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
index 82e8f9f..eeb84f3 100644
--- a/libgcc/gthr-posix.h
+++ b/libgcc/gthr-posix.h
@@ -1,6 +1,6 @@
/* Threads compatibility routines for libgcc2 and libobjc. */
/* Compile this one with gcc. */
-/* Copyright (C) 1997-2024 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2025 Free Software Foundation, Inc.
This file is part of GCC.
@@ -44,6 +44,21 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
# endif
#endif
+#ifdef __has_attribute
+# if __has_attribute(__always_inline__)
+# define __GTHREAD_ALWAYS_INLINE __attribute__((__always_inline__))
+# endif
+#endif
+#ifndef __GTHREAD_ALWAYS_INLINE
+# define __GTHREAD_ALWAYS_INLINE
+#endif
+
+#ifdef __cplusplus
+# define __GTHREAD_INLINE inline __GTHREAD_ALWAYS_INLINE
+#else
+# define __GTHREAD_INLINE static inline
+#endif
+
typedef pthread_t __gthread_t;
typedef pthread_key_t __gthread_key_t;
typedef pthread_once_t __gthread_once_t;
@@ -182,22 +197,30 @@ __gthrw(pthread_setschedparam)
#if defined(__FreeBSD__) || (defined(__sun) && defined(__svr4__))
-static volatile int __gthread_active = -1;
+#pragma GCC visibility push(hidden)
+__GTHREAD_INLINE volatile int *
+__gthread_active (void)
+{
+ static volatile int __gthread_active_var = -1;
+ return &__gthread_active_var;
+}
+#pragma GCC visibility pop
-static void
+__GTHREAD_INLINE void
__gthread_trigger (void)
{
- __gthread_active = 1;
+ *__gthread_active () = 1;
}
-static inline int
+#pragma GCC visibility push(hidden)
+__GTHREAD_INLINE int
__gthread_active_p (void)
{
static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_once_t __gthread_active_once = PTHREAD_ONCE_INIT;
/* Avoid reading __gthread_active twice on the main code path. */
- int __gthread_active_latest_value = __gthread_active;
+ int __gthread_active_latest_value = *__gthread_active ();
/* This test is not protected to avoid taking a lock on the main code
path so every update of __gthread_active in a threaded program must
@@ -214,14 +237,15 @@ __gthread_active_p (void)
}
/* Make sure we'll never enter this block again. */
- if (__gthread_active < 0)
- __gthread_active = 0;
+ if (*__gthread_active () < 0)
+ *__gthread_active () = 0;
- __gthread_active_latest_value = __gthread_active;
+ __gthread_active_latest_value = *__gthread_active ();
}
return __gthread_active_latest_value != 0;
}
+#pragma GCC visibility pop
#else /* neither FreeBSD nor Solaris */
@@ -257,13 +281,15 @@ __gthrw2(__gthrw_(__pthread_key_create),
# define GTHR_ACTIVE_PROXY __gthrw_(pthread_cancel)
#endif
-static inline int
+#pragma GCC visibility push(hidden)
+__GTHREAD_INLINE int
__gthread_active_p (void)
{
static void *const __gthread_active_ptr
= __extension__ (void *) &GTHR_ACTIVE_PROXY;
return __gthread_active_ptr != 0;
}
+#pragma GCC visibility pop
#endif /* FreeBSD or Solaris */
@@ -288,20 +314,27 @@ __gthread_active_p (void)
#if defined(__hppa__) && defined(__hpux__)
-static volatile int __gthread_active = -1;
+#pragma GCC visibility push(hidden)
+__GTHREAD_INLINE volatile int *
+__gthread_active (void)
+{
+ static volatile int __gthread_active_var = -1;
+ return &__gthread_active_var;
+}
+#pragma GCC visibility pop
-static inline int
+__GTHREAD_INLINE int
__gthread_active_p (void)
{
/* Avoid reading __gthread_active twice on the main code path. */
- int __gthread_active_latest_value = __gthread_active;
+ int __gthread_active_latest_value = *__gthread_active ();
size_t __s;
if (__builtin_expect (__gthread_active_latest_value < 0, 0))
{
pthread_default_stacksize_np (0, &__s);
- __gthread_active = __s ? 1 : 0;
- __gthread_active_latest_value = __gthread_active;
+ *__gthread_active () = __s ? 1 : 0;
+ __gthread_active_latest_value = *__gthread_active ();
}
return __gthread_active_latest_value != 0;
@@ -309,7 +342,7 @@ __gthread_active_p (void)
#else /* not hppa-hpux */
-static inline int
+__GTHREAD_INLINE int
__gthread_active_p (void)
{
return 1;
@@ -669,44 +702,44 @@ __gthread_objc_condition_signal (objc_condition_t condition)
#else /* _LIBOBJC */
-static inline int
+__GTHREAD_INLINE int
__gthread_create (__gthread_t *__threadid, void *(*__func) (void*),
void *__args)
{
return __gthrw_(pthread_create) (__threadid, NULL, __func, __args);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_join (__gthread_t __threadid, void **__value_ptr)
{
return __gthrw_(pthread_join) (__threadid, __value_ptr);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_detach (__gthread_t __threadid)
{
return __gthrw_(pthread_detach) (__threadid);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_equal (__gthread_t __t1, __gthread_t __t2)
{
return __gthrw_(pthread_equal) (__t1, __t2);
}
-static inline __gthread_t
+__GTHREAD_INLINE __gthread_t
__gthread_self (void)
{
return __gthrw_(pthread_self) ();
}
-static inline int
+__GTHREAD_INLINE int
__gthread_yield (void)
{
return __gthrw_(sched_yield) ();
}
-static inline int
+__GTHREAD_INLINE int
__gthread_once (__gthread_once_t *__once, void (*__func) (void))
{
if (__gthread_active_p ())
@@ -715,38 +748,38 @@ __gthread_once (__gthread_once_t *__once, void (*__func) (void))
return -1;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
{
return __gthrw_(pthread_key_create) (__key, __dtor);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_key_delete (__gthread_key_t __key)
{
return __gthrw_(pthread_key_delete) (__key);
}
-static inline void *
+__GTHREAD_INLINE void *
__gthread_getspecific (__gthread_key_t __key)
{
return __gthrw_(pthread_getspecific) (__key);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_setspecific (__gthread_key_t __key, const void *__ptr)
{
return __gthrw_(pthread_setspecific) (__key, __ptr);
}
-static inline void
+__GTHREAD_INLINE void
__gthread_mutex_init_function (__gthread_mutex_t *__mutex)
{
if (__gthread_active_p ())
__gthrw_(pthread_mutex_init) (__mutex, NULL);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_mutex_destroy (__gthread_mutex_t *__mutex)
{
if (__gthread_active_p ())
@@ -755,7 +788,7 @@ __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_mutex_lock (__gthread_mutex_t *__mutex)
{
if (__gthread_active_p ())
@@ -764,7 +797,7 @@ __gthread_mutex_lock (__gthread_mutex_t *__mutex)
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_mutex_trylock (__gthread_mutex_t *__mutex)
{
if (__gthread_active_p ())
@@ -774,7 +807,7 @@ __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
}
#if _GTHREAD_USE_MUTEX_TIMEDLOCK
-static inline int
+__GTHREAD_INLINE int
__gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
const __gthread_time_t *__abs_timeout)
{
@@ -785,7 +818,7 @@ __gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
}
#endif
-static inline int
+__GTHREAD_INLINE int
__gthread_mutex_unlock (__gthread_mutex_t *__mutex)
{
if (__gthread_active_p ())
@@ -796,7 +829,7 @@ __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
#if !defined( PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) \
|| defined(_GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC)
-static inline int
+__GTHREAD_INLINE int
__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
{
if (__gthread_active_p ())
@@ -818,20 +851,20 @@ __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
}
#endif
-static inline int
+__GTHREAD_INLINE int
__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
{
return __gthread_mutex_lock (__mutex);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
{
return __gthread_mutex_trylock (__mutex);
}
#if _GTHREAD_USE_MUTEX_TIMEDLOCK
-static inline int
+__GTHREAD_INLINE int
__gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
const __gthread_time_t *__abs_timeout)
{
@@ -839,20 +872,20 @@ __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
}
#endif
-static inline int
+__GTHREAD_INLINE int
__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
{
return __gthread_mutex_unlock (__mutex);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
{
return __gthread_mutex_destroy (__mutex);
}
#ifdef _GTHREAD_USE_COND_INIT_FUNC
-static inline void
+__GTHREAD_INLINE void
__gthread_cond_init_function (__gthread_cond_t *__cond)
{
if (__gthread_active_p ())
@@ -860,46 +893,46 @@ __gthread_cond_init_function (__gthread_cond_t *__cond)
}
#endif
-static inline int
+__GTHREAD_INLINE int
__gthread_cond_broadcast (__gthread_cond_t *__cond)
{
return __gthrw_(pthread_cond_broadcast) (__cond);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_cond_signal (__gthread_cond_t *__cond)
{
return __gthrw_(pthread_cond_signal) (__cond);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
{
return __gthrw_(pthread_cond_wait) (__cond, __mutex);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
const __gthread_time_t *__abs_timeout)
{
return __gthrw_(pthread_cond_timedwait) (__cond, __mutex, __abs_timeout);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_cond_wait_recursive (__gthread_cond_t *__cond,
__gthread_recursive_mutex_t *__mutex)
{
return __gthread_cond_wait (__cond, __mutex);
}
-static inline int
+__GTHREAD_INLINE int
__gthread_cond_destroy (__gthread_cond_t* __cond)
{
return __gthrw_(pthread_cond_destroy) (__cond);
}
#ifndef __cplusplus
-static inline int
+__GTHREAD_INLINE int
__gthread_rwlock_rdlock (__gthread_rwlock_t *__rwlock)
{
if (__gthread_active_p ())
@@ -908,7 +941,7 @@ __gthread_rwlock_rdlock (__gthread_rwlock_t *__rwlock)
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_rwlock_tryrdlock (__gthread_rwlock_t *__rwlock)
{
if (__gthread_active_p ())
@@ -917,7 +950,7 @@ __gthread_rwlock_tryrdlock (__gthread_rwlock_t *__rwlock)
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_rwlock_wrlock (__gthread_rwlock_t *__rwlock)
{
if (__gthread_active_p ())
@@ -926,7 +959,7 @@ __gthread_rwlock_wrlock (__gthread_rwlock_t *__rwlock)
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_rwlock_trywrlock (__gthread_rwlock_t *__rwlock)
{
if (__gthread_active_p ())
@@ -935,7 +968,7 @@ __gthread_rwlock_trywrlock (__gthread_rwlock_t *__rwlock)
return 0;
}
-static inline int
+__GTHREAD_INLINE int
__gthread_rwlock_unlock (__gthread_rwlock_t *__rwlock)
{
if (__gthread_active_p ())
@@ -947,4 +980,7 @@ __gthread_rwlock_unlock (__gthread_rwlock_t *__rwlock)
#endif /* _LIBOBJC */
+#undef __GTHREAD_INLINE
+#undef __GTHREAD_ALWAYS_INLINE
+
#endif /* ! GCC_GTHR_POSIX_H */