Skip to content

Commit 9233e60

Browse files
committed
T826-026 Add a generic version of Has_Been_Canceled
to reduce copy/paste.
1 parent fceb876 commit 9233e60

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018-2021, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
18+
package body LSP.Generic_Cancel_Check is
19+
20+
Count : Natural := Max_Skip_Count;
21+
-- Counter to restrict frequency of Request.Canceled checks
22+
23+
-----------------------
24+
-- Has_Been_Canceled --
25+
-----------------------
26+
27+
function Has_Been_Canceled return Boolean is
28+
begin
29+
Count := Count - 1;
30+
31+
if Count = 0 then
32+
Count := Max_Skip_Count;
33+
return Request.Canceled;
34+
else
35+
return False;
36+
end if;
37+
end Has_Been_Canceled;
38+
39+
end LSP.Generic_Cancel_Check;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
------------------------------------------------------------------------------
2+
-- Language Server Protocol --
3+
-- --
4+
-- Copyright (C) 2018-2021, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it under --
7+
-- terms of the GNU General Public License as published by the Free Soft- --
8+
-- ware Foundation; either version 3, or (at your option) any later ver- --
9+
-- sion. This software is distributed in the hope that it will be useful, --
10+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
11+
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
12+
-- License for more details. You should have received a copy of the GNU --
13+
-- General Public License distributed with this software; see file --
14+
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
15+
-- of the license. --
16+
------------------------------------------------------------------------------
17+
--
18+
-- Each server request has an atomic flag to inform the handler that
19+
-- the request has been canceled. But, under a havy load, a frequent atomic
20+
-- checking cound generate overhead. This package provides a function to
21+
-- avoid an extra overhread by reducing atomic flag check frequency.
22+
23+
with LSP.Messages.Server_Requests;
24+
25+
generic
26+
Request : in out LSP.Messages.Server_Requests.Server_Request'Class;
27+
-- A request to check cancelation
28+
Max_Skip_Count : Natural;
29+
-- How much checks to skip before make a real atomic flag check
30+
31+
package LSP.Generic_Cancel_Check is
32+
33+
function Has_Been_Canceled return Boolean
34+
with Inline;
35+
36+
end LSP.Generic_Cancel_Check;

0 commit comments

Comments
 (0)