comp.lang.ada
 help / color / mirror / Atom feed
* Timing events in GNAT GPL 2006
@ 2007-01-12 16:49 Rolf
  2007-01-12 17:40 ` Vo, Anh (US SSA)
  0 siblings, 1 reply; 2+ messages in thread
From: Rolf @ 2007-01-12 16:49 UTC (permalink / raw)


I wanted to test the new Ada timing events with GNAT GPL 2006.  Here is
some code that should print a line every second. GNAT does not accept
my protected procedure when setting the handler. Why? I don't see my
error.

    Rolf
--
with Ada.Real_Time;                use Ada.Real_Time;
with Ada.Real_Time.Timing_Events;  use Ada.Real_Time.Timing_Events;
with Ada.Text_IO;                  use Ada.Text_IO;

procedure Test_Timing_Event is

   protected Clock_Tick is
      procedure Inc_Clock (Ev : Timing_Event);
   end Clock_Tick;

   Tick    : Timing_Event;
   One_Sec : constant Time_Span := Seconds (1);

   protected body Clock_Tick is
      procedure Inc_Clock (Ev : Timing_Event)
      is
      begin
         Put_Line ("Inc_Sec");
         -- using Time_Span
         Set_Handler (Tick, One_Sec, Handler => Inc_Clock'Access);
      end Inc_Clock;
   end Clock_Tick;

begin
   -- using absolute time
   Set_Handler (Tick, Clock + One_Sec, Clock_Tick.Inc_Clock'Access);
   loop null; end loop;
end Test_Timing_Event;

$ gnatmake -gnat05 test_timing_event.adb
gcc -c -gnat05 test_timing_event.adb
test_timing_event.adb:20:10: no candidate interpretations match the
actuals:
test_timing_event.adb:20:29: expected private type "Ada.Real_Time.Time"
test_timing_event.adb:20:29: found private type
"Ada.Real_Time.Time_Span"
test_timing_event.adb:20:29:   ==> in call to "Set_Handler" at
a-rttiev.ads:47
test_timing_event.adb:20:58: expected type
"Ada.Real_Time.Timing_Events.Timing_Event_Handler"
test_timing_event.adb:20:58: found type access to procedure "Inc_Clock"
defined at line 20
test_timing_event.adb:20:58:   ==> in call to "Set_Handler" at
a-rttiev.ads:52
test_timing_event.adb:26:04: no candidate interpretations match the
actuals:
test_timing_event.adb:26:29: expected private type
"Ada.Real_Time.Time_Span"
test_timing_event.adb:26:29: found private type "Ada.Real_Time.Time"
test_timing_event.adb:26:29:   ==> in call to "Set_Handler" at
a-rttiev.ads:52
test_timing_event.adb:26:60: expected type
"Ada.Real_Time.Timing_Events.Timing_Event_Handler"
test_timing_event.adb:26:60: found type access to procedure "Inc_Clock"
defined at line 26
test_timing_event.adb:26:60:   ==> in call to "Set_Handler" at
a-rttiev.ads:47
gnatmake: "test_timing_event.adb" compilation error

$ gnatls -v
GNATLS GPL 2006 (20060522-34)
Copyright 1997-2006, Free Software Foundation, Inc.




^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: Timing events in GNAT GPL 2006
  2007-01-12 16:49 Timing events in GNAT GPL 2006 Rolf
@ 2007-01-12 17:40 ` Vo, Anh (US SSA)
  0 siblings, 0 replies; 2+ messages in thread
From: Vo, Anh (US SSA) @ 2007-01-12 17:40 UTC (permalink / raw)
  To: Rolf, comp.lang.ada

--
with Ada.Real_Time;                use Ada.Real_Time;
with Ada.Real_Time.Timing_Events;  use Ada.Real_Time.Timing_Events;
with Ada.Text_IO;                  use Ada.Text_IO;

procedure Test_Timing_Event is

   protected Clock_Tick is
      procedure Inc_Clock (Ev : Timing_Event);
   end Clock_Tick;

   Tick    : Timing_Event;
   One_Sec : constant Time_Span := Seconds (1);

   protected body Clock_Tick is
      procedure Inc_Clock (Ev : Timing_Event)
      is
      begin
         Put_Line ("Inc_Sec");
         -- using Time_Span
         Set_Handler (Tick, One_Sec, Handler => Inc_Clock'Access);
      end Inc_Clock;
   end Clock_Tick;

begin
   -- using absolute time
   Set_Handler (Tick, Clock + One_Sec, Clock_Tick.Inc_Clock'Access);
   loop null; end loop;
end Test_Timing_Event;

-- >>

There are three things wrong with your codes. Two of them are critical.
1. The protected procedure Inc_Clock has wrong parameter mode. It must
be in out mode.
2. The call Set_Handler from the protected procedure will result in a
deadlock it is run.
3. Protected object must be declared at the library level. Yours is not.
As the result, non-local pointer cannot point to local object error at
lines 20 and 26

I designed for both one shot and periodic timers using Timing Event. If
it is helpful, I will post my code here. Just let me know.

AV



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-01-12 17:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-12 16:49 Timing events in GNAT GPL 2006 Rolf
2007-01-12 17:40 ` Vo, Anh (US SSA)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox