/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. --
  4. deferred 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. inherit
  10. JOB
  11. feature {ANY}
  12. period: REAL -- unit is seconds
  13. next_time: MICROSECOND_TIME
  14. feature {LOOP_ITEM}
  15. prepare (events: EVENTS_SET)
  16. local
  17. t: TIME_EVENTS
  18. do
  19. events.expect(t.at_date(next_time))
  20. end
  21. is_ready (events: EVENTS_SET): BOOLEAN
  22. do
  23. Result := next_time <= events.current_time
  24. if Result then
  25. next_time := events.current_time + period
  26. end
  27. end
  28. invariant
  29. period > 0
  30. end -- class PERIODIC_JOB
  31. --
  32. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  33. --
  34. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  35. -- of this software and associated documentation files (the "Software"), to deal
  36. -- in the Software without restriction, including without limitation the rights
  37. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  38. -- copies of the Software, and to permit persons to whom the Software is
  39. -- furnished to do so, subject to the following conditions:
  40. --
  41. -- The above copyright notice and this permission notice shall be included in
  42. -- all copies or substantial portions of the Software.
  43. --
  44. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  45. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  46. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  47. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  48. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  49. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  50. -- THE SOFTWARE.