]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Sync different variants of interrupt handler registration
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 9 Sep 2022 15:49:39 +0000 (17:49 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 23 May 2023 07:58:57 +0000 (09:58 +0200)
This patch propagates the apparently cleanest solutions between various
variants of the runtime units for interrupt handler registration.

In particular, the unnecessary default expressions for list cells with
interrupt handler addresses are removed, the list is changed from
doubly-linked to singly-linked, and assertion preventing registration of
null addresses now appears in all runtimes.

Effectively, it is just a code cleanup and minor optimization; behavior
of the runtime unit is unaffected.

gcc/ada/

* libgnarl/s-interr.adb
(Registered_Handler): Remove default expression.
(Registered_Handlers): Switch to singly-linked list.
(Bind_Interrupt_To_Entry): Sync whitespace with other unit variants.
(Is_Registered): Use singly-linked list.
(Register_Interrupt_Handler): Use singly-linked list and initialized
allocator; sync assertion with other unit variants.
* libgnarl/s-interr__sigaction.adb: Likewise.
* libgnarl/s-interr__vxworks.adb: Likewise.
* libgnarl/s-interr__hwint.adb: Likewise.
(Is_Registered): Remove repeated declaration.

gcc/ada/libgnarl/s-interr.adb
gcc/ada/libgnarl/s-interr__hwint.adb
gcc/ada/libgnarl/s-interr__sigaction.adb
gcc/ada/libgnarl/s-interr__vxworks.adb

index d28c8f9736bb5c17952e96a90260ee7cfdd60f49..7a231681272139763c2c51c010997803d52454a2 100644 (file)
@@ -187,20 +187,23 @@ package body System.Interrupts is
    --  needed to accomplish locking per Interrupt base. Also is needed to
    --  decide whether to create a new Server_Task.
 
-   --  Type and Head, Tail of the list containing Registered Interrupt
-   --  Handlers. These definitions are used to register the handlers
-   --  specified by the pragma Interrupt_Handler.
+   --  Type and the list containing Registered Interrupt Handlers. These
+   --  definitions are used to register the handlers specified by the pragma
+   --  Interrupt_Handler.
+
+   --------------------------
+   -- Handler Registration --
+   --------------------------
 
    type Registered_Handler;
    type R_Link is access all Registered_Handler;
 
    type Registered_Handler is record
-      H    : System.Address := System.Null_Address;
-      Next : R_Link := null;
+      H    : System.Address;
+      Next : R_Link;
    end record;
 
-   Registered_Handler_Head : R_Link := null;
-   Registered_Handler_Tail : R_Link := null;
+   Registered_Handlers : R_Link := null;
 
    Access_Hold : Server_Task_Access;
    --  Variable used to allocate Server_Task using "new"
@@ -254,7 +257,6 @@ package body System.Interrupts is
    is
       Interrupt : constant Interrupt_ID :=
                     Interrupt_ID (Storage_Elements.To_Integer (Int_Ref));
-
    begin
       if Is_Reserved (Interrupt) then
          raise Program_Error with
@@ -538,6 +540,7 @@ package body System.Interrupts is
    -------------------
 
    function Is_Registered (Handler : Parameterless_Handler) return Boolean is
+      Ptr : R_Link := Registered_Handlers;
 
       type Acc_Proc is access procedure;
 
@@ -549,7 +552,6 @@ package body System.Interrupts is
       function To_Fat_Ptr is new Ada.Unchecked_Conversion
         (Parameterless_Handler, Fat_Ptr);
 
-      Ptr : R_Link;
       Fat : Fat_Ptr;
 
    begin
@@ -559,7 +561,6 @@ package body System.Interrupts is
 
       Fat := To_Fat_Ptr (Handler);
 
-      Ptr := Registered_Handler_Head;
       while Ptr /= null loop
          if Ptr.H = Fat.Handler_Addr.all'Address then
             return True;
@@ -600,8 +601,6 @@ package body System.Interrupts is
    ---------------------------------
 
    procedure Register_Interrupt_Handler (Handler_Addr : System.Address) is
-      New_Node_Ptr : R_Link;
-
    begin
       --  This routine registers the Handler as usable for Dynamic Interrupt
       --  Handler. Routines attaching and detaching Handler dynamically should
@@ -615,17 +614,8 @@ package body System.Interrupts is
 
       pragma Assert (Handler_Addr /= System.Null_Address);
 
-      New_Node_Ptr := new Registered_Handler;
-      New_Node_Ptr.H := Handler_Addr;
-
-      if Registered_Handler_Head = null then
-         Registered_Handler_Head := New_Node_Ptr;
-         Registered_Handler_Tail := New_Node_Ptr;
-
-      else
-         Registered_Handler_Tail.Next := New_Node_Ptr;
-         Registered_Handler_Tail := New_Node_Ptr;
-      end if;
+      Registered_Handlers :=
+       new Registered_Handler'(H => Handler_Addr, Next => Registered_Handlers);
    end Register_Interrupt_Handler;
 
    -----------------------
index 4410835a7613792dd57af7d9cd54a72b38e2248b..dcac8e8762eddbbb158e366fcfdae0a81ada9a1c 100644 (file)
@@ -141,20 +141,23 @@ package body System.Interrupts is
    pragma Volatile_Components (User_Entry);
    --  Holds the task and entry index (if any) for each interrupt
 
-   --  Type and Head, Tail of the list containing Registered Interrupt
-   --  Handlers. These definitions are used to register the handlers
-   --  specified by the pragma Interrupt_Handler.
+   --  Type and the list containing Registered Interrupt Handlers. These
+   --  definitions are used to register the handlers specified by the pragma
+   --  Interrupt_Handler.
+
+   --------------------------
+   -- Handler Registration --
+   --------------------------
 
    type Registered_Handler;
    type R_Link is access all Registered_Handler;
 
    type Registered_Handler is record
-      H    : System.Address := System.Null_Address;
-      Next : R_Link := null;
+      H    : System.Address;
+      Next : R_Link;
    end record;
 
-   Registered_Handler_Head : R_Link := null;
-   Registered_Handler_Tail : R_Link := null;
+   Registered_Handlers : R_Link := null;
 
    Server_ID : array (Interrupt_ID) of System.Tasking.Task_Id :=
                  (others => System.Tasking.Null_Task);
@@ -543,6 +546,7 @@ package body System.Interrupts is
    -------------------
 
    function Is_Registered (Handler : Parameterless_Handler) return Boolean is
+      Ptr : R_Link := Registered_Handlers;
 
       type Acc_Proc is access procedure;
 
@@ -554,7 +558,6 @@ package body System.Interrupts is
       function To_Fat_Ptr is new Ada.Unchecked_Conversion
         (Parameterless_Handler, Fat_Ptr);
 
-      Ptr : R_Link;
       Fat : Fat_Ptr;
 
    begin
@@ -564,7 +567,6 @@ package body System.Interrupts is
 
       Fat := To_Fat_Ptr (Handler);
 
-      Ptr := Registered_Handler_Head;
       while Ptr /= null loop
          if Ptr.H = Fat.Handler_Addr.all'Address then
             return True;
@@ -635,8 +637,6 @@ package body System.Interrupts is
    --------------------------------
 
    procedure Register_Interrupt_Handler (Handler_Addr : System.Address) is
-      New_Node_Ptr : R_Link;
-
    begin
       --  This routine registers a handler as usable for dynamic interrupt
       --  handler association. Routines attaching and detaching handlers
@@ -650,16 +650,8 @@ package body System.Interrupts is
 
       pragma Assert (Handler_Addr /= System.Null_Address);
 
-      New_Node_Ptr := new Registered_Handler;
-      New_Node_Ptr.H := Handler_Addr;
-
-      if Registered_Handler_Head = null then
-         Registered_Handler_Head := New_Node_Ptr;
-         Registered_Handler_Tail := New_Node_Ptr;
-      else
-         Registered_Handler_Tail.Next := New_Node_Ptr;
-         Registered_Handler_Tail := New_Node_Ptr;
-      end if;
+      Registered_Handlers :=
+       new Registered_Handler'(H => Handler_Addr, Next => Registered_Handlers);
    end Register_Interrupt_Handler;
 
    -----------------------
index 96916745355de29da97c0299486bba116d817b94..c0398e4edf3d8803c6b72f8528c4bfbb3bb1e7bc 100644 (file)
@@ -91,9 +91,9 @@ package body System.Interrupts is
    pragma Convention (C, Signal_Handler);
    --  This procedure is used to handle all the signals
 
-   --  Type and Head, Tail of the list containing Registered Interrupt
-   --  Handlers. These definitions are used to register the handlers
-   --  specified by the pragma Interrupt_Handler.
+   --  Type and the list containing Registered Interrupt Handlers. These
+   --  definitions are used to register the handlers specified by the pragma
+   --  Interrupt_Handler.
 
    --------------------------
    -- Handler Registration --
@@ -103,8 +103,8 @@ package body System.Interrupts is
    type R_Link is access all Registered_Handler;
 
    type Registered_Handler is record
-      H    : System.Address := System.Null_Address;
-      Next : R_Link := null;
+      H    : System.Address;
+      Next : R_Link;
    end record;
 
    Registered_Handlers : R_Link := null;
@@ -471,6 +471,18 @@ package body System.Interrupts is
 
    procedure Register_Interrupt_Handler (Handler_Addr : System.Address) is
    begin
+      --  This routine registers a handler as usable for dynamic interrupt
+      --  handler association. Routines attaching and detaching handlers
+      --  dynamically should determine whether the handler is registered.
+      --  Program_Error should be raised if it is not registered.
+
+      --  Pragma Interrupt_Handler can only appear in a library level PO
+      --  definition and instantiation. Therefore, we do not need to implement
+      --  an unregister operation. Nor do we need to protect the queue
+      --  structure with a lock.
+
+      pragma Assert (Handler_Addr /= System.Null_Address);
+
       Registered_Handlers :=
        new Registered_Handler'(H => Handler_Addr, Next => Registered_Handlers);
    end Register_Interrupt_Handler;
index 329020dafc2ab40ecc99a786183284415a8fa51b..aade352748faf93aae66e94f167a5a5e00a18171 100644 (file)
@@ -164,20 +164,23 @@ package body System.Interrupts is
    pragma Volatile_Components (User_Entry);
    --  Holds the task and entry index (if any) for each interrupt / signal
 
-   --  Type and Head, Tail of the list containing Registered Interrupt
-   --  Handlers. These definitions are used to register the handlers
-   --  specified by the pragma Interrupt_Handler.
+   --  Type and the list containing Registered Interrupt Handlers. These
+   --  definitions are used to register the handlers specified by the pragma
+   --  Interrupt_Handler.
+
+   --------------------------
+   -- Handler Registration --
+   --------------------------
 
    type Registered_Handler;
    type R_Link is access all Registered_Handler;
 
    type Registered_Handler is record
-      H    : System.Address := System.Null_Address;
-      Next : R_Link := null;
+      H    : System.Address;
+      Next : R_Link;
    end record;
 
-   Registered_Handler_Head : R_Link := null;
-   Registered_Handler_Tail : R_Link := null;
+   Registered_Handlers : R_Link := null;
 
    Server_ID : array (Interrupt_ID) of System.Tasking.Task_Id :=
                  (others => System.Tasking.Null_Task);
@@ -583,6 +586,7 @@ package body System.Interrupts is
    -------------------
 
    function Is_Registered (Handler : Parameterless_Handler) return Boolean is
+      Ptr : R_Link := Registered_Handlers;
 
       type Acc_Proc is access procedure;
 
@@ -594,7 +598,6 @@ package body System.Interrupts is
       function To_Fat_Ptr is new Ada.Unchecked_Conversion
         (Parameterless_Handler, Fat_Ptr);
 
-      Ptr : R_Link;
       Fat : Fat_Ptr;
 
    begin
@@ -604,7 +607,6 @@ package body System.Interrupts is
 
       Fat := To_Fat_Ptr (Handler);
 
-      Ptr := Registered_Handler_Head;
       while Ptr /= null loop
          if Ptr.H = Fat.Handler_Addr.all'Address then
             return True;
@@ -675,8 +677,6 @@ package body System.Interrupts is
    --------------------------------
 
    procedure Register_Interrupt_Handler (Handler_Addr : System.Address) is
-      New_Node_Ptr : R_Link;
-
    begin
       --  This routine registers a handler as usable for dynamic interrupt
       --  handler association. Routines attaching and detaching handlers
@@ -690,16 +690,8 @@ package body System.Interrupts is
 
       pragma Assert (Handler_Addr /= System.Null_Address);
 
-      New_Node_Ptr := new Registered_Handler;
-      New_Node_Ptr.H := Handler_Addr;
-
-      if Registered_Handler_Head = null then
-         Registered_Handler_Head := New_Node_Ptr;
-         Registered_Handler_Tail := New_Node_Ptr;
-      else
-         Registered_Handler_Tail.Next := New_Node_Ptr;
-         Registered_Handler_Tail := New_Node_Ptr;
-      end if;
+      Registered_Handlers :=
+       new Registered_Handler'(H => Handler_Addr, Next => Registered_Handlers);
    end Register_Interrupt_Handler;
 
    -----------------------