OSDN Git Service

PR middle-end/49875
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-tposen.adb
index dfa4c03..10cfca2 100644 (file)
@@ -6,25 +6,23 @@
 --                                                                          --
 --                                B o d y                                   --
 --                                                                          --
---         Copyright (C) 1998-2008, Free Software Foundation, Inc.          --
+--         Copyright (C) 1998-2009, Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNARL is free software; you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
--- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
--- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
--- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNARL; see file COPYING.  If not, write --
--- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
--- Boston, MA 02110-1301, USA.                                              --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
 --                                                                          --
--- As a special exception,  if other files  instantiate  generics from this --
--- unit, or you link  this unit with other files  to produce an executable, --
--- this  unit  does not  by itself cause  the resulting  executable  to  be --
--- covered  by the  GNU  General  Public  License.  This exception does not --
--- however invalidate  any other reasons why  the executable file  might be --
--- covered by the  GNU Public License.                                      --
+-- As a special exception 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/>.                                          --
 --                                                                          --
 -- GNARL was developed by the GNARL team at Florida State University.       --
 -- Extensive contributions were provided by Ada Core Technologies, Inc.     --
@@ -233,12 +231,7 @@ package body System.Tasking.Protected_Objects.Single_Entry is
       STPO.Timed_Sleep
         (Self_Id, Wakeup_Time, Mode, Entry_Caller_Sleep, Timedout, Yielded);
 
-      if Timedout then
-         Entry_Call.State := Cancelled;
-      else
-         Entry_Call.State := Done;
-      end if;
-
+      Entry_Call.State := (if Timedout then Cancelled else Done);
       Self_Id.Common.State := Runnable;
    end Wait_For_Completion_With_Timeout;
 
@@ -320,15 +313,9 @@ package body System.Tasking.Protected_Objects.Single_Entry is
       Compiler_Info     : System.Address;
       Entry_Body        : Entry_Body_Access)
    is
-      Init_Priority : Integer := Ceiling_Priority;
    begin
-      if Init_Priority = Unspecified_Priority then
-         Init_Priority := System.Priority'Last;
-      end if;
+      Initialize_Protection (Object.Common'Access, Ceiling_Priority);
 
-      STPO.Initialize_Lock (Init_Priority, Object.L'Access);
-      Object.Ceiling := System.Any_Priority (Init_Priority);
-      Object.Owner := Null_Task;
       Object.Compiler_Info := Compiler_Info;
       Object.Call_In_Progress := null;
       Object.Entry_Body := Entry_Body;
@@ -343,45 +330,8 @@ package body System.Tasking.Protected_Objects.Single_Entry is
    --  Do not call this procedure from within the run-time system.
 
    procedure Lock_Entry (Object : Protection_Entry_Access) is
-      Ceiling_Violation : Boolean;
-
    begin
-      --  If pragma Detect_Blocking is active then, as described in the ARM
-      --  9.5.1, par. 15, we must check whether this is an external call on a
-      --  protected subprogram with the same target object as that of the
-      --  protected action that is currently in progress (i.e., if the caller
-      --  is already the protected object's owner). If this is the case hence
-      --  Program_Error must be raised.
-
-      if Detect_Blocking and then Object.Owner = Self then
-         raise Program_Error;
-      end if;
-
-      STPO.Write_Lock (Object.L'Access, Ceiling_Violation);
-
-      if Ceiling_Violation then
-         raise Program_Error;
-      end if;
-
-      --  We are entering in a protected action, so that we increase the
-      --  protected object nesting level (if pragma Detect_Blocking is
-      --  active), and update the protected object's owner.
-
-      if Detect_Blocking then
-         declare
-            Self_Id : constant Task_Id := Self;
-
-         begin
-            --  Update the protected object's owner
-
-            Object.Owner := Self_Id;
-
-            --  Increase protected object nesting level
-
-            Self_Id.Common.Protected_Action_Nesting :=
-              Self_Id.Common.Protected_Action_Nesting + 1;
-         end;
-      end if;
+      Lock (Object.Common'Access);
    end Lock_Entry;
 
    --------------------------
@@ -393,53 +343,8 @@ package body System.Tasking.Protected_Objects.Single_Entry is
    --  Do not call this procedure from within the runtime system
 
    procedure Lock_Read_Only_Entry (Object : Protection_Entry_Access) is
-      Ceiling_Violation : Boolean;
-
    begin
-      --  If pragma Detect_Blocking is active then, as described in the ARM
-      --  9.5.1, par. 15, we must check whether this is an external call on a
-      --  protected subprogram with the same target object as that of the
-      --  protected action that is currently in progress (i.e., if the caller
-      --  is already the protected object's owner). If this is the case hence
-      --  Program_Error must be raised.
-
-      --  Note that in this case (getting read access), several tasks may
-      --  have read ownership of the protected object, so that this method of
-      --  storing the (single) protected object's owner does not work
-      --  reliably for read locks. However, this is the approach taken for two
-      --  major reasons: first, this function is not currently being used (it
-      --  is provided for possible future use), and second, it largely
-      --  simplifies the implementation.
-
-      if Detect_Blocking and then Object.Owner = Self then
-         raise Program_Error;
-      end if;
-
-      STPO.Read_Lock (Object.L'Access, Ceiling_Violation);
-
-      if Ceiling_Violation then
-         raise Program_Error;
-      end if;
-
-      --  We are entering in a protected action, so that we increase the
-      --  protected object nesting level (if pragma Detect_Blocking is
-      --  active), and update the protected object's owner.
-
-      if Detect_Blocking then
-         declare
-            Self_Id : constant Task_Id := Self;
-
-         begin
-            --  Update the protected object's owner
-
-            Object.Owner := Self_Id;
-
-            --  Increase protected object nesting level
-
-            Self_Id.Common.Protected_Action_Nesting :=
-              Self_Id.Common.Protected_Action_Nesting + 1;
-         end;
-      end if;
+      Lock_Read_Only (Object.Common'Access);
    end Lock_Read_Only_Entry;
 
    --------------------
@@ -667,7 +572,6 @@ package body System.Tasking.Protected_Objects.Single_Entry is
    is
       Self_Id           : constant Task_Id  := STPO.Self;
       Entry_Call        : Entry_Call_Record renames Self_Id.Entry_Calls (1);
-      Ceiling_Violation : Boolean;
 
    begin
       --  If pragma Detect_Blocking is active then Program_Error must be
@@ -680,11 +584,7 @@ package body System.Tasking.Protected_Objects.Single_Entry is
          raise Program_Error with "potentially blocking operation";
       end if;
 
-      STPO.Write_Lock (Object.L'Access, Ceiling_Violation);
-
-      if Ceiling_Violation then
-         raise Program_Error;
-      end if;
+      Lock (Object.Common'Access);
 
       Entry_Call.Mode := Timed_Call;
       Entry_Call.State := Now_Abortable;
@@ -732,32 +632,7 @@ package body System.Tasking.Protected_Objects.Single_Entry is
 
    procedure Unlock_Entry (Object : Protection_Entry_Access) is
    begin
-      --  We are exiting from a protected action, so that we decrease the
-      --  protected object nesting level (if pragma Detect_Blocking is
-      --  active), and remove ownership of the protected object.
-
-      if Detect_Blocking then
-         declare
-            Self_Id : constant Task_Id := Self;
-
-         begin
-            --  Calls to this procedure can only take place when being within
-            --  a protected action and when the caller is the protected
-            --  object's owner.
-
-            pragma Assert (Self_Id.Common.Protected_Action_Nesting > 0
-                             and then Object.Owner = Self_Id);
-
-            --  Remove ownership of the protected object
-
-            Object.Owner := Null_Task;
-
-            Self_Id.Common.Protected_Action_Nesting :=
-              Self_Id.Common.Protected_Action_Nesting - 1;
-         end;
-      end if;
-
-      STPO.Unlock (Object.L'Access);
+      Unlock (Object.Common'Access);
    end Unlock_Entry;
 
 end System.Tasking.Protected_Objects.Single_Entry;