agpl_1.0.0_b5da3320/src/agpl-tasking-period.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
with Ada.Calendar;

package Agpl.Tasking.Period is

   --  Soft real-time non-skewing periods

   Default_Catch_Up : Boolean := False;
   --  This governs global behavior, not very clever but maybe useful for debug

   type Object is tagged private;

   function Create (Period : Duration) return Object;

   function Get_Period (This : Object) return Duration;

   procedure Set_Period (This   : in out Object;
                         Period :        Duration);

   procedure Next (This     : in out Object;
                   Time     :    out Ada.Calendar.Time;
                   Catch_Up :        Boolean := Default_Catch_Up);
   --  Move to next slot and give it
   --  If Catch_Up, Next is guaranteed to be in the future even if this means
   --   skipping some slots
   --  If not Catch_Up, we may get a time in the past, but the internal slots
   --   are moved forward nonetheless so your next call should be again in the
   --   future.
   --  This prevents some saturation in certain cases.

private

   type Object is tagged record
      First_Time : Boolean  := True;
      Now        : Ada.Calendar.Time;
      Period     : Duration := -1.0; -- To detect uninitialization
   end record;

end Agpl.Tasking.Period;