update gthr-tpf.h
diff mbox

Message ID 201506020704.t5274Wa4032369@greed.delorie.com
State New
Headers show

Commit Message

DJ Delorie June 2, 2015, 7:04 a.m. UTC
This patch updates gthr-tpf.h to the current gthr.h API and TPF API.  Ok?

	* gthr-tpf.h (__GTHREADS_CXX0X): Define.
	(__gthread_t): Define.
	(__gthread_cond_t): Define.
	(__gthread_time_t): Define.
	(__GTHREAD_HAS_COND): Define.
	(__GTHREAD_COND_INIT): Define.

	(__gthread_active_p): Check __tpf_pthread_active().
	(__gthread_mutex_lock): Remove unneeded conditional.
	(__gthread_mutex_trylock): Likewise.
	(__gthread_recursive_mutex_lock): Likewise.
	(__gthread_recursive_mutex_trylock): Likewise.
	(__gthread_recursive_mutex_unlock): Likewise.
	(__gthread_recursive_mutex_init_function): Likewise.

	(__gthread_join): New.
	(__gthread_detach): New.
	(__gthread_equal): New.
	(__gthread_self): New.
	(__gthread_yield): New.
	(__gthread_mutex_timedlock): New.
	(__gthread_recursive_mutex_timedlock): New.
	(__gthread_cond_broadcast): New.
	(__gthread_cond_signal): New.
	(__gthread_cond_wait): New.
	(__gthread_cond_wait_recursive): New.
	(__gthread_cond_timedwait): New.
	(__gthread_cond_timedwait_recursive): New.
	(__gthread_cond_destroy): New.

Comments

DJ Delorie July 1, 2015, 8:26 p.m. UTC | #1
Ping?
https://gcc.gnu.org/ml/gcc-patches/2015-06/msg00149.html

> This patch updates gthr-tpf.h to the current gthr.h API and TPF API.  Ok?
> 
> 	* gthr-tpf.h (__GTHREADS_CXX0X): Define.
> 	(__gthread_t): Define.
> 	(__gthread_cond_t): Define.
> 	(__gthread_time_t): Define.
> 	(__GTHREAD_HAS_COND): Define.
> 	(__GTHREAD_COND_INIT): Define.
> 
> 	(__gthread_active_p): Check __tpf_pthread_active().
> 	(__gthread_mutex_lock): Remove unneeded conditional.
> 	(__gthread_mutex_trylock): Likewise.
> 	(__gthread_recursive_mutex_lock): Likewise.
> 	(__gthread_recursive_mutex_trylock): Likewise.
> 	(__gthread_recursive_mutex_unlock): Likewise.
> 	(__gthread_recursive_mutex_init_function): Likewise.
> 
> 	(__gthread_join): New.
> 	(__gthread_detach): New.
> 	(__gthread_equal): New.
> 	(__gthread_self): New.
> 	(__gthread_yield): New.
> 	(__gthread_mutex_timedlock): New.
> 	(__gthread_recursive_mutex_timedlock): New.
> 	(__gthread_cond_broadcast): New.
> 	(__gthread_cond_signal): New.
> 	(__gthread_cond_wait): New.
> 	(__gthread_cond_wait_recursive): New.
> 	(__gthread_cond_timedwait): New.
> 	(__gthread_cond_timedwait_recursive): New.
> 	(__gthread_cond_destroy): New.

Patch
diff mbox

Index: libgcc/config/s390/gthr-tpf.h
===================================================================
--- libgcc/config/s390/gthr-tpf.h	(revision 224011)
+++ libgcc/config/s390/gthr-tpf.h	(working copy)
@@ -35,6 +35,8 @@ 
    Easy, since the interface is just one-to-one mapping.  */
 
 #define __GTHREADS 1
+/* To enable the c++0x thread library.  */
+#define __GTHREADS_CXX0X 1
 
 /* Some implementations of <pthread.h> require this to be defined.  */
 #ifndef _REENTRANT
@@ -44,11 +46,17 @@ 
 #include <pthread.h>
 #include <unistd.h>
 
+typedef pthread_t __gthread_t;                        
 typedef pthread_key_t __gthread_key_t;
 typedef pthread_once_t __gthread_once_t;
 typedef pthread_mutex_t __gthread_mutex_t;
 typedef pthread_mutex_t __gthread_recursive_mutex_t;
+typedef pthread_cond_t __gthread_cond_t;             
+typedef struct timespec __gthread_time_t;             
 
+#define __GTHREAD_HAS_COND 1
+#define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
+
 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
@@ -80,9 +88,15 @@ 
 __gthrw(pthread_getspecific)
 __gthrw(pthread_setspecific)
 __gthrw(pthread_create)
+__gthrw(pthread_join)
+__gthrw(pthread_detach)
+__gthrw(pthread_equal)
+__gthrw(pthread_self)
+__gthrw(sched_yield)
 
 __gthrw(pthread_mutex_lock)
 __gthrw(pthread_mutex_trylock)
+__gthrw(pthread_mutex_timedlock) 
 __gthrw(pthread_mutex_unlock)
 __gthrw(pthread_mutexattr_init)
 __gthrw(pthread_mutexattr_settype)
@@ -90,31 +104,81 @@ 
 __gthrw(pthread_mutex_init)
 __gthrw(pthread_mutex_destroy)
 
