]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/io/async.h
Update copyright years.
[thirdparty/gcc.git] / libgfortran / io / async.h
index 47081a151519fa911c2ce9eee08c8daebc249a82..527c1a66faddd4c1c40091192bf73265dd25083b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2018 Free Software Foundation, Inc.
+/* Copyright (C) 2018-2021 Free Software Foundation, Inc.
    Contributed by Nicolas Koenig
 
    This file is part of the GNU Fortran runtime library (libgfortran).
    Contributed by Nicolas Koenig
 
    This file is part of the GNU Fortran runtime library (libgfortran).
@@ -29,7 +29,7 @@
    __gthread_cond_t and __gthread_equal / __gthread_self.  Check
    this.  */
 
    __gthread_cond_t and __gthread_equal / __gthread_self.  Check
    this.  */
 
-#if defined(__GTHREAD_HAS_COND) && defined(__GTHREADS_CXX0X) && !defined(_AIX)
+#if defined(__GTHREAD_HAS_COND) && defined(__GTHREADS_CXX0X)
 #define ASYNC_IO 1
 #else
 #define ASYNC_IO 0
 #define ASYNC_IO 1
 #else
 #define ASYNC_IO 0
 
 #if ASYNC_IO
 
 
 #if ASYNC_IO
 
+/* au->lock has to be held when calling this macro.  */
+
 #define SIGNAL(advcond) do{                                            \
 #define SIGNAL(advcond) do{                                            \
-    INTERN_LOCK (&(advcond)->lock);                                    \
     (advcond)->pending = 1;                                            \
     DEBUG_PRINTF ("%s%-75s %20s():%-5d %18p\n", aio_prefix, DEBUG_ORANGE "SIGNAL: " DEBUG_NORM \
                 #advcond, __FUNCTION__, __LINE__, (void *) advcond);   \
     (advcond)->pending = 1;                                            \
     DEBUG_PRINTF ("%s%-75s %20s():%-5d %18p\n", aio_prefix, DEBUG_ORANGE "SIGNAL: " DEBUG_NORM \
                 #advcond, __FUNCTION__, __LINE__, (void *) advcond);   \
-    T_ERROR (__gthread_cond_broadcast, &(advcond)->signal);            \
-    INTERN_UNLOCK (&(advcond)->lock);                                  \
+    T_ERROR (__gthread_cond_broadcast, &(advcond)->signal);                    \
   } while (0)
 
   } while (0)
 
+/* Has to be entered with mutex locked.  */
+
 #define WAIT_SIGNAL_MUTEX(advcond, condition, mutex) do{               \
     __label__ finish;                                                  \
 #define WAIT_SIGNAL_MUTEX(advcond, condition, mutex) do{               \
     __label__ finish;                                                  \
-    INTERN_LOCK (&((advcond)->lock));                                  \
     DEBUG_PRINTF ("%s%-75s %20s():%-5d %18p\n", aio_prefix, DEBUG_BLUE "WAITING: " DEBUG_NORM \
                 #advcond, __FUNCTION__, __LINE__, (void *) advcond);   \
     DEBUG_PRINTF ("%s%-75s %20s():%-5d %18p\n", aio_prefix, DEBUG_BLUE "WAITING: " DEBUG_NORM \
                 #advcond, __FUNCTION__, __LINE__, (void *) advcond);   \
-    if ((advcond)->pending || (condition)){                            \
-      UNLOCK (mutex);                                                  \
+    if ((advcond)->pending || (condition))                             \
       goto finish;                                                     \
       goto finish;                                                     \
-    }                                                                  \
-    UNLOCK (mutex);                                                    \
-     while (!__gthread_cond_wait(&(advcond)->signal, &(advcond)->lock)) {      \
-       { int cond;                                                     \
-        LOCK (mutex); cond = condition; UNLOCK (mutex);        \
-          if (cond){                                                   \
-            DEBUG_PRINTF ("%s%-75s %20s():%-5d %18p\n", aio_prefix, DEBUG_ORANGE "REC: " DEBUG_NORM \
-                 #advcond,  __FUNCTION__, __LINE__, (void *)advcond);  \
-          break;                                                       \
-        }                                                      \
+    while (1)                                                          \
+      {                                                                        \
+       int err_ret = __gthread_cond_wait(&(advcond)->signal, mutex);   \
+       if (err_ret) internal_error (NULL, "WAIT_SIGNAL_MUTEX failed"); \
+       if (condition)                                                  \
+         {                                                             \
+           DEBUG_PRINTF ("%s%-75s %20s():%-5d %18p\n", aio_prefix, DEBUG_ORANGE \
+                         "REC: " DEBUG_NORM                            \
+                         #advcond,  __FUNCTION__, __LINE__, (void *)advcond); \
+           break;                                                      \
+         }                                                             \
       }                                                                        \
       }                                                                        \
-    }                                                                  \
   finish:                                                              \
   finish:                                                              \
-                (advcond)->pending = 0;                                \
-                INTERN_UNLOCK (&((advcond)->lock));                    \
-                } while (0)
+    (advcond)->pending = 0;                                            \
+    UNLOCK (mutex);                                                    \
+  } while (0)
+
+/* au->lock has to be held when calling this macro.  */
 
 #define REVOKE_SIGNAL(advcond) do{             \
 
 #define REVOKE_SIGNAL(advcond) do{             \
-    INTERN_LOCK (&(advcond)->lock);            \
     (advcond)->pending = 0;                    \
     (advcond)->pending = 0;                    \
-    INTERN_UNLOCK (&(advcond)->lock);          \
   } while (0)
 
 #else
   } while (0)
 
 #else
@@ -330,15 +330,14 @@ struct adv_cond
 {
 #if ASYNC_IO
   int pending;
 {
 #if ASYNC_IO
   int pending;
-  __gthread_mutex_t lock;
   __gthread_cond_t signal;
 #endif
 };
 
 typedef struct async_unit
 {
   __gthread_cond_t signal;
 #endif
 };
 
 typedef struct async_unit
 {
-  pthread_mutex_t io_lock;   /* Lock for doing actual I/O. */
-  pthread_mutex_t lock;      /* Lock for manipulating the queue structure.  */
+  __gthread_mutex_t io_lock;   /* Lock for doing actual I/O. */
+  __gthread_mutex_t lock;      /* Lock for manipulating the queue structure.  */
   bool empty;
   struct
   {
   bool empty;
   struct
   {