mirror of https://git.codelabs.ch/alog.git
Guard active logger shutdown with protected boolean
Otherwise the procedure might be called multiple times if the Shutdown procedure has been called already but the backend tasks are not terminated yet.
This commit is contained in:
parent
e872fcc367
commit
9d99b8be1b
|
@ -123,8 +123,7 @@ package body Alog.Active_Logger is
|
|||
|
||||
function Is_Terminated (Logger : Instance) return Boolean is
|
||||
begin
|
||||
return Logger.Backend'Terminated
|
||||
and then Logger.Logger_Task'Terminated;
|
||||
return Logger.Terminated.State;
|
||||
end Is_Terminated;
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
|
@ -170,8 +169,13 @@ package body Alog.Active_Logger is
|
|||
(Logger : in out Instance;
|
||||
Flush : Boolean := True)
|
||||
is
|
||||
Is_Terminated : Boolean;
|
||||
begin
|
||||
if Logger.Is_Terminated then
|
||||
Logger.Terminated.Swap
|
||||
(New_State => True,
|
||||
Old_State => Is_Terminated);
|
||||
|
||||
if Is_Terminated then
|
||||
return;
|
||||
end if;
|
||||
|
||||
|
@ -211,6 +215,32 @@ package body Alog.Active_Logger is
|
|||
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
protected body Protected_Boolean
|
||||
is
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
function State return Boolean
|
||||
is
|
||||
begin
|
||||
return S;
|
||||
end State;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
procedure Swap
|
||||
(New_State : Boolean;
|
||||
Old_State : out Boolean)
|
||||
is
|
||||
begin
|
||||
Old_State := S;
|
||||
S := New_State;
|
||||
end Swap;
|
||||
|
||||
end Protected_Boolean;
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
task body Logging_Task is
|
||||
use type Log_Request.Instance;
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ package Alog.Active_Logger is
|
|||
-- procedure will wait for all queued messages to be logged.
|
||||
|
||||
function Is_Terminated (Logger : Instance) return Boolean;
|
||||
-- Returns True if active logger shutdown sequence is complete.
|
||||
-- Returns True if active logger is terminated.
|
||||
|
||||
procedure All_Done (Logger : in out Instance);
|
||||
-- This procedure blocks until all queued logging requests have been
|
||||
|
@ -139,6 +139,21 @@ package Alog.Active_Logger is
|
|||
|
||||
private
|
||||
|
||||
protected type Protected_Boolean (Initial_State : Boolean) is
|
||||
|
||||
function State return Boolean;
|
||||
-- Return current state.
|
||||
|
||||
procedure Swap
|
||||
(New_State : Boolean;
|
||||
Old_State : out Boolean);
|
||||
-- Swap internal state with new state and return old state.
|
||||
|
||||
private
|
||||
S : Boolean := Initial_State;
|
||||
end Protected_Boolean;
|
||||
-- Protected boolean used to guard shutdown procedure.
|
||||
|
||||
task type Logging_Task (Parent : not null access Instance);
|
||||
-- This task takes logging requests from the parent's message queue and
|
||||
-- logs them using the parent's backend logger.
|
||||
|
@ -147,6 +162,7 @@ private
|
|||
Logger_Task : Logging_Task (Parent => Instance'Access);
|
||||
Backend : Tasked_Logger.Instance (Init);
|
||||
Message_Queue : Protected_Containers.Log_Request_List;
|
||||
Terminated : Protected_Boolean (Initial_State => False);
|
||||
end record;
|
||||
|
||||
type Shutdown_Helper (Logger : not null access Instance) is
|
||||
|
|
Loading…
Reference in New Issue