From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Ravenscar vs selective wait
Date: Tue, 24 Mar 2015 00:25:55 -0700
Date: 2015-03-24T00:25:55-07:00 [thread overview]
Message-ID: <mer3gh$lph$1@dont-email.me> (raw)
In-Reply-To: <lyk2y6vqkk.fsf@pushface.org>
On 03/23/2015 11:48 PM, Simon Wright wrote:
> Simon Wright <simon@pushface.org> writes:
>
>> Is it possible to construct an analog of the selective wait using the
>> Ravenscar profile?
>>
>> Turn_On_The_Lamp;
>> Next := Clock + Milliseconds (500);
>> select
>> accept Reset do
>> Next := Clock + Milliseconds (500);
>> end Reset;
>> or
>> delay until Next;
>> Turn_Off_The_Lamp;
>> end select;
>
> This is rather simplified from what I want to achieve, and I can think
> of an ugly solution for it.
>
> Turn_On_The_Lamp;
> Next := Clock + Milliseconds (500); -- Next is a shared variable
> loop
> delay until Next;
> if Next <= Clock then
> exit;
> else
> -- something else in the program has updated Next
> end if;
> end loop;
> Turn_Off_The_Lamp;
>
> But what if I need the next wake-up to be *earlier*?
Seems to me you could do what you originally asked about with 3 tasks and a PO:
Lamp task:
Turn_On;
Next := Clock + Interval;
PO.Set_Expiration (Expiration_Time => Next);
loop
PO.Wait (Result => Wait_Result);
case Wait_Result is
when Reset =>
Next := Clock + Interval;
PO.Set_Expiration (Expiration_Time => Next);
when Timeout =>
Turn_Off;
exit;
end case;
end loop;
PO:
procedure Set_Expiration (Expiration_Time : in Time);
procedure Delay_Expired;
procedure Reset_Expiration;
function Expiration return Time;
entry Wait (Result : out Wait_Result_ID);
The delay task would poll function Expiration and compare it to Clock, calling
Delay_Expired when Expiration >= Clock.
Some 3rd task would call Reset_Expiration when the expiration should be extended.
With some more complication this could also allow resetting to an earlier time.
--
Jeff Carter
"What's the amount of the insult?"
Never Give a Sucker an Even Break
104
next prev parent reply other threads:[~2015-03-24 7:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-23 22:00 Ravenscar vs selective wait Simon Wright
2015-03-24 6:48 ` Simon Wright
2015-03-24 7:25 ` Jeffrey Carter [this message]
2015-03-24 9:21 ` J-P. Rosen
2015-03-24 17:16 ` Jeffrey Carter
2015-03-24 20:12 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox