PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/src/lib/sequencer/periodic_job.e

http://github.com/tybor/Liberty
Specman e | 57 lines | 23 code | 7 blank | 27 comment | 1 complexity | 2078ddf738c189fbfd594bb89a90e513 MD5 | raw file
 1-- This file is part of a Liberty Eiffel library.
 2-- See the full copyright at the end.
 3--
 4deferred class PERIODIC_JOB
 5   -- Pseudo periodic job. The timing is not exact : the time between
 6   -- two executions may be longer than the given period depending on
 7   -- time needed to execute the ready tasks. There is no try to recover the
 8   -- time lost each time.
 9
10inherit
11   JOB
12
13feature {ANY}
14   period: REAL -- unit is seconds
15
16   next_time: MICROSECOND_TIME
17
18feature {LOOP_ITEM}
19   prepare (events: EVENTS_SET)
20      local
21         t: TIME_EVENTS
22      do
23         events.expect(t.at_date(next_time))
24      end
25
26   is_ready (events: EVENTS_SET): BOOLEAN
27      do
28         Result := next_time <= events.current_time
29         if Result then
30            next_time := events.current_time + period
31         end
32      end
33
34invariant
35   period > 0
36
37end -- class PERIODIC_JOB
38--
39-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
40--
41-- Permission is hereby granted, free of charge, to any person obtaining a copy
42-- of this software and associated documentation files (the "Software"), to deal
43-- in the Software without restriction, including without limitation the rights
44-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45-- copies of the Software, and to permit persons to whom the Software is
46-- furnished to do so, subject to the following conditions:
47--
48-- The above copyright notice and this permission notice shall be included in
49-- all copies or substantial portions of the Software.
50--
51-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
57-- THE SOFTWARE.