File : s-mufalo.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 . F A I R _ 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 with System.Multiprocessors.Spin_Locks;
  30 
  31 package System.Multiprocessors.Fair_Locks is
  32    pragma Preelaborate;
  33 
  34    --  Note: The locks implemented in this package are fair among CPUs. Using
  35    --  this package to synchronize tasks assigned to the same CPU may result
  36    --  in a dead lock.
  37 
  38    ---------------
  39    -- Fair lock --
  40    ---------------
  41 
  42    type Spinning_Array is array (CPU) of Boolean;
  43    pragma Volatile_Components (Spinning_Array);
  44 
  45    type Fair_Lock is limited record
  46       Spinning : Spinning_Array := (others => False);
  47       Lock     : Spin_Locks.Spin_Lock;
  48    end record;
  49    --  Note: the default value of a Fair_Lock is the unlocked state
  50 
  51    procedure Initialize (Flock : in out Fair_Lock);
  52    pragma Inline (Initialize);
  53    --  Initialize the lock
  54 
  55    procedure Lock (Flock : in out Fair_Lock);
  56    pragma Inline (Lock);
  57    --  Loop until lock is acquired
  58 
  59    function Locked (Flock : Fair_Lock) return Boolean;
  60    pragma Inline (Locked);
  61    --  Return the current state of the lock
  62 
  63    procedure Try_Lock (Flock : in out Fair_Lock; Succeeded : out Boolean);
  64    pragma Inline (Try_Lock);
  65    --  Return True if the lock has been acquired, otherwise don't wait for the
  66    --  lock and return False.
  67 
  68    procedure Unlock (Flock : in out Fair_Lock);
  69    pragma Inline (Unlock);
  70    --  Release the lock and wake up the next waiting CPU (if any)
  71 
  72 end System.Multiprocessors.Fair_Locks;