diff options
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/unit.c | 6 | ||||
-rw-r--r-- | libgfortran/io/unix.c | 3 |
2 files changed, 9 insertions, 0 deletions
diff --git a/libgfortran/io/unit.c b/libgfortran/io/unit.c index bcc1e37e2e3..ef94294526a 100644 --- a/libgfortran/io/unit.c +++ b/libgfortran/io/unit.c @@ -583,14 +583,17 @@ get_unit (st_parameter_dt *dtp, int do_create) } else { + __gthread_mutex_lock (&unit_lock); if (newunit_tos) { dtp->common.unit = newunit_stack[newunit_tos].unit_number; unit = newunit_stack[newunit_tos--].unit; + __gthread_mutex_unlock (&unit_lock); unit->fbuf->act = unit->fbuf->pos = 0; } else { + __gthread_mutex_unlock (&unit_lock); dtp->common.unit = newunit_alloc (); unit = xcalloc (1, sizeof (gfc_unit)); fbuf_init (unit, 128); @@ -603,12 +606,15 @@ get_unit (st_parameter_dt *dtp, int do_create) /* If an internal unit number is passed from the parent to the child it should have been stashed on the newunit_stack ready to be used. Check for it now and return the internal unit if found. */ + __gthread_mutex_lock (&unit_lock); if (newunit_tos && (dtp->common.unit <= NEWUNIT_START) && (dtp->common.unit == newunit_stack[newunit_tos].unit_number)) { unit = newunit_stack[newunit_tos--].unit; + __gthread_mutex_unlock (&unit_lock); return unit; } + __gthread_mutex_unlock (&unit_lock); /* Has to be an external unit. */ dtp->u.p.unit_is_internal = 0; diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index c76b427387a..61e9f7997b2 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -582,6 +582,9 @@ buf_read (unix_stream *s, void *buf, ssize_t nbyte) static ssize_t buf_write (unix_stream *s, const void *buf, ssize_t nbyte) { + if (nbyte == 0) + return 0; + if (s->ndirty == 0) s->buffer_offset = s->logical_offset; |