-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2007, 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- --
with System.Task_Primitives.Operations;
-- used for Write_Lock
--- Set_Priority
-- Wakeup
-- Unlock
-- Sleep
-- used for Dequeue_Call
-- Dequeue_Head
-with System.Tasking.Debug;
--- used for Trace
-
with System.Parameters;
-- used for Single_Lock
-- Runtime_Traces
with System.Traces.Tasking;
-- used for Send_Trace_Info
-with Unchecked_Conversion;
-
package body System.Tasking.Utilities is
package STPO renames System.Task_Primitives.Operations;
-- Abort_Tasks --
-----------------
- -- Compiler interface only: Do not call from within the RTS,
-
- -- except in the implementation of Ada.Task_Identification.
-- This must be called to implement the abort statement.
-- Much of the actual work of the abort is done by the abortee,
-- via the Abort_Handler signal handler, and propagation of the
P : Task_Id;
begin
+ -- If pragma Detect_Blocking is active then Program_Error must be
+ -- raised if this potentially blocking operation is called from a
+ -- protected action.
+
+ if System.Tasking.Detect_Blocking
+ and then Self_Id.Common.Protected_Action_Nesting > 0
+ then
+ Ada.Exceptions.Raise_Exception
+ (Program_Error'Identity, "potentially blocking operation");
+ end if;
+
Initialization.Defer_Abort_Nestable (Self_Id);
-- ?????
if Parent /= Environment_Task then
- -- We can not lock three tasks at the same time, so defer the
+ -- We cannot lock three tasks at the same time, so defer the
-- operations on the parent.
Parent_Needs_Updating := True;
-- Our parent should wait in Phase 1 of Complete_Master.
Master_Completion_Phase := 1;
- pragma Assert (Self_ID.Awake_Count = 1);
+ pragma Assert (Self_ID.Awake_Count >= 1);
end if;
- -- We are accepting with a terminate alternative.
+ -- We are accepting with a terminate alternative
else
if Self_ID.Open_Accepts = null then
Write_Lock (C);
end loop;
- pragma Assert (P.Awake_Count /= 0);
-
if P.Common.State = Master_Phase_2_Sleep
and then C.Master_of_Task = P.Master_Within
then
C.Awake_Count := C.Awake_Count - 1;
if Task_Completed then
- pragma Assert (Self_ID.Awake_Count = 0);
C.Alive_Count := C.Alive_Count - 1;
end if;
-- C has a parent, P.
loop
- -- Notify P that C has gone passive.
+ -- Notify P that C has gone passive
- P.Awake_Count := P.Awake_Count - 1;
+ if P.Awake_Count > 0 then
+ P.Awake_Count := P.Awake_Count - 1;
+ end if;
if Task_Completed and then C.Alive_Count = 0 then
P.Alive_Count := P.Alive_Count - 1;
Write_Lock (C);
end loop;
- -- P has non-passive dependents.
+ -- P has non-passive dependents
if P.Common.State = Master_Completion_Sleep
and then C.Master_of_Task = P.Master_Within