1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. with Ada.Task_Identification;           use Ada.Task_Identification; 
  10. with Ada.Unchecked_Deallocation; 
  11.  
  12. package Locking_Objects is 
  13.  
  14.     pragma Preelaborate; 
  15.  
  16.     -- A simple protected object used to implement a lock mutex. 
  17.     protected type Locking_Object is 
  18.  
  19.         -- Takes the lock. The calling thread will block until the lock is free. 
  20.         -- This must not be called again by the caller until it calls Unlock. 
  21.         entry Lock( owner : Task_Id := Current_Task ); 
  22.  
  23.         -- Immediately releases the lock. Only the thread that has first called 
  24.         -- Lock should call Unlock. Raises LOCK_USE_EXCEPTION if the lock is 
  25.         -- being used illegally. 
  26.         procedure Unlock; 
  27.  
  28.     private 
  29.         lockingTask : Task_Id := Null_Task_Id; 
  30.     end Locking_Object; 
  31.  
  32.     type A_Locking_Object is access all Locking_Object; 
  33.  
  34.     -- Deletes a Locking_Object. 
  35.     procedure Delete is new Ada.Unchecked_Deallocation( Locking_Object, A_Locking_Object ); 
  36.  
  37.     -- raised on improper use of a Locking_Object 
  38.     LOCK_USE_EXCEPTION : exception; 
  39.  
  40. end Locking_Objects;