1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . A T O M I C _ P R I M I T I V E S --
9 -- Copyright (C) 2012, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 package body System.Atomic_Primitives is
34 ----------------------
35 -- Lock_Free_Read_8 --
36 ----------------------
38 function Lock_Free_Read_8 (Ptr : Address) return uint8 is
40 if uint8'Atomic_Always_Lock_Free then
41 return Atomic_Load_8 (Ptr, Acquire);
47 -----------------------
48 -- Lock_Free_Read_16 --
49 -----------------------
51 function Lock_Free_Read_16 (Ptr : Address) return uint16 is
53 if uint16'Atomic_Always_Lock_Free then
54 return Atomic_Load_16 (Ptr, Acquire);
58 end Lock_Free_Read_16;
60 -----------------------
61 -- Lock_Free_Read_32 --
62 -----------------------
64 function Lock_Free_Read_32 (Ptr : Address) return uint32 is
66 if uint32'Atomic_Always_Lock_Free then
67 return Atomic_Load_32 (Ptr, Acquire);
71 end Lock_Free_Read_32;
73 -----------------------
74 -- Lock_Free_Read_64 --
75 -----------------------
77 function Lock_Free_Read_64 (Ptr : Address) return uint64 is
79 if uint64'Atomic_Always_Lock_Free then
80 return Atomic_Load_64 (Ptr, Acquire);
84 end Lock_Free_Read_64;
86 ---------------------------
87 -- Lock_Free_Try_Write_8 --
88 ---------------------------
90 function Lock_Free_Try_Write_8
92 Expected : in out uint8;
93 Desired : uint8) return Boolean
98 if Expected /= Desired then
100 if uint8'Atomic_Always_Lock_Free then
101 Actual := Sync_Compare_And_Swap_8 (Ptr, Expected, Desired);
106 if Actual /= Expected then
113 end Lock_Free_Try_Write_8;
115 ----------------------------
116 -- Lock_Free_Try_Write_16 --
117 ----------------------------
119 function Lock_Free_Try_Write_16
121 Expected : in out uint16;
122 Desired : uint16) return Boolean
127 if Expected /= Desired then
129 if uint16'Atomic_Always_Lock_Free then
130 Actual := Sync_Compare_And_Swap_16 (Ptr, Expected, Desired);
135 if Actual /= Expected then
142 end Lock_Free_Try_Write_16;
144 ----------------------------
145 -- Lock_Free_Try_Write_32 --
146 ----------------------------
148 function Lock_Free_Try_Write_32
150 Expected : in out uint32;
151 Desired : uint32) return Boolean
156 if Expected /= Desired then
158 if uint32'Atomic_Always_Lock_Free then
159 Actual := Sync_Compare_And_Swap_32 (Ptr, Expected, Desired);
164 if Actual /= Expected then
171 end Lock_Free_Try_Write_32;
173 ----------------------------
174 -- Lock_Free_Try_Write_64 --
175 ----------------------------
177 function Lock_Free_Try_Write_64
179 Expected : in out uint64;
180 Desired : uint64) return Boolean
185 if Expected /= Desired then
187 if uint64'Atomic_Always_Lock_Free then
188 Actual := Sync_Compare_And_Swap_64 (Ptr, Expected, Desired);
193 if Actual /= Expected then
200 end Lock_Free_Try_Write_64;
201 end System.Atomic_Primitives;