From patchwork Tue May 23 08:08:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 97845 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1974225vqo; Tue, 23 May 2023 01:12:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6joY0dZ2vN+b4Uk7dK6oDAIXnYjMayZ6nVjS6ztKf5GhCFAcLuGdr+zESf7U+zw7IyBm1m X-Received: by 2002:a17:906:da8b:b0:970:1a68:bacc with SMTP id xh11-20020a170906da8b00b009701a68baccmr3163416ejb.67.1684829566250; Tue, 23 May 2023 01:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684829566; cv=none; d=google.com; s=arc-20160816; b=tRmM7TENkzoZrYDmh8CF8E8JlocX/ENjBEPJqQTEmpUZUUHyhgBWQkThSWcbwdGWi0 mOMc/Ob1yKA0tMmDPjgAsA94f6osNMoTu7XKBE05nRq439J5fBIgzmGuSh7xY21eL24s S5GySzLtjyDeik+QQ2TOaes0ZNTYFx93utPbmroNfis3847TCgvmJ7sGuB9Hc+/bHR+R bcJ3cR0osfa3n1Rj+5hxnSMYMLDZToFpyWa72mqbBGPhyp1mApuvS1LZVacg+B4OvFSt Q9yQqW1geph4huW00MyLd/vu0uYPLQ0KeuITEkc6HzHVkaKIJ+HYi7lgn6SliUSjw8G1 diUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=n8BnEFt/EozXbv6MBa6AXG7T1Ys2i4tgPY4Clj3YYc8=; b=P19Ee9jBcid1hQouIqesKgOtiqDm+hZpxa84G+y9FPeoL7TDNKPAlaVjxYHGKHxP58 vwDZJUU9dG61/cIRPSGB4N2BCEDUeOidu1RQBp1NXZmy8gtLJwk+8xeoET3Nk5oAyyIa 6BjMhs4oBhEcLBK994RjI6HRP+WbUPIpF6zOROdiv6kMah3u/wGM21iOZGDiEVFMEaN6 zyijhgoH0R0RAFr8C8OzGLT/nDRwB83Eoz86L0XUhFLnuaJACI8PL6z6vAwUudCurgmr p8Vg7kg3YNXmHsDywXCtn4OoXzAnZH/k7NcDEw0subt5fKRNr2aE3RZQfs4bhUR5sKMZ y6bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GCcNS7Yu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a13-20020aa7cf0d000000b0050572338dc4si1218179edy.244.2023.05.23.01.12.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:12:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GCcNS7Yu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B285D388B6A3 for ; Tue, 23 May 2023 08:10:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B285D388B6A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684829405; bh=n8BnEFt/EozXbv6MBa6AXG7T1Ys2i4tgPY4Clj3YYc8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=GCcNS7YuH6um+pOftKPoU/jL1xhsQClNjUJedjJJmaUxRKJxxcPH2sLUORmtcdi+P nizxENm6vc1WsCSY654YrW35Jp+3j6hM7oBSF9uuctsRGXHXd2YcLHOhmYHvm9bna3 YtDZhfRWIps9S2BkCSlACvXQNJB5T2wkKC0AihdQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 074863857725 for ; Tue, 23 May 2023 08:08:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 074863857725 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-30a8dc89c33so1581241f8f.0 for ; Tue, 23 May 2023 01:08:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684829284; x=1687421284; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=n8BnEFt/EozXbv6MBa6AXG7T1Ys2i4tgPY4Clj3YYc8=; b=hXvgBr5ZwDHznFSHDUSKGYFGND4sEbzkf9+gqbQxfCWHP8zjJvOqoPvtvk6nxsUvVb z2FXAH96c0FGTbtVQi6uAI+tG6HNWkgfn/at1JPuiZJZ4AQAgz4qtEdfWf4MWLjGFGyA tYRGDyBdsio6dLXy6RbWRonBoctU8tzz+/Tn5eZpMV42/U8mxzNkfuNk8prZh0rur65U 7di6t8Kee0y5uHTGENyjjcZfQlL5+bPf1WRtFeikLmn4Kf6I4iLCxwRBKPNMdaeKdBub 5sCerg+WFYZL0sPRAovQjyKJgJbC+Olx2IwVvygJElxeQSo5LQy6zUeeZaf6o4HY+qsZ NoXQ== X-Gm-Message-State: AC+VfDyvBJKXDp/+o8es71Ug7jWHlwBJ6TXeymi+hDC9Phn8FZgBrtOE OaG2EWsoTTNZ2j1Z6hdPz+3J7G8yZm4rlUwwWI9QCQ== X-Received: by 2002:adf:ec0b:0:b0:302:5d34:38a7 with SMTP id x11-20020adfec0b000000b003025d3438a7mr9338790wrn.36.1684829283774; Tue, 23 May 2023 01:08:03 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id l18-20020adffe92000000b003093a412310sm10138306wrr.92.2023.05.23.01.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:08:03 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Sync different variants of interrupt handler registration Date: Tue, 23 May 2023 10:08:02 +0200 Message-Id: <20230523080802.1873289-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766671847127645946?= X-GMAIL-MSGID: =?utf-8?q?1766671847127645946?= From: Piotr Trojanek 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. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/libgnarl/s-interr.adb | 36 +++++++++--------------- gcc/ada/libgnarl/s-interr__hwint.adb | 34 +++++++++------------- gcc/ada/libgnarl/s-interr__sigaction.adb | 22 +++++++++++---- gcc/ada/libgnarl/s-interr__vxworks.adb | 34 +++++++++------------- 4 files changed, 56 insertions(+), 70 deletions(-) diff --git a/gcc/ada/libgnarl/s-interr.adb b/gcc/ada/libgnarl/s-interr.adb index d28c8f9736b..7a231681272 100644 --- a/gcc/ada/libgnarl/s-interr.adb +++ b/gcc/ada/libgnarl/s-interr.adb @@ -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; ----------------------- diff --git a/gcc/ada/libgnarl/s-interr__hwint.adb b/gcc/ada/libgnarl/s-interr__hwint.adb index 4410835a761..dcac8e8762e 100644 --- a/gcc/ada/libgnarl/s-interr__hwint.adb +++ b/gcc/ada/libgnarl/s-interr__hwint.adb @@ -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; ----------------------- diff --git a/gcc/ada/libgnarl/s-interr__sigaction.adb b/gcc/ada/libgnarl/s-interr__sigaction.adb index 96916745355..c0398e4edf3 100644 --- a/gcc/ada/libgnarl/s-interr__sigaction.adb +++ b/gcc/ada/libgnarl/s-interr__sigaction.adb @@ -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; diff --git a/gcc/ada/libgnarl/s-interr__vxworks.adb b/gcc/ada/libgnarl/s-interr__vxworks.adb index 329020dafc2..aade352748f 100644 --- a/gcc/ada/libgnarl/s-interr__vxworks.adb +++ b/gcc/ada/libgnarl/s-interr__vxworks.adb @@ -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; -----------------------