+__gthrw(pthread_cond_broadcast)
+__gthrw(pthread_cond_signal)
+__gthrw(pthread_cond_wait)
+__gthrw(pthread_cond_timedwait)
+__gthrw(pthread_cond_destroy)
+
+
 static inline int
 __gthread_active_p (void)
 {
-  return 1;
+  return __tpf_pthread_active ();
 }
 
 static inline int
-__gthread_once (__gthread_once_t *__once, void (*__func) (void))
+__gthread_create (__gthread_t *__threadid, void *(*__func) (void*),
+		  void *__args)
 {
+  return __gthrw_(pthread_create) (__threadid, NULL, __func, __args);
+}
+
+static inline int
+__gthread_join (__gthread_t __threadid, void **__value_ptr)
+{
   if (__tpf_pthread_active ())
-    return __gthrw_(pthread_once) (__once, __func);
+    return __gthrw_(pthread_join) (__threadid, __value_ptr);
   else
     return -1;
 }
 
 static inline int
-__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
+__gthread_detach (__gthread_t __threadid)
 {
   if (__tpf_pthread_active ())
-    return __gthrw_(pthread_key_create) (__key, __dtor);
+    return __gthrw_(pthread_detach) (__threadid);
   else
     return -1;
 }
 
 static inline int
+__gthread_equal (__gthread_t __t1, __gthread_t __t2)
+{
+  if (__tpf_pthread_active ())
+    return __gthrw_(pthread_equal) (__t1, __t2);
+  else
+    return -1;
+}
+
+static inline __gthread_t
+__gthread_self (void)
+{
+  return __gthrw_(pthread_self) ();
+}
+
+static inline int
+__gthread_yield (void)
+{
+  return __gthrw_(sched_yield) ();
+}
+
+static inline int
+__gthread_once (__gthread_once_t *__once, void (*__func) (void))
+{
+  if (__tpf_pthread_active ())
+    return __gthrw_(pthread_once) (__once, __func);
+  else
+    return -1;
+}
+
+static inline int
+__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
+{
+  return __gthrw_(pthread_key_create) (__key, __dtor);
+}
+
+static inline int
 __gthread_key_delete (__gthread_key_t __key)
 {
   if (__tpf_pthread_active ())
@@ -153,22 +217,23 @@ 
 static inline int
 __gthread_mutex_lock (__gthread_mutex_t *__mutex)
 {
-  if (__tpf_pthread_active ())
-    return __gthrw_(pthread_mutex_lock) (__mutex);
-  else
-    return 0;
+  return __gthrw_(pthread_mutex_lock) (__mutex);
 }
 
 static inline int
 __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
 {
-  if (__tpf_pthread_active ())
-    return __gthrw_(pthread_mutex_trylock) (__mutex);
-  else
-    return 0;
+  return __gthrw_(pthread_mutex_trylock) (__mutex);
 }
 
 static inline int
+__gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
+			   const __gthread_time_t *__abs_timeout)
+{
+  return __gthrw_(pthread_mutex_timedlock) (__mutex, __abs_timeout);
+}
+
+static inline int
 __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
 {
   if (__tpf_pthread_active ())
@@ -180,49 +245,43 @@ 
 static inline int
 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
 {
-  if (__tpf_pthread_active ())
-    return __gthread_mutex_lock (__mutex);
-  else
-    return 0;
+  return __gthread_mutex_lock (__mutex);
 }
 
 static inline int
 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
 {
-  if (__tpf_pthread_active ())
-    return __gthread_mutex_trylock (__mutex);
-  else
-    return 0;
+  return __gthread_mutex_trylock (__mutex);
 }
 
 static inline int
+__gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
+				     const __gthread_time_t *__abs_timeout)
+{
+  return __gthread_mutex_timedlock (__mutex, __abs_timeout);
+}
+
+static inline int
 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
 {
-  if (__tpf_pthread_active ())
-    return __gthread_mutex_unlock (__mutex);
-  else
-    return 0;
+  return __gthread_mutex_unlock (__mutex);
 }
 
 static inline int
 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
 {
-  if (__tpf_pthread_active ())
-    {
-      pthread_mutexattr_t __attr;
-      int __r;
+  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;
-    }
-  return 0;
+  __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;
 }
 
 static inline int
@@ -231,4 +290,53 @@ 
   return __gthread_mutex_destroy (__mutex);
 }
 
+static inline int
+__gthread_cond_broadcast (__gthread_cond_t *__cond)
+{
+  return __gthrw_(pthread_cond_broadcast) (__cond);
+}
+
+static inline int
+__gthread_cond_signal (__gthread_cond_t *__cond)
+{
+  return __gthrw_(pthread_cond_signal) (__cond);
+}
+
+static inline int
+__gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
+{
+  return __gthrw_(pthread_cond_wait) (__cond, __mutex);
+}
+
+static 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_cond_wait_recursive (__gthread_cond_t *__cond,
+			       __gthread_recursive_mutex_t *__mutex)
+{
+  return __gthread_cond_wait (__cond, __mutex);
+}
+
+static inline int
+__gthread_cond_timedwait_recursive (__gthread_cond_t *__cond,
+				    __gthread_recursive_mutex_t *__mutex,
+				    const __gthread_time_t *__abs_timeout)
+{
+  return __gthread_cond_timedwait (__cond, __mutex, __abs_timeout);
+}
+
+static inline int
+__gthread_cond_destroy (__gthread_cond_t* __cond)
+{
+  if (__tpf_pthread_active ())
+    return __gthrw_(pthread_cond_destroy) (__cond);
+  else
+    return 0;
+}
+
 #endif /* ! GCC_GTHR_TPF_H */