aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/s-fileio.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2014-07-31 14:46:16 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2014-07-31 14:46:16 +0200
commitd780e54fa036407bc057a43f2ebf7d945b80add0 (patch)
tree840e6150c70a5d4987c45efe13a41caf7c171cdc /gcc/ada/s-fileio.adb
parent16b5e0b7c5ddfe3d8722b1ffcfa6d66047f8228f (diff)
downloadgcc-d780e54fa036407bc057a43f2ebf7d945b80add0.zip
gcc-d780e54fa036407bc057a43f2ebf7d945b80add0.tar.gz
gcc-d780e54fa036407bc057a43f2ebf7d945b80add0.tar.bz2
[multiple changes]
2014-07-31 Hristian Kirtchev <kirtchev@adacore.com> * freeze.adb (Freeze_Record_Type): Replace all calls to Is_SPARK_Volatile with Is_Effectively_Volatile and update related comments. * sem_ch3.adb (Analyze_Object_Contract, Process_Discriminants): Replace all calls to Is_SPARK_Volatile with Is_Effectively_Volatile and update related comments. * sem_ch5.adb (Analyze_Iterator_Specification, Analyze_Loop_Parameter_Specification): Replace all calls to Is_SPARK_Volatile with Is_Effectively_Volatile and update related comments. * sem_ch6.adb (Process_Formals): Replace all calls to Is_SPARK_Volatile with Is_Effectively_Volatile and update related comments. * sem_ch12.adb (Instantiate_Object): Replace the call to Is_SPARK_Volatile_Object with Is_Effectively_Volatile_Object and update related comment. * sem_prag.adb (Analyze_External_Property_In_Decl_Part, Analyze_Global_Item): Replace all calls to Is_SPARK_Volatile with Is_Effectively_Volatile and update related comments. * sem_res.adb (Resolve_Actuals, Resolve_Entity_Name): Replace all calls to Is_SPARK_Volatile with Is_Effectively_Volatile and update related comments. * sem_util.adb (Has_Enabled_Property, Variable_Has_Enabled_Property): Replace all calls to Is_SPARK_Volatile with Is_Effectively_Volatile and update related comments. (Is_Effectively_Volatile): New routine. (Is_Effectively_Volatile_Object): New routine. (Is_SPARK_Volatile): Removed. (Is_SPARK_Volatile_Object): Removed. * sem_util.ads (Is_Effectively_Volatile): New routine. (Is_Effectively_Volatile_Object): New routine. (Is_SPARK_Volatile): Removed. (Is_SPARK_Volatile_Object): Removed. 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: r213352
Diffstat (limited to 'gcc/ada/s-fileio.adb')
-rw-r--r--gcc/ada/s-fileio.adb92
1 files changed, 53 insertions, 39 deletions
diff --git a/gcc/ada/s-fileio.adb b/gcc/ada/s-fileio.adb
index 073dbdb..1264279 100644
--- a/gcc/ada/s-fileio.adb
+++ b/gcc/ada/s-fileio.adb
@@ -933,6 +933,11 @@ package body System.File_IO is
pragma Import (C, Get_Case_Sensitive,
"__gnat_get_file_names_case_sensitive");
+ procedure Record_AFCB;
+ -- Create and record new AFCB into the runtime, note that the
+ -- implementation uses the variables below which corresponds to the
+ -- status of the opened file.
+
File_Names_Case_Sensitive : constant Boolean := Get_Case_Sensitive /= 0;
-- Set to indicate whether the operating system convention is for file
-- names to be case sensitive (e.g., in Unix, set True), or not case
@@ -975,6 +980,33 @@ package body System.File_IO is
Encoding : CRTL.Filename_Encoding;
-- Filename encoding specified into the form parameter
+ ------------------
+ -- Record_AFCB --
+ ------------------
+
+ procedure Record_AFCB is
+ begin
+ File_Ptr := AFCB_Allocate (Dummy_FCB);
+
+ File_Ptr.Is_Regular_File :=
+ (is_regular_file (fileno (Stream)) /= 0);
+ File_Ptr.Is_System_File := False;
+ File_Ptr.Text_Encoding := Text_Encoding;
+ File_Ptr.Shared_Status := Shared;
+ File_Ptr.Access_Method := Amethod;
+ File_Ptr.Stream := Stream;
+ File_Ptr.Form :=
+ new String'(Formstr);
+ File_Ptr.Name :=
+ new String'(Fullname (1 .. Full_Name_Len));
+ File_Ptr.Mode := Mode;
+ File_Ptr.Is_Temporary_File := Tempfile;
+ File_Ptr.Encoding := Encoding;
+
+ Chain_File (File_Ptr);
+ Append_Set (File_Ptr);
+ end Record_AFCB;
+
begin
if File_Ptr /= null then
raise Status_Error with "file already open";
@@ -1156,17 +1188,6 @@ 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.
@@ -1175,6 +1196,10 @@ 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;
@@ -1198,6 +1223,9 @@ package body System.File_IO is
and then P.Shared_Status = Yes
then
Stream := P.Stream;
+
+ Record_AFCB;
+
exit;
-- Otherwise one of the files has Shared=Yes and one has
@@ -1214,12 +1242,23 @@ 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;
- -- Open specified file if we did not find an existing stream
+ -- Open specified file if we did not find an existing stream,
+ -- otherwise we just return as there is nothing more to be done.
+
+ if Stream /= NULL_Stream then
+ return;
- if Stream = NULL_Stream then
+ else
Fopen_Mode
(Mode, Text_Encoding in Text_Content_Encoding,
Creat, Amethod, Fopstr);
@@ -1292,32 +1331,7 @@ package body System.File_IO is
-- committed to completing the opening of the file. Allocate block on
-- heap and fill in its fields.
- File_Ptr := AFCB_Allocate (Dummy_FCB);
-
- File_Ptr.Is_Regular_File := (is_regular_file (fileno (Stream)) /= 0);
- File_Ptr.Is_System_File := False;
- File_Ptr.Text_Encoding := Text_Encoding;
- File_Ptr.Shared_Status := Shared;
- File_Ptr.Access_Method := Amethod;
- File_Ptr.Stream := Stream;
- File_Ptr.Form := new String'(Formstr);
- File_Ptr.Name := new String'(Fullname (1 .. Full_Name_Len));
- File_Ptr.Mode := Mode;
- File_Ptr.Is_Temporary_File := Tempfile;
- File_Ptr.Encoding := Encoding;
-
- 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;
+ Record_AFCB;
end Open;
------------------------