Debian Codegraph @

gcc/ada/libgnat/s-atopri.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . A T O M I C _ P R I M I T I V E S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2012-2025, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 package body System.Atomic_Primitives is
33
34 --------------------
35 -- Lock_Free_Read --
36 --------------------
37
38 function Lock_Free_Read (Ptr : Address) return Atomic_Type is
39 function My_Atomic_Load is new Atomic_Load (Atomic_Type);
40
41 begin
42 if Atomic_Type'Atomic_Always_Lock_Free then
43 return My_Atomic_Load (Ptr, Acquire);
44 else
45 raise Program_Error;
46 end if;
47 end Lock_Free_Read;
48
49 -------------------------
50 -- Lock_Free_Try_Write --
51 -------------------------
52
53 function Lock_Free_Try_Write
54 (Ptr : Address;
55 Expected : in out Atomic_Type;
56 Desired : Atomic_Type) return Boolean
57 is
58 function My_Atomic_Compare_Exchange is
59 new Atomic_Compare_Exchange (Atomic_Type);
60
61 begin
62 pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
63 "early returns for performance");
64
65 if Expected /= Desired then
66 if Atomic_Type'Atomic_Always_Lock_Free then
67 return My_Atomic_Compare_Exchange (Ptr, Expected'Address, Desired);
68 else
69 raise Program_Error;
70 end if;
71 end if;
72
73 return True;
74
75 pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
76 end Lock_Free_Try_Write;
77
78 end System.Atomic_Primitives;