This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] ada/41383: Return correct time for unset event
- From: Samuel Tardieu <sam at rfc1149 dot net>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Samuel Tardieu <sam at rfc1149 dot net>
- Date: Fri, 2 Oct 2009 22:47:55 +0200
- Subject: [PATCH] ada/41383: Return correct time for unset event
Calling Cancel_Handler clears an event (RM D.15(17/2)). The
time of an unset event as returned by Time_Of_Event must be
Ada.Real_Time.Time_First (RM D.15(18/2)).
The attached test program must execute without error.
The patch is trivial.
gcc/ada/
PR ada/41383
* a-rttiev.adb (Time_Of_Event): Return Time_First for unset event.
gcc/testsuite/
PR ada/41383
* gnat.dg/timer_cancel.adb: New test.
Tested on x86_64-unknown-linux-gnu. Ok for trunk?
---
gcc/ada/a-rttiev.adb | 8 ++++++-
gcc/testsuite/gnat.dg/timer_cancel.adb | 38 ++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 1 deletions(-)
diff --git a/gcc/ada/a-rttiev.adb b/gcc/ada/a-rttiev.adb
index 2068c78..0b86066 100644
--- a/gcc/ada/a-rttiev.adb
+++ b/gcc/ada/a-rttiev.adb
@@ -332,7 +332,13 @@ package body Ada.Real_Time.Timing_Events is
function Time_Of_Event (Event : Timing_Event) return Time is
begin
- return Event.Timeout;
+ -- RM D.15(18/2): Time_First must be returned in the event is not set
+
+ if Event.Handler = null then
+ return Time_First;
+ else
+ return Event.Timeout;
+ end if;
end Time_Of_Event;
--------------
diff --git a/gcc/testsuite/gnat.dg/timer_cancel.adb b/gcc/testsuite/gnat.dg/timer_cancel.adb
new file mode 100644
index 0000000..c300b47
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/timer_cancel.adb
@@ -0,0 +1,38 @@
+-- { dg-do run }
+
+with Ada.Real_Time.Timing_Events;
+use Ada.Real_Time, Ada.Real_Time.Timing_Events;
+
+procedure Timer_Cancel is
+
+ E : Timing_Event;
+ C : Boolean;
+
+ protected Dummy is
+ procedure Trigger (Event : in out Timing_Event);
+ end Dummy;
+
+ protected body Dummy is
+ procedure Trigger (Event : in out Timing_Event) is
+ begin
+ null;
+ end Trigger;
+ end Dummy;
+
+begin
+ Set_Handler (E, Time_Last, Dummy.Trigger'Unrestricted_Access);
+
+ if Time_Of_Event (E) /= Time_Last then
+ raise Program_Error with "Event time not set correctly";
+ end if;
+
+ Cancel_Handler (E, C);
+
+ if not C then
+ raise Program_Error with "Event triggered already";
+ end if;
+
+ if Time_Of_Event (E) /= Time_First then
+ raise Program_Error with "Event time not reset correctly";
+ end if;
+end Timer_Cancel;
--
tg: (47c3d42..) t/cancel-time-event (depends on: origin/trunk)