OSDN Git Service

2006-10-31 Ed Schonberg <schonberg@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-taskin.adb
index a9c2a4e..066dbf0 100644 (file)
@@ -1,14 +1,12 @@
 ------------------------------------------------------------------------------
 --                                                                          --
---                GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS               --
+--                 GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                 --
 --                                                                          --
 --                        S Y S T E M . T A S K I N G                       --
 --                                                                          --
 --                                  B o d y                                 --
 --                                                                          --
---                             $Revision$
---                                                                          --
---             Copyright (C) 1991-2001 Florida State University             --
+--          Copyright (C) 1992-2006, 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- --
@@ -18,8 +16,8 @@
 -- 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,  59 Temple Place - Suite 330,  Boston, --
--- MA 02111-1307, USA.                                                      --
+-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
+-- Boston, MA 02110-1301, USA.                                              --
 --                                                                          --
 -- As a special exception,  if other files  instantiate  generics from this --
 -- unit, or you link  this unit with other files  to produce an executable, --
@@ -28,9 +26,8 @@
 -- however invalidate  any other reasons why  the executable file  might be --
 -- covered by the  GNU Public License.                                      --
 --                                                                          --
--- GNARL was developed by the GNARL team at Florida State University. It is --
--- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
--- State University (http://www.gnat.com).                                  --
+-- GNARL was developed by the GNARL team at Florida State University.       --
+-- Extensive contributions were provided by Ada Core Technologies, Inc.     --
 --                                                                          --
 ------------------------------------------------------------------------------
 
@@ -41,42 +38,48 @@ pragma Polling (Off);
 with System.Task_Primitives.Operations;
 --  used for Self
 
-with Unchecked_Deallocation;
---  To recover from failure of ATCB initialization.
-
 with System.Storage_Elements;
 --  Needed for initializing Stack_Info.Size
 
-with System.Parameters;
---  Used for Adjust_Storage_Size
-
 package body System.Tasking is
 
    package STPO renames System.Task_Primitives.Operations;
 
-   procedure Free is new
-     Unchecked_Deallocation (Ada_Task_Control_Block, Task_ID);
+   ---------------------
+   -- Detect_Blocking --
+   ---------------------
+
+   function Detect_Blocking return Boolean is
+      GL_Detect_Blocking : Integer;
+      pragma Import (C, GL_Detect_Blocking, "__gl_detect_blocking");
+      --  Global variable exported by the binder generated file.
+      --  A value equal to 1 indicates that pragma Detect_Blocking is active,
+      --  while 0 is used for the pragma not being present.
+
+   begin
+      return GL_Detect_Blocking = 1;
+   end Detect_Blocking;
 
    ----------
    -- Self --
    ----------
 
-   function Self return Task_ID renames STPO.Self;
+   function Self return Task_Id renames STPO.Self;
 
    ---------------------
    -- Initialize_ATCB --
    ---------------------
 
    procedure Initialize_ATCB
-     (Self_ID          : Task_ID;
+     (Self_ID          : Task_Id;
       Task_Entry_Point : Task_Procedure_Access;
       Task_Arg         : System.Address;
-      Parent           : Task_ID;
+      Parent           : Task_Id;
       Elaborated       : Access_Boolean;
       Base_Priority    : System.Any_Priority;
       Task_Info        : System.Task_Info.Task_Info_Type;
       Stack_Size       : System.Parameters.Size_Type;
-      T                : in out Task_ID;
+      T                : Task_Id;
       Success          : out Boolean) is
    begin
       T.Common.State := Unactivated;
@@ -86,13 +89,13 @@ package body System.Tasking is
       STPO.Initialize_TCB (T, Success);
 
       if not Success then
-         Free (T);
          return;
       end if;
 
       T.Common.Parent := Parent;
       T.Common.Base_Priority := Base_Priority;
       T.Common.Current_Priority := 0;
+      T.Common.Protected_Action_Nesting := 0;
       T.Common.Call := null;
       T.Common.Task_Arg := Task_Arg;
       T.Common.Task_Entry_Point := Task_Entry_Point;
@@ -101,6 +104,9 @@ package body System.Tasking is
       T.Common.Elaborated := Elaborated;
       T.Common.Activation_Failed := False;
       T.Common.Task_Info := Task_Info;
+      T.Common.Global_Task_Lock_Nesting := 0;
+      T.Common.Fall_Back_Handler := null;
+      T.Common.Specific_Handler  := null;
 
       if T.Common.Parent = null then
          --  For the environment task, the adjusted stack size is
@@ -119,44 +125,46 @@ package body System.Tasking is
              (Parameters.Adjust_Storage_Size (Stack_Size));
       end if;
 
-      --  Link the task into the list of all tasks.
+      --  Link the task into the list of all tasks
 
       T.Common.All_Tasks_Link := All_Tasks_List;
       All_Tasks_List := T;
    end Initialize_ATCB;
 
-   Main_Task_Image : aliased String := "main_task";
-   --  Declare a global variable to avoid allocating dynamic memory.
+   ----------------
+   -- Initialize --
+   ----------------
 
-   Main_Priority : Priority;
+   Main_Task_Image : constant String := "main_task";
+   --  Image of environment task
+
+   Main_Priority : Integer;
    pragma Import (C, Main_Priority, "__gl_main_priority");
+   --  Priority for main task. Note that this is of type Integer, not
+   --  Priority, because we use the value -1 to indicate the default
+   --  main priority, and that is of course not in Priority'range.
+
+   Initialized : Boolean := False;
+   --  Used to prevent multiple calls to Initialize
 
-   ----------------------------
-   -- Tasking Initialization --
-   ----------------------------
-
-   --  This block constitutes the first part of the initialization of the
-   --  GNARL. This includes creating data structures to make the initial thread
-   --  into the environment task. The last part of the initialization is done
-   --  in System.Tasking.Initialization or System.Tasking.Restricted.Stages.
-   --  All the initializations used to be in Tasking.Initialization, but this
-   --  is no longer possible with the run time simplification (including
-   --  optimized PO and the restricted run time) since one cannot rely on
-   --  System.Tasking.Initialization being present, as was done before.
-
-begin
-   declare
-      T             : Task_ID;
+   procedure Initialize is
+      T             : Task_Id;
       Success       : Boolean;
       Base_Priority : Any_Priority;
 
    begin
+      if Initialized then
+         return;
+      end if;
+
+      Initialized := True;
+
       --  Initialize Environment Task
 
       if Main_Priority = Unspecified_Priority then
          Base_Priority := Default_Priority;
       else
-         Base_Priority := Main_Priority;
+         Base_Priority := Priority (Main_Priority);
       end if;
 
       Success := True;
@@ -169,11 +177,13 @@ begin
       STPO.Initialize (T);
       STPO.Set_Priority (T, T.Common.Base_Priority);
       T.Common.State := Runnable;
-      T.Common.Task_Image := Main_Task_Image'Unrestricted_Access;
+      T.Common.Task_Image_Len := Main_Task_Image'Length;
+      T.Common.Task_Image (Main_Task_Image'Range) := Main_Task_Image;
 
       --  Only initialize the first element since others are not relevant
       --  in ravenscar mode. Rest of the initialization is done in Init_RTS.
 
       T.Entry_Calls (1).Self := T;
-   end;
+   end Initialize;
+
 end System.Tasking;