annotate gcc/ada/libgnat/s-atopri.ads @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . A T O M I C _ P R I M I T I V E S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 2012-2017, Free Software Foundation, Inc. --
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package contains both atomic primitives defined from gcc built-in
kono
parents:
diff changeset
33 -- functions and operations used by the compiler to generate the lock-free
kono
parents:
diff changeset
34 -- implementation of protected objects.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 package System.Atomic_Primitives is
kono
parents:
diff changeset
37 pragma Preelaborate;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 type uint is mod 2 ** Long_Integer'Size;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 type uint8 is mod 2**8
kono
parents:
diff changeset
42 with Size => 8;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 type uint16 is mod 2**16
kono
parents:
diff changeset
45 with Size => 16;
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 type uint32 is mod 2**32
kono
parents:
diff changeset
48 with Size => 32;
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 type uint64 is mod 2**64
kono
parents:
diff changeset
51 with Size => 64;
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 Relaxed : constant := 0;
kono
parents:
diff changeset
54 Consume : constant := 1;
kono
parents:
diff changeset
55 Acquire : constant := 2;
kono
parents:
diff changeset
56 Release : constant := 3;
kono
parents:
diff changeset
57 Acq_Rel : constant := 4;
kono
parents:
diff changeset
58 Seq_Cst : constant := 5;
kono
parents:
diff changeset
59 Last : constant := 6;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 subtype Mem_Model is Integer range Relaxed .. Last;
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 ------------------------------------
kono
parents:
diff changeset
64 -- GCC built-in atomic primitives --
kono
parents:
diff changeset
65 ------------------------------------
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 function Atomic_Load_8
kono
parents:
diff changeset
68 (Ptr : Address;
kono
parents:
diff changeset
69 Model : Mem_Model := Seq_Cst) return uint8;
kono
parents:
diff changeset
70 pragma Import (Intrinsic, Atomic_Load_8, "__atomic_load_1");
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 function Atomic_Load_16
kono
parents:
diff changeset
73 (Ptr : Address;
kono
parents:
diff changeset
74 Model : Mem_Model := Seq_Cst) return uint16;
kono
parents:
diff changeset
75 pragma Import (Intrinsic, Atomic_Load_16, "__atomic_load_2");
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 function Atomic_Load_32
kono
parents:
diff changeset
78 (Ptr : Address;
kono
parents:
diff changeset
79 Model : Mem_Model := Seq_Cst) return uint32;
kono
parents:
diff changeset
80 pragma Import (Intrinsic, Atomic_Load_32, "__atomic_load_4");
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 function Atomic_Load_64
kono
parents:
diff changeset
83 (Ptr : Address;
kono
parents:
diff changeset
84 Model : Mem_Model := Seq_Cst) return uint64;
kono
parents:
diff changeset
85 pragma Import (Intrinsic, Atomic_Load_64, "__atomic_load_8");
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 function Sync_Compare_And_Swap_8
kono
parents:
diff changeset
88 (Ptr : Address;
kono
parents:
diff changeset
89 Expected : uint8;
kono
parents:
diff changeset
90 Desired : uint8) return uint8;
kono
parents:
diff changeset
91 pragma Import (Intrinsic,
kono
parents:
diff changeset
92 Sync_Compare_And_Swap_8,
kono
parents:
diff changeset
93 "__sync_val_compare_and_swap_1");
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 -- ??? Should use __atomic_compare_exchange_1 (doesn't work yet):
kono
parents:
diff changeset
96 -- function Sync_Compare_And_Swap_8
kono
parents:
diff changeset
97 -- (Ptr : Address;
kono
parents:
diff changeset
98 -- Expected : Address;
kono
parents:
diff changeset
99 -- Desired : uint8;
kono
parents:
diff changeset
100 -- Weak : Boolean := False;
kono
parents:
diff changeset
101 -- Success_Model : Mem_Model := Seq_Cst;
kono
parents:
diff changeset
102 -- Failure_Model : Mem_Model := Seq_Cst) return Boolean;
kono
parents:
diff changeset
103 -- pragma Import (Intrinsic,
kono
parents:
diff changeset
104 -- Sync_Compare_And_Swap_8,
kono
parents:
diff changeset
105 -- "__atomic_compare_exchange_1");
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 function Sync_Compare_And_Swap_16
kono
parents:
diff changeset
108 (Ptr : Address;
kono
parents:
diff changeset
109 Expected : uint16;
kono
parents:
diff changeset
110 Desired : uint16) return uint16;
kono
parents:
diff changeset
111 pragma Import (Intrinsic,
kono
parents:
diff changeset
112 Sync_Compare_And_Swap_16,
kono
parents:
diff changeset
113 "__sync_val_compare_and_swap_2");
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 function Sync_Compare_And_Swap_32
kono
parents:
diff changeset
116 (Ptr : Address;
kono
parents:
diff changeset
117 Expected : uint32;
kono
parents:
diff changeset
118 Desired : uint32) return uint32;
kono
parents:
diff changeset
119 pragma Import (Intrinsic,
kono
parents:
diff changeset
120 Sync_Compare_And_Swap_32,
kono
parents:
diff changeset
121 "__sync_val_compare_and_swap_4");
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 function Sync_Compare_And_Swap_64
kono
parents:
diff changeset
124 (Ptr : Address;
kono
parents:
diff changeset
125 Expected : uint64;
kono
parents:
diff changeset
126 Desired : uint64) return uint64;
kono
parents:
diff changeset
127 pragma Import (Intrinsic,
kono
parents:
diff changeset
128 Sync_Compare_And_Swap_64,
kono
parents:
diff changeset
129 "__sync_val_compare_and_swap_8");
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 --------------------------
kono
parents:
diff changeset
132 -- Lock-free operations --
kono
parents:
diff changeset
133 --------------------------
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 -- The lock-free implementation uses two atomic instructions for the
kono
parents:
diff changeset
136 -- expansion of protected operations:
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 -- * Lock_Free_Read_N atomically loads the value of the protected component
kono
parents:
diff changeset
139 -- accessed by the current protected operation.
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 -- * Lock_Free_Try_Write_N tries to write the Desired value into Ptr only
kono
parents:
diff changeset
142 -- if Expected and Desired mismatch.
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 function Lock_Free_Read_8 (Ptr : Address) return uint8;
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 function Lock_Free_Read_16 (Ptr : Address) return uint16;
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 function Lock_Free_Read_32 (Ptr : Address) return uint32;
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 function Lock_Free_Read_64 (Ptr : Address) return uint64;
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 function Lock_Free_Try_Write_8
kono
parents:
diff changeset
153 (Ptr : Address;
kono
parents:
diff changeset
154 Expected : in out uint8;
kono
parents:
diff changeset
155 Desired : uint8) return Boolean;
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 function Lock_Free_Try_Write_16
kono
parents:
diff changeset
158 (Ptr : Address;
kono
parents:
diff changeset
159 Expected : in out uint16;
kono
parents:
diff changeset
160 Desired : uint16) return Boolean;
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 function Lock_Free_Try_Write_32
kono
parents:
diff changeset
163 (Ptr : Address;
kono
parents:
diff changeset
164 Expected : in out uint32;
kono
parents:
diff changeset
165 Desired : uint32) return Boolean;
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 function Lock_Free_Try_Write_64
kono
parents:
diff changeset
168 (Ptr : Address;
kono
parents:
diff changeset
169 Expected : in out uint64;
kono
parents:
diff changeset
170 Desired : uint64) return Boolean;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 pragma Inline (Lock_Free_Read_8);
kono
parents:
diff changeset
173 pragma Inline (Lock_Free_Read_16);
kono
parents:
diff changeset
174 pragma Inline (Lock_Free_Read_32);
kono
parents:
diff changeset
175 pragma Inline (Lock_Free_Read_64);
kono
parents:
diff changeset
176 pragma Inline (Lock_Free_Try_Write_8);
kono
parents:
diff changeset
177 pragma Inline (Lock_Free_Try_Write_16);
kono
parents:
diff changeset
178 pragma Inline (Lock_Free_Try_Write_32);
kono
parents:
diff changeset
179 pragma Inline (Lock_Free_Try_Write_64);
kono
parents:
diff changeset
180 end System.Atomic_Primitives;