comp.lang.ada
 help / color / mirror / Atom feed
* protected types and functions in Ada95 (Newbie)
@ 1997-04-24  0:00 Magnus Therning
  1997-04-24  0:00 ` Robert A Duff
  1997-04-24  0:00 ` Jon S Anthony
  0 siblings, 2 replies; 4+ messages in thread
From: Magnus Therning @ 1997-04-24  0:00 UTC (permalink / raw)



I want to seize a semaphore in a function. Is that possible using the
following protected type semaphore? Functions can only take 'in'
parameters, but I need 'in out' since Seize changes the semaphore.

package Semaphore_S is

    type Kind(Num : Integer := 1) is limited private;

    procedure Seize(Sem : in out Kind);
    procedure Release(Sem : in out Kind);

private

   protected type Kind(Num : Integer := 1) is
      entry Secure;
      procedure Release; 
   private
      Count : Integer := Num;
   end Kind;

end Semaphore_S;

package body Semaphore_S is

   protected body Kind is
      Entry Secure when Count > 0 is
      begin
	 Count := Count - 1;
      end Secure;
      
      procedure Release is
      begin
	 Count := Count + 1;
      end Release;
   end Kind;

   procedure Seize(Sem : in out Kind) is
   begin  
      Sem.Secure;
   end Seize;

   procedure Release(Sem : in out Kind) is
   begin
      Sem.Release;
   end Release;

end Semaphore_S;
-- 
Magnus Therning ( d94magth@und.ida.liu.se )
http://www-und.ida.liu.se/~d94magth/




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1997-04-25  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-04-24  0:00 protected types and functions in Ada95 (Newbie) Magnus Therning
1997-04-24  0:00 ` Robert A Duff
1997-04-25  0:00   ` Robert Dewar
1997-04-24  0:00 ` Jon S Anthony

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox