File : bc-containers-maps-unbounded-guarded.adb


-- Copyright (C) 1994-2000 Grady Booch and Simon Wright.
-- All Rights Reserved.
--
--      This program is free software; you can redistribute it
--      and/or modify it under the terms of the Ada Community
--      License which comes with this Library.
--
--      This program is distributed in the hope that it will be
--      useful, but WITHOUT ANY WARRANTY; without even the implied
--      warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
--      PURPOSE. See the Ada Community License for more details.
--      You should have received a copy of the Ada Community
--      License with this library, in the file named "Ada Community
--      License" or "ACL". If not, contact the author of this library
--      for a copy.
--

-- $Id: bc-containers-maps-unbounded-guarded.adb,v 1.1.2.1 2000/02/19 10:23:08 simon Exp $

package body BC.Containers.Maps.Unbounded.Guarded is

  function "=" (Left, Right : in Guarded_Unbounded_Map) return Boolean is
  begin
    return "=" (Unbounded_Map (Left), Unbounded_Map (Right));
  end "=";

  procedure Seize (M : in out Guarded_Unbounded_Map) is
  begin
    BC.Support.Synchronization.Seize (M.Guard.all);
  end Seize;

  procedure Release (M : in out Guarded_Unbounded_Map) is
  begin
    BC.Support.Synchronization.Release (M.Guard.all);
  end Release;

  procedure Initialize (M : in out Guarded_Unbounded_Map) is
  begin
    Initialize (Unbounded_Map (M));
    M.Guard := new Semaphore;
  end Initialize;

  procedure Adjust (M : in out Guarded_Unbounded_Map) is
    -- Consider M := P;
    -- On entry to Adjust, M contains a bitwise copy of P.
  begin
    -- lock P's semaphore
    Seize (M);
    -- make the deep copy
    Adjust (Unbounded_Map (M));
    -- unlock P's semaphore
    Release (M);
    -- create a new semaphore for R
    M.Guard := new Semaphore;
  end Adjust;
  -- XXX Perhaps Adjust should use a lock variable? to ensure it's
  -- released even if an exception occurs.

  procedure Finalize (M : in out Guarded_Unbounded_Map) is
  begin
    BC.Support.Synchronization.Delete (M.Guard);
    Finalize (Unbounded_Map (M));
  end Finalize;

end BC.Containers.Maps.Unbounded.Guarded;