b1f45884f6
2018-07-25 Nicolas Koenig <koenigni@gcc.gnu.org> Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/25829 * gfortran.texi: Add description of asynchronous I/O. * trans-decl.c (gfc_finish_var_decl): Treat asynchronous variables as volatile. * trans-io.c (gfc_build_io_library_fndecls): Rename st_wait to st_wait_async and change argument spec from ".X" to ".w". (gfc_trans_wait): Pass ID argument via reference. 2018-07-25 Nicolas Koenig <koenigni@gcc.gnu.org> Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/25829 * gfortran.dg/f2003_inquire_1.f03: Add write statement. * gfortran.dg/f2003_io_1.f03: Add wait statement. 2018-07-25 Nicolas Koenig <koenigni@gcc.gnu.org> Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/25829 * Makefile.am: Add async.c to gfor_io_src. Add async.h to gfor_io_headers. * Makefile.in: Regenerated. * gfortran.map: Add _gfortran_st_wait_async. * io/async.c: New file. * io/async.h: New file. * io/close.c: Include async.h. (st_close): Call async_wait for an asynchronous unit. * io/file_pos.c (st_backspace): Likewise. (st_endfile): Likewise. (st_rewind): Likewise. (st_flush): Likewise. * io/inquire.c: Add handling for asynchronous PENDING and ID arguments. * io/io.h (st_parameter_dt): Add async bit. (st_parameter_wait): Correct. (gfc_unit): Add au pointer. (st_wait_async): Add prototype. (transfer_array_inner): Likewise. (st_write_done_worker): Likewise. * io/open.c: Include async.h. (new_unit): Initialize asynchronous unit. * io/transfer.c (async_opt): New struct. (wrap_scalar_transfer): New function. (transfer_integer): Call wrap_scalar_transfer to do the work. (transfer_real): Likewise. (transfer_real_write): Likewise. (transfer_character): Likewise. (transfer_character_wide): Likewise. (transfer_complex): Likewise. (transfer_array_inner): New function. (transfer_array): Call transfer_array_inner. (transfer_derived): Call wrap_scalar_transfer. (data_transfer_init): Check for asynchronous I/O. Perform a wait operation on any pending asynchronous I/O if the data transfer is synchronous. Copy PDT and enqueue thread for data transfer. (st_read_done_worker): New function. (st_read_done): Enqueue transfer or call st_read_done_worker. (st_write_done_worker): New function. (st_write_done): Enqueue transfer or call st_read_done_worker. (st_wait): Document as no-op for compatibility reasons. (st_wait_async): New function. * io/unit.c (insert_unit): Use macros LOCK, UNLOCK and TRYLOCK; add NOTE where necessary. (get_gfc_unit): Likewise. (init_units): Likewise. (close_unit_1): Likewise. Call async_close if asynchronous. (close_unit): Use macros LOCK and UNLOCK. (finish_last_advance_record): Likewise. (newunit_alloc): Likewise. * io/unix.c (find_file): Likewise. (flush_all_units_1): Likewise. (flush_all_units): Likewise. * libgfortran.h (generate_error_common): Add prototype. * runtime/error.c: Include io.h and async.h. (generate_error_common): New function. 2018-07-25 Nicolas Koenig <koenigni@gcc.gnu.org> Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/25829 * testsuite/libgomp.fortran/async_io_1.f90: New test. * testsuite/libgomp.fortran/async_io_2.f90: New test. * testsuite/libgomp.fortran/async_io_3.f90: New test. * testsuite/libgomp.fortran/async_io_4.f90: New test. * testsuite/libgomp.fortran/async_io_5.f90: New test. * testsuite/libgomp.fortran/async_io_6.f90: New test. * testsuite/libgomp.fortran/async_io_7.f90: New test. Co-Authored-By: Thomas Koenig <tkoenig@gcc.gnu.org> From-SVN: r262978
121 lines
2.9 KiB
C
121 lines
2.9 KiB
C
/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
|
|
Contributed by Andy Vaught
|
|
|
|
This file is part of the GNU Fortran 95 runtime library (libgfortran).
|
|
|
|
Libgfortran is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
any later version.
|
|
|
|
Libgfortran is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#include "io.h"
|
|
#include "unix.h"
|
|
#include "async.h"
|
|
#include <limits.h>
|
|
|
|
typedef enum
|
|
{ CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED }
|
|
close_status;
|
|
|
|
static const st_option status_opt[] = {
|
|
{"keep", CLOSE_KEEP},
|
|
{"delete", CLOSE_DELETE},
|
|
{NULL, 0}
|
|
};
|
|
|
|
|
|
extern void st_close (st_parameter_close *);
|
|
export_proto(st_close);
|
|
|
|
void
|
|
st_close (st_parameter_close *clp)
|
|
{
|
|
close_status status;
|
|
gfc_unit *u;
|
|
#if !HAVE_UNLINK_OPEN_FILE
|
|
char *path;
|
|
|
|
path = NULL;
|
|
#endif
|
|
|
|
library_start (&clp->common);
|
|
|
|
status = !(clp->common.flags & IOPARM_CLOSE_HAS_STATUS) ? CLOSE_UNSPECIFIED :
|
|
find_option (&clp->common, clp->status, clp->status_len,
|
|
status_opt, "Bad STATUS parameter in CLOSE statement");
|
|
|
|
u = find_unit (clp->common.unit);
|
|
|
|
if (u && u->au)
|
|
if (async_wait (&(clp->common), u->au))
|
|
{
|
|
library_end ();
|
|
return;
|
|
}
|
|
|
|
if ((clp->common.flags & IOPARM_LIBRETURN_MASK) != IOPARM_LIBRETURN_OK)
|
|
{
|
|
library_end ();
|
|
return;
|
|
}
|
|
|
|
if (u != NULL)
|
|
{
|
|
if (close_share (u) < 0)
|
|
generate_error (&clp->common, LIBERROR_OS, "Problem in CLOSE");
|
|
if (u->flags.status == STATUS_SCRATCH)
|
|
{
|
|
if (status == CLOSE_KEEP)
|
|
generate_error (&clp->common, LIBERROR_BAD_OPTION,
|
|
"Can't KEEP a scratch file on CLOSE");
|
|
#if !HAVE_UNLINK_OPEN_FILE
|
|
path = strdup (u->filename);
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
if (status == CLOSE_DELETE)
|
|
{
|
|
if (u->flags.readonly)
|
|
generate_warning (&clp->common, "STATUS set to DELETE on CLOSE"
|
|
" but file protected by READONLY specifier");
|
|
else
|
|
{
|
|
#if HAVE_UNLINK_OPEN_FILE
|
|
remove (u->filename);
|
|
#else
|
|
path = strdup (u->filename);
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|
|
close_unit (u);
|
|
|
|
#if !HAVE_UNLINK_OPEN_FILE
|
|
if (path != NULL)
|
|
{
|
|
remove (path);
|
|
free (path);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/* CLOSE on unconnected unit is legal and a no-op: F95 std., 9.3.5. */
|
|
library_end ();
|
|
}
|