Re: Designing Timers using Ada.Real_Time.Timing_Events package




Dmitry A. Kazakov wrote:
On Mon, 27 Mar 2006 09:49:59 +0200, Dmitry A. Kazakov wrote:

-- Main entrance (is closed during notification) The reason is
-- to aviod irace condition upon timer event. Otherwise a task
-- might get it twice.
entry Wait_For when Inactive or not Occured is
if Inactive then
raise Timer_Canceled;
else
requeue Wait_Notify with abort;
end if;
end Wait_For;

-- The notification queue, this is a private entry point to gather
-- the waiting requests.
entry Wait_Notify when Inactive or Occured is
if Inactive then
raise Timer_Canceled;

I forgot to reset it:

else
Occurred := Wait_Notify'Count > 0;

end if;
end Wait_Notify;

procedure Set (Period : Time_Span) is
begin
-- attach Signal to the timer
Inactive := False;
end Set;

procedure Signal (...) is
Occurred := True;
end Signal;

procedure Stop is
-- detach Signal from the timer
Inactive := True;
end Stop;

Dmitry,

Before going further, I would like to know if this is exactly what you
had in mind. By the way, it is compilable.


with Ada.Real_Time.Timing_Events;

package Dmitry_Timers is

use Ada;

Timer_Canceled : exception;

protected type Periodic_Timer is
entry Wait_For;
-- May raise Timer_Canceled
procedure Set (Period : Real_Time.Time_Span);
-- Sets. reset timer
procedure Cancel;
-- Stops timer. Any task in Wait_For queue gets Timer_Canceled
raised
entry Simulate;
-- Simulates a timer event
private
procedure Signal (Event: in out
Real_Time.Timing_Events.Timing_Event);
-- To be set as a handler for Ada.Real_Time.Timing_Events
-- [...]
-- Some internal entry to requeue Wait_For, if Signal cannot
-- be an entry, but must be a protected procedure, instead.
entry Wait_Notify;

Inactive : Boolean := True;
Occurred : Boolean := False;
The_Event : Real_Time.Timing_Events.Timing_Event;
end Periodic_Timer;

end Dmitry_Timers;

package body Dmitry_Timers is

protected body Periodic_Timer is
entry Wait_For when Inactive or not Occurred is
begin
if Inactive then
raise Timer_Canceled;
else
requeue Wait_Notify with abort;
end if;
end Wait_For;

entry Wait_Notify when Inactive or Occurred is
begin
if Inactive then
raise Timer_Canceled;
else
Occurred := Wait_Notify'Count > 0;
end if;
end Wait_Notify;

procedure Set (Period : Real_Time.Time_Span) is
begin
Real_Time.Timing_Events.Set_Handler (The_Event, Period,
Signal'access);
end Set;

procedure Cancel is
Success : Boolean := False;
use type Ada.Real_Time.Timing_Events.Timing_Event_Handler;
begin
if Real_Time.Timing_Events.Current_Handler (The_Event) /= null
then
Real_Time.Timing_Events.Cancel_Handler (The_Event,
Success);
Inactive := True;
Occurred := False;
end if;
end Cancel;

entry Simulate when True is
begin
null; -- What does it do exactly???
end Simulate;

procedure Signal (Event: in out
Real_Time.Timing_Events.Timing_Event) is
begin
Occurred := True;
-- Action to be performed.
end Signal;

end Periodic_Timer;

end Dmitry_Timers;

AV

.



Relevant Pages

  • Re: VB6 Application Overwhelmed by Rapid User Interaction
    ... entry the application behaves fine. ... store the new row index in a queue, you could use a timer to read ... the queue and display the data. ... A similar approach is to disable and reenable a timer when a row is selected, then in the timer event, just get the latest row. ...
    (microsoft.public.vb.winapi)
  • Re: How to make time limited function?
    ... I have no experience with delimited continuations, ... If your timer hasn't expired yet you can go on to start ... [If you don't have timers you can calculate the abort time on entry ... When the timer expires, ...
    (comp.lang.lisp)
  • Re: Designing Timers using Ada.Real_Time.Timing_Events package
    ... entry Wait_For; ... -- Simulates a timer event ... So there is no deadlock if one of them hangs somewhere. ...
    (comp.lang.ada)
  • Re: Designing Timers using Ada.Real_Time.Timing_Events package
    ... -- to aviod irace condition upon timer event. ... raise Timer_Canceled; ... this is a private entry point to gather ... procedure Set is ...
    (comp.lang.ada)
  • Re: timer implementation
    ... timer and the case where the timer runs to expiration? ... your timer tick is pre-emptive. ... Link the given node into the given queue, as a delta-key entry. ...
    (comp.arch.embedded)