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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM 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!postnews.google.com!t31g2000cwb.googlegroups.com!not-for-mail From: "Anh Vo" Newsgroups: comp.lang.ada Subject: Re: Designing Timers using Ada.Real_Time.Timing_Events package Date: 27 Mar 2006 14:00:01 -0800 Organization: http://groups.google.com Message-ID: <1143496801.549618.279120@t31g2000cwb.googlegroups.com> 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> NNTP-Posting-Host: 209.225.226.92 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1143496815 24191 127.0.0.1 (27 Mar 2006 22:00:15 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 27 Mar 2006 22:00:15 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: t31g2000cwb.googlegroups.com; posting-host=209.225.226.92; posting-account=JVr7Xg0AAAAI3MbuARxMmvWLmA7qdJMx Xref: g2news1.google.com comp.lang.ada:3661 Date: 2006-03-27T14:00:01-08:00 List-Id: 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