File : s-musplo.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . M U L T I P R O C E S S O R S . S P I N _ L O C K S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2010-2016, AdaCore --
10 -- --
11 -- GNARL 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. GNARL 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 -- --
19 -- --
20 -- --
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 ------------------------------------------------------------------------------
28
29 package System.Multiprocessors.Spin_Locks is
30 pragma Preelaborate;
31
32 ---------------
33 -- Spin lock --
34 ---------------
35
36 type Atomic_Flag is mod 2**8;
37 pragma Atomic (Atomic_Flag);
38
39 Unlocked : constant Atomic_Flag := 0;
40
41 type Spin_Lock is limited record
42 Flag : aliased Atomic_Flag := Unlocked;
43 end record;
44 -- The default value of a Spin_Lock is unlocked
45
46 procedure Lock (Slock : in out Spin_Lock);
47 pragma Inline (Lock);
48 -- Loop until lock is acquired
49
50 function Locked (Slock : Spin_Lock) return Boolean;
51 pragma Inline (Locked);
52 -- Return the current state of the lock
53
54 procedure Try_Lock (Slock : in out Spin_Lock; Succeeded : out Boolean);
55 pragma Inline (Try_Lock);
56 -- Return True if the lock has been acquired, otherwise don't wait for the
57 -- lock and return False.
58
59 procedure Unlock (Slock : in out Spin_Lock);
60 pragma Inline (Unlock);
61 -- Release the lock
62
63 end System.Multiprocessors.Spin_Locks;