-/* 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).
#if ASYNC_IO
+/* au->lock has to be held when calling this macro. */
+
#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); \
- T_ERROR (__gthread_cond_broadcast, &(advcond)->signal); \
- INTERN_UNLOCK (&(advcond)->lock); \
+ T_ERROR (__gthread_cond_broadcast, &(advcond)->signal); \
} while (0)
+/* Has to be entered with mutex locked. */
+
#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); \
- if ((advcond)->pending || (condition)){ \
- UNLOCK (mutex); \
+ if ((advcond)->pending || (condition)) \
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: \
- (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{ \
- INTERN_LOCK (&(advcond)->lock); \
(advcond)->pending = 0; \
- INTERN_UNLOCK (&(advcond)->lock); \
} while (0)
#else
struct adv_cond
{
+#if ASYNC_IO
int pending;
- __gthread_mutex_t lock;
__gthread_cond_t signal;
+#endif
};
typedef struct async_unit
{
- pthread_mutex_t lock; /* Lock for manipulating the queue structure. */
- pthread_mutex_t io_lock; /* Lock for doing actual I/O. */
- struct adv_cond work;
- struct adv_cond emptysignal;
- struct st_parameter_dt *pdt;
- pthread_t thread;
- struct transfer_queue *head;
- struct transfer_queue *tail;
+ __gthread_mutex_t io_lock; /* Lock for doing actual I/O. */
+ __gthread_mutex_t lock; /* Lock for manipulating the queue structure. */
+ bool empty;
struct
{
int waiting;
struct adv_cond done;
} id;
- bool empty;
+#if ASYNC_IO
+ struct adv_cond work;
+ struct adv_cond emptysignal;
+ struct st_parameter_dt *pdt;
+ pthread_t thread;
+ struct transfer_queue *head;
+ struct transfer_queue *tail;
struct {
const char *message;
int family;
bool fatal_error;
} error;
-
+#endif
} async_unit;
void init_async_unit (gfc_unit *);