File : s-bbtiev.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . B B . T I M I N G _ E V E N T S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2011-2013, AdaCore --
10 -- --
11 -- GNARL is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- --
19 -- --
20 -- --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 ------------------------------------------------------------------------------
28
29 with System.BB.Time;
30 with System.Multiprocessors;
31
32 package System.Bb.Timing_Events is
33 pragma Preelaborate;
34
35 type Timing_Event;
36
37 type Timing_Event_Handler
38 is access procedure (Event : in out Timing_Event'Class);
39
40 type Timing_Event_Access is access all Timing_Event;
41
42 type Timing_Event is tagged limited record
43 Timeout : System.BB.Time.Time := System.BB.Time.Time'First;
44 -- The time at which the user's handler should be invoked when the event
45 -- is "set" (i.e., when Handler is not null).
46
47 Handler : Timing_Event_Handler := null;
48 -- An access value designating the protected procedure to be invoked at
49 -- the Timeout time in the future. When this value is null the event is
50 -- said to be "cleared" and no timeout is processed.
51
52 Next : Timing_Event_Access := null;
53 -- Next event in the list
54
55 Prev : Timing_Event_Access := null;
56 -- Previous event in the list
57
58 CPU : System.Multiprocessors.CPU;
59 -- Owner of the timing event
60
61 end record;
62
63 procedure Set_Handler
64 (Event : in out Timing_Event;
65 At_Time : System.BB.Time.Time;
66 Handler : Timing_Event_Handler);
67 -- Associate the handler Handler with the event Event: if Handler is null
68 -- the event is cleared; otherwise, it is set, and the execution time for
69 -- the event to be At_Time.
70 --
71 -- A call of a procedure Set_Handler for an event that is already set
72 -- replaces the handler and the time of execution; if Handler is not null,
73 -- the event remains set.
74
75 function Current_Handler
76 (Event : Timing_Event) return Timing_Event_Handler;
77 -- Return the handler associated with Event if that event is set, null
78 -- otherwise.
79
80 procedure Cancel_Handler
81 (Event : in out Timing_Event;
82 Cancelled : out Boolean);
83 -- Clear the event if it is set. Cancelled is assigned True if the event
84 -- was set prior to it being cleared; otherwise, it is assigned False.
85
86 function Time_Of_Event (Event : Timing_Event) return System.BB.Time.Time;
87 -- Return the time of the event if the event is set, Time'First otherwise
88
89 function Get_Next_Timeout
90 (CPU_Id : System.Multiprocessors.CPU) return System.BB.Time.Time;
91 pragma Inline (Get_Next_Timeout);
92 -- Return the next expiration time for all timing events associated with
93 -- CPU_Id. Return Time'Last if no timing event is pending for CPU_Id.
94
95 procedure Execute_Expired_Timing_Events (Now : System.BB.Time.Time);
96 -- Execute all timing events whose expiration time is before Now
97
98 end System.BB.Timing_Events;