From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5b15c37c5d0c986f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.hanau.net!noris.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Designing Timers using Ada.Real_Time.Timing_Events package Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1143317010.868435.251190@v46g2000cwv.googlegroups.com> <1d4yew2i587h5.1h8dilwbda4zv.dlg@40tude.net> <1143351567.528574.297850@z34g2000cwc.googlegroups.com> <1fiau0e4pe84o$.gulfgysczk5i$.dlg@40tude.net> <1143389936.844624.243020@i40g2000cwc.googlegroups.com> <1143402228.182836.29570@v46g2000cwv.googlegroups.com> <1pvsgg60odxin$.16vcgq2jyhf8g$.dlg@40tude.net> <1143496801.549618.279120@t31g2000cwb.googlegroups.com> Date: Tue, 28 Mar 2006 09:51:22 +0200 Message-ID: <1gyqhdonzlb1x.1a5ckmt6o6cou$.dlg@40tude.net> NNTP-Posting-Date: 28 Mar 2006 09:51:22 MEST NNTP-Posting-Host: 24d59f70.newsread2.arcor-online.net X-Trace: DXC=MgjVMPOPU0YD__2dTlB=E[Q5U85hF6f;TjW\KbG]kaMXDAHcn;Zl5eXkGE>o`eP>LU[6LHn;2LCV^7enW;^6ZC`TIXm65S@:3>_ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:3669 Date: 2006-03-28T09:51:22+02:00 List-Id: 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