Re: Designing Timers using Ada.Real_Time.Timing_Events package
- From: "Anh Vo" <anhvofrcaus@xxxxxxxxx>
- Date: 27 Mar 2006 14:00:01 -0800
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
.
- Follow-Ups:
- Re: Designing Timers using Ada.Real_Time.Timing_Events package
- From: Dmitry A. Kazakov
- Re: Designing Timers using Ada.Real_Time.Timing_Events package
- References:
- Designing Timers using Ada.Real_Time.Timing_Events package
- From: Anh Vo
- Re: Designing Timers using Ada.Real_Time.Timing_Events package
- From: Dmitry A. Kazakov
- Re: Designing Timers using Ada.Real_Time.Timing_Events package
- From: Anh Vo
- Re: Designing Timers using Ada.Real_Time.Timing_Events package
- From: Dmitry A. Kazakov
- Re: Designing Timers using Ada.Real_Time.Timing_Events package
- From: Anh Vo
- Re: Designing Timers using Ada.Real_Time.Timing_Events package
- From: Dmitry A. Kazakov
- Re: Designing Timers using Ada.Real_Time.Timing_Events package
- From: Anh Vo
- Re: Designing Timers using Ada.Real_Time.Timing_Events package
- From: Dmitry A. Kazakov
- Re: Designing Timers using Ada.Real_Time.Timing_Events package
- From: Dmitry A. Kazakov
- Designing Timers using Ada.Real_Time.Timing_Events package
- Prev by Date: Re: ada and pl/sql
- Next by Date: Linux kernel bindings - at least sockets?
- Previous by thread: Re: Designing Timers using Ada.Real_Time.Timing_Events package
- Next by thread: Re: Designing Timers using Ada.Real_Time.Timing_Events package
- Index(es):
Relevant Pages
|