package Ada_Store.Support.IPC

package Ada_Store.Support.IPC is

   protected type Mutex is

      entry Acquire;
      procedure Release;

   private
      Locked : Boolean := False;
   end Mutex;

   protected type Semaphore(Auto_Reset : Boolean := True) is
      
      entry Wait;
      entry Signal;

      entry Reset;

   private
      Signals : Integer := 0;
   end Semaphore;

end Ada_Store.Support.IPC;

package body Ada_Store.Support.IPC is

   protected body Mutex is

      entry Acquire when not Locked is
      begin
	 Locked := True;
      end Acquire;

      procedure Release is
      begin
	 Locked := False;
      end Release;

   end Mutex;

   protected body Semaphore is
      
      entry Wait when Signals > 0 is
      begin
	 if Auto_Reset then
	    requeue Reset;
	 end if;
      end Wait;

      entry Signal when True is
      begin
	 Signals := Signals + 1;
      end Signal;

      entry Reset when Signals > 0 is
      begin
	 Signals := Signals - 1;
      end Reset;

   end Semaphore;

end Ada_Store.Support.IPC;

Contents Page

Copyright © 1996 Simon Johnston &
Addison Wesley Longman