------------------------------------------------------------------------------
-- --
--- 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 . A S Y N C _ D E L A Y S --
-- --
-- B o d y --
-- --
--- $Revision: 1.5 $
--- --
--- Copyright (C) 1998-2001 Ada Core Technologies, 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, 59 Temple Place - Suite 330, Boston, --
--- MA 02111-1307, USA. --
+-- or FITNESS FOR A PARTICULAR PURPOSE. --
+-- --
+-- 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. --
-- --
--- 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. --
+-- 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. 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. --
-- --
------------------------------------------------------------------------------
-- Turn off polling, we do not want ATC polling to take place during
-- tasking operations. It causes infinite loops and other problems.
-with Ada.Exceptions;
--- Used for Raise_Exception
+with Ada.Unchecked_Conversion;
+with Ada.Task_Identification;
with System.Task_Primitives.Operations;
--- Used for Write_Lock,
--- Unlock,
--- Self,
--- Monotonic_Clock,
--- Self,
--- Timed_Sleep,
--- Wakeup,
--- Yield
-
with System.Tasking.Utilities;
--- Used for Make_Independent
-
with System.Tasking.Initialization;
--- Used for Defer_Abort
--- Undefer_Abort
-
with System.Tasking.Debug;
--- Used for Trace
-
with System.OS_Primitives;
--- used for Max_Sensible_Delay
-
-with Ada.Task_Identification;
--- used for Task_ID type
-
-with Unchecked_Conversion;
+with System.Interrupt_Management.Operations;
+with System.Parameters;
+with System.Traces.Tasking;
package body System.Tasking.Async_Delays is
package STI renames System.Tasking.Initialization;
package OSP renames System.OS_Primitives;
- function To_System is new Unchecked_Conversion
- (Ada.Task_Identification.Task_Id, Task_ID);
+ use Parameters;
+ use System.Traces;
+ use System.Traces.Tasking;
- Timer_Server_ID : ST.Task_ID;
+ function To_System is new Ada.Unchecked_Conversion
+ (Ada.Task_Identification.Task_Id, Task_Id);
+
+ Timer_Server_ID : ST.Task_Id;
Timer_Attention : Boolean := False;
pragma Atomic (Timer_Attention);
-- remove self from timer queue
STI.Defer_Abort_Nestable (D.Self_Id);
+
+ if Single_Lock then
+ STPO.Lock_RTS;
+ end if;
+
STPO.Write_Lock (Timer_Server_ID);
Dpred := D.Pred;
Dsucc := D.Succ;
STPO.Write_Lock (D.Self_Id);
STU.Exit_One_ATC_Level (D.Self_Id);
STPO.Unlock (D.Self_Id);
+
+ if Single_Lock then
+ STPO.Unlock_RTS;
+ end if;
+
STI.Undefer_Abort_Nestable (D.Self_Id);
end Cancel_Async_Delay;
---------------------------
function Enqueue_Duration
- (T : in Duration;
- D : Delay_Block_Access)
- return Boolean
+ (T : Duration;
+ D : Delay_Block_Access) return Boolean
is
begin
if T <= 0.0 then
return False;
else
+ -- The corresponding call to Undefer_Abort is performed by the
+ -- expanded code (see exp_ch9).
+
STI.Defer_Abort (STPO.Self);
Time_Enqueue
(STPO.Monotonic_Clock
(T : Duration;
D : Delay_Block_Access)
is
- Self_Id : constant Task_ID := STPO.Self;
+ Self_Id : constant Task_Id := STPO.Self;
Q : Delay_Block_Access;
- use type ST.Task_ID;
+ use type ST.Task_Id;
-- for visibility of operator "="
begin
"async delay from within abort-deferred region");
if Self_Id.ATC_Nesting_Level = ATC_Level'Last then
- Ada.Exceptions.Raise_Exception (Storage_Error'Identity,
- "not enough ATC nesting levels");
+ raise Storage_Error with "not enough ATC nesting levels";
end if;
Self_Id.ATC_Nesting_Level := Self_Id.ATC_Nesting_Level + 1;
D.Self_Id := Self_Id;
D.Resume_Time := T;
- STI.Defer_Abort (Self_Id);
+ if Single_Lock then
+ STPO.Lock_RTS;
+ end if;
+
STPO.Write_Lock (Timer_Server_ID);
-- Previously, there was code here to dynamically create
end if;
STPO.Unlock (Timer_Server_ID);
- STI.Undefer_Abort (Self_Id);
+
+ if Single_Lock then
+ STPO.Unlock_RTS;
+ end if;
end Time_Enqueue;
---------------
------------------
task body Timer_Server is
- Next_Wakeup_Time : Duration := Duration'Last;
+ function Get_Next_Wakeup_Time return Duration;
+ -- Used to initialize Next_Wakeup_Time, but also to ensure that
+ -- Make_Independent is called during the elaboration of this task.
+
+ --------------------------
+ -- Get_Next_Wakeup_Time --
+ --------------------------
+
+ function Get_Next_Wakeup_Time return Duration is
+ begin
+ STU.Make_Independent;
+ return Duration'Last;
+ end Get_Next_Wakeup_Time;
+
+ -- Local Declarations
+
+ Next_Wakeup_Time : Duration := Get_Next_Wakeup_Time;
Timedout : Boolean;
Yielded : Boolean;
Now : Duration;
- Dequeued,
- Tpred,
- Tsucc : Delay_Block_Access;
- Dequeued_Task : Task_ID;
+ Dequeued : Delay_Block_Access;
+ Dequeued_Task : Task_Id;
- -- Initialize_Timer_Queue returns null, but has critical side-effects
- -- of initializing the timer queue.
+ pragma Unreferenced (Timedout, Yielded);
begin
Timer_Server_ID := STPO.Self;
- STU.Make_Independent;
+
+ -- Since this package may be elaborated before System.Interrupt,
+ -- we need to call Setup_Interrupt_Mask explicitly to ensure that
+ -- this task has the proper signal mask.
+
+ Interrupt_Management.Operations.Setup_Interrupt_Mask;
-- Initialize the timer queue to empty, and make the wakeup time of the
-- header node be larger than any real wakeup time we will ever use.
loop
STI.Defer_Abort (Timer_Server_ID);
+
+ if Single_Lock then
+ STPO.Lock_RTS;
+ end if;
+
STPO.Write_Lock (Timer_Server_ID);
-- The timer server needs to catch pending aborts after finalization
Timer_Attention := False;
Now := STPO.Monotonic_Clock;
-
while Timer_Queue.Succ.Resume_Time <= Now loop
- -- Dequeue the waiting task from the front of the queue.
+ -- Dequeue the waiting task from the front of the queue
pragma Debug (System.Tasking.Debug.Trace
- ("Timer service: waking up waiting task", 'E'));
+ (Timer_Server_ID, "Timer service: waking up waiting task", 'E'));
Dequeued := Timer_Queue.Succ;
Timer_Queue.Succ := Dequeued.Succ;
-- the timer queue, but that is OK because we always restart the
-- next iteration at the head of the queue.
+ if Parameters.Runtime_Traces then
+ Send_Trace_Info (E_Kill, Dequeued.Self_Id);
+ end if;
+
STPO.Unlock (Timer_Server_ID);
STPO.Write_Lock (Dequeued.Self_Id);
Dequeued_Task := Dequeued.Self_Id;
-- an actual delay in this server.
STPO.Unlock (Timer_Server_ID);
+
+ if Single_Lock then
+ STPO.Unlock_RTS;
+ end if;
+
STI.Undefer_Abort (Timer_Server_ID);
end loop;
end Timer_Server;
------------------------------
begin
- Timer_Queue.Succ := Timer_Queue'Unchecked_Access;
- Timer_Queue.Pred := Timer_Queue'Unchecked_Access;
+ Timer_Queue.Succ := Timer_Queue'Access;
+ Timer_Queue.Pred := Timer_Queue'Access;
Timer_Queue.Resume_Time := Duration'Last;
Timer_Server_ID := To_System (Timer_Server'Identity);
end System.Tasking.Async_Delays;