As analyzed by Steve, on freebsd __gthread_t is a pointer type.
I thought it the cleanest solution to remove the #ifdef in gfc_unit,
make the "self" member a intptr_t and cast the return value of
__gthread_t to that type.

Sorry for breaking bootstrap... the ubiquity of Linux is really
striking here. There are a couple of

Regression-tested on Linux.  FreeBSD should also work, but I'd
like confirmation, if possible. Steve, could you be so kind?

OK for trunk?

Best regards

        Thomas

PR fortran/123512

libgfortran/ChangeLog:

        * io/io.h: Change type of self to intptr_t.
        * io/async.h (LOCK_UNIT): Cast __gthread_self () to intptr_t.
        (TRYLOCK_UNIT): Likewise.
        (OWN_THREAD_ID): Likewise.
diff --git a/libgfortran/io/async.h b/libgfortran/io/async.h
index 265f248950d..03f0546868a 100644
--- a/libgfortran/io/async.h
+++ b/libgfortran/io/async.h
@@ -246,11 +246,11 @@
   } while (0)
 
 
 #define LOCK_UNIT(unit) do {		\
     LOCK (&(unit)->lock);		\
-    (unit)->self = __gthread_self ();	\
+    (unit)->self = (intptr_t) __gthread_self ();	\
   } while (0)
 
 #ifdef __GTHREAD_RWLOCK_INIT
 #define RWLOCK_DEBUG_ADD(rwlock) do {		\
     aio_rwlock_debug *n;				\
@@ -388,15 +388,15 @@
 
 /* When pthreads are not active, we do not touch the lock for locking /
    unlocking; the only use for this is checking for recursion.  */
 
 #define LOCK_UNIT(unit) do {					\
-  if (__gthread_active_p ()) {					\
-    LOCK (&(unit)->lock); (unit)->self = __gthread_self ();	\
-  } else {							\
-    (unit)->self = 1;						\
-  }								\
+    if (__gthread_active_p ()) {					\
+      LOCK (&(unit)->lock); (unit)->self = (intptr_t) __gthread_self (); \
+    } else {								\
+      (unit)->self = 1;							\
+    }									\
   } while(0)
 #else
 
 #define LOCK_UNIT(unit) do { \
     (unit)->self = 1;	     \
@@ -428,11 +428,11 @@
 #define TRYLOCK_UNIT(unit) ({					\
       int res;							\
       if (__gthread_active_p ()) {				\
 	res = __gthread_mutex_trylock (&(unit)->lock);		\
 	if (!res)						\
-	  (unit)->self = __gthread_self ();			\
+	  (unit)->self = (intptr_t) __gthread_self ();		\
       }								\
       else {							\
 	res = (unit)->self;					\
 	(unit)->self = 1;					\
       }								\
@@ -553,11 +553,11 @@ extern __thread gfc_unit *thread_unit;
 
 /* When threading is not active, or there is no thread system, we fake the ID
    to be 1.  */
 
 #ifdef __GTHREADS_CXX0X
-#define OWN_THREAD_ID (__gthread_active_p () ? __gthread_self () : 1)
+#define OWN_THREAD_ID (__gthread_active_p () ? (intptr_t) __gthread_self () : 1)
 #else
 #define OWN_THREAD_ID 1
 #endif
 
 enum aio_do {
diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h
index 029fb6b9414..0458003765f 100644
--- a/libgfortran/io/io.h
+++ b/libgfortran/io/io.h
@@ -726,15 +726,11 @@ typedef struct gfc_unit
      are an unsigned char, EOF, or EOF - 1 used to mark the
      field as not valid.  */
   int last_char;
   bool has_size;
   GFC_IO_INT size_used;
-#ifdef __GTHREADS_CXX0X
-  __gthread_t self;
-#else
-  int self;
-#endif
+  intptr_t self;
 }
 gfc_unit;
 
 typedef struct gfc_saved_unit
 {

Reply via email to