From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Designing Timers using Ada.Real_Time.Timing_Events package
Date: Tue, 28 Mar 2006 09:51:22 +0200
Date: 2006-03-28T09:51:22+02:00 [thread overview]
Message-ID: <1gyqhdonzlb1x.1a5ckmt6o6cou$.dlg@40tude.net> (raw)
In-Reply-To: 1143496801.549618.279120@t31g2000cwb.googlegroups.com
On 27 Mar 2006 14:00:01 -0800, Anh Vo wrote:
> 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);
++++++++++++++++
Inactive := False;
> 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???
Emulates a premature timer event. It could be a direct call to Signal:
Signal (The_Event);
It can be a procedure rather than entry, because Signal is a procedure.
> 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;
I cannot comment on Real_Time.Timing_Events, I have no any experience of
using it...
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2006-03-28 7:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-25 20:03 Designing Timers using Ada.Real_Time.Timing_Events package Anh Vo
2006-03-25 20:58 ` Dmitry A. Kazakov
2006-03-26 5:39 ` Anh Vo
2006-03-26 12:58 ` Dmitry A. Kazakov
2006-03-26 16:18 ` Anh Vo
2006-03-26 18:22 ` Dmitry A. Kazakov
2006-03-26 19:43 ` Anh Vo
[not found] ` <3itd22hcekts5lsojdqjnn966bbvc8fckh@4ax.com>
2006-03-26 23:53 ` Anh Vo
[not found] ` <0mae22lshe5nee8pt8h7seussloebv07g3@4ax.com>
2006-03-27 5:01 ` Anh Vo
[not found] ` <5vse22h4mc1och27s0nkbv986csi2rorki@4ax.com>
2006-03-28 0:07 ` Anh Vo
2006-03-27 7:49 ` Dmitry A. Kazakov
2006-03-27 18:14 ` Dmitry A. Kazakov
2006-03-27 22:00 ` Anh Vo
2006-03-28 7:51 ` Dmitry A. Kazakov [this message]
2006-03-28 16:00 ` Anh Vo
2006-03-26 7:59 ` Martin Krischik
2006-03-26 15:50 ` Anh Vo
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox