aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/s-fileio.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2014-07-31 14:37:03 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2014-07-31 14:37:03 +0200
commit396eb900bbb7deb1243ea6de03fe881234314acb (patch)
treeda507e16b9cb1d5024f943ccf7be402675dd61cf /gcc/ada/s-fileio.adb
parente8cddc3b5a9c50a9c7bd4b58b97f6384bc1aa807 (diff)
downloadgcc-396eb900bbb7deb1243ea6de03fe881234314acb.zip
gcc-396eb900bbb7deb1243ea6de03fe881234314acb.tar.gz
gcc-396eb900bbb7deb1243ea6de03fe881234314acb.tar.bz2
[multiple changes]
2014-07-31 Robert Dewar <dewar@adacore.com> * checks.ads, checks.adb (Activate_Overflow_Check): Do not set flag for unconstrained fpt ops. 2014-07-31 Pascal Obry <obry@adacore.com> * s-fileio.adb (Open): Make sure a shared file gets inserted into the global list atomically. This ensures that the file descriptor won't be freed because another tasks is closing the file. From-SVN: r213349
Diffstat (limited to 'gcc/ada/s-fileio.adb')
-rw-r--r--gcc/ada/s-fileio.adb44
1 files changed, 26 insertions, 18 deletions
diff --git a/gcc/ada/s-fileio.adb b/gcc/ada/s-fileio.adb
index 72f7db8..d4d9a67 100644
--- a/gcc/ada/s-fileio.adb
+++ b/gcc/ada/s-fileio.adb
@@ -29,28 +29,26 @@
-- --
------------------------------------------------------------------------------
-with Ada.Finalization; use Ada.Finalization;
-with Ada.IO_Exceptions; use Ada.IO_Exceptions;
+with Ada.Finalization; use Ada.Finalization;
+with Ada.IO_Exceptions; use Ada.IO_Exceptions;
+with Ada.Unchecked_Deallocation;
with Interfaces.C;
with Interfaces.C_Streams; use Interfaces.C_Streams;
-with System.CRTL;
-
with System.Case_Util; use System.Case_Util;
+with System.CRTL;
with System.OS_Lib;
with System.Soft_Links;
-with Ada.Unchecked_Deallocation;
-
package body System.File_IO is
use System.File_Control_Block;
package SSL renames System.Soft_Links;
- use type Interfaces.C.int;
use type CRTL.size_t;
+ use type Interfaces.C.int;
subtype String_Access is System.OS_Lib.String_Access;
procedure Free (X : in out String_Access) renames System.OS_Lib.Free;
@@ -1162,6 +1160,17 @@ package body System.File_IO is
To_Lower (Fullname (1 .. Full_Name_Len));
end if;
+ -- We need to lock all tasks from this point. This is needed as in
+ -- the case of a shared file we want to ensure that the file is
+ -- inserted into the chain with the shared status. We must be sure
+ -- that this file won't be closed (and then the runtime file
+ -- descriptor removed from the chain and released) before we leave
+ -- this routine.
+
+ -- Take a task lock to protect Open_Files
+
+ SSL.Lock_Task.all;
+
-- If Shared=None or Shared=Yes, then check for the existence of
-- another file with exactly the same full name.
@@ -1170,10 +1179,6 @@ package body System.File_IO is
P : AFCB_Ptr;
begin
- -- Take a task lock to protect Open_Files
-
- SSL.Lock_Task.all;
-
-- Search list of open files
P := Open_Files;
@@ -1213,13 +1218,6 @@ package body System.File_IO is
P := P.Next;
end loop;
-
- SSL.Unlock_Task.all;
-
- exception
- when others =>
- SSL.Unlock_Task.all;
- raise;
end;
end if;
@@ -1314,6 +1312,16 @@ package body System.File_IO is
Chain_File (File_Ptr);
Append_Set (File_Ptr);
+
+ -- We can now safely release the global lock, as the File_Ptr is
+ -- inserted into the global file list.
+
+ SSL.Unlock_Task.all;
+
+ exception
+ when others =>
+ SSL.Unlock_Task.all;
+ raise;
end Open;
------------------------