From: Magnus Therning <d94magth@und.ida.liu.se>
Subject: protected types and functions in Ada95 (Newbie)
Date: 1997/04/24
Date: 1997-04-24T00:00:00+00:00 [thread overview]
Message-ID: <335F2DF6.827@und.ida.liu.se> (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/
next reply other threads:[~1997-04-24 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-04-24 0:00 Magnus Therning [this message]
1997-04-24 0:00 ` protected types and functions in Ada95 (Newbie) Jon S Anthony
1997-04-24 0:00 ` Robert A Duff
1997-04-25 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox