/src/lib/sequencer/loop_item.e

http://github.com/tybor/Liberty · Specman e · 186 lines · 143 code · 15 blank · 28 comment · 9 complexity · 52f7cc09e116b630b72ee531e34a90b5 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class LOOP_ITEM
  5. -- One loop level with related jobs to run
  6. insert
  7. ANY
  8. PLATFORM
  9. create {LOOP_STACK}
  10. make
  11. feature {LOOP_STACK}
  12. job_list: FAST_ARRAY[JOB]
  13. feature {}
  14. finished_jobs: FAST_ARRAY[JOB]
  15. ready_jobs: FAST_ARRAY[JOB]
  16. events: EVENTS_SET
  17. make
  18. do
  19. create job_list.make(0)
  20. create finished_jobs.make(0)
  21. create ready_jobs.make(0)
  22. create events.make
  23. pause := True
  24. ensure
  25. pause
  26. not break
  27. end
  28. feature {LOOP_STACK}
  29. pause: BOOLEAN
  30. break: BOOLEAN
  31. run
  32. require
  33. pause and not break
  34. local
  35. i: INTEGER; selected_priority: INTEGER
  36. job: JOB
  37. do
  38. from
  39. pause := False
  40. break := False
  41. until
  42. pause or else break or else job_list.is_empty
  43. loop
  44. -- prepare jobs
  45. from
  46. i := job_list.lower
  47. events.reset
  48. variant
  49. job_list.upper - i
  50. until
  51. i > job_list.upper
  52. loop
  53. job := job_list.item(i)
  54. if job.done then
  55. job_list.remove(i)
  56. finished_jobs.add_last(job)
  57. else
  58. job.prepare(events)
  59. i := i + 1
  60. end
  61. end
  62. if not job_list.is_empty then
  63. -- wait for something to do
  64. events.wait
  65. -- search ready jobs (with same priority as the first ready job)
  66. from
  67. i := job_list.lower
  68. selected_priority := Minimum_integer
  69. ready_jobs.clear_count
  70. until
  71. i > job_list.upper or else selected_priority /= Minimum_integer
  72. loop
  73. job := job_list.item(i)
  74. if job.is_ready(events) then
  75. selected_priority := job.priority
  76. ready_jobs.add_last(job)
  77. end
  78. i := i + 1
  79. end
  80. from
  81. until
  82. i > job_list.upper or else job_list.item(i).priority /= selected_priority
  83. loop
  84. job := job_list.item(i)
  85. if job.is_ready(events) then
  86. ready_jobs.add_last(job)
  87. end
  88. i := i + 1
  89. end
  90. -- run selected ready jobs
  91. from
  92. i := ready_jobs.upper
  93. until
  94. i < ready_jobs.lower
  95. loop
  96. ready_jobs.item(i).continue
  97. i := i - 1
  98. end
  99. end
  100. end
  101. ensure
  102. pause or job_list.is_empty or break
  103. end
  104. break_loop
  105. do
  106. break := True
  107. ensure
  108. break
  109. end
  110. pause_loop
  111. require
  112. not pause
  113. do
  114. pause := True
  115. ensure
  116. pause
  117. end
  118. add_job (j: JOB)
  119. require
  120. j /= Void
  121. local
  122. i: INTEGER
  123. do
  124. from
  125. i := job_list.lower
  126. until
  127. i > job_list.upper or else job_list.item(i).priority > j.priority
  128. loop
  129. i := i + 1
  130. end
  131. job_list.add(j, i)
  132. end
  133. restart
  134. require
  135. not pause or break
  136. do
  137. from
  138. until
  139. finished_jobs.is_empty
  140. loop
  141. finished_jobs.last.restart
  142. add_job(finished_jobs.last)
  143. finished_jobs.remove_last
  144. end
  145. pause := True
  146. break := False
  147. ensure
  148. pause
  149. not break
  150. end
  151. end -- class LOOP_ITEM
  152. --
  153. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  154. --
  155. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  156. -- of this software and associated documentation files (the "Software"), to deal
  157. -- in the Software without restriction, including without limitation the rights
  158. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  159. -- copies of the Software, and to permit persons to whom the Software is
  160. -- furnished to do so, subject to the following conditions:
  161. --
  162. -- The above copyright notice and this permission notice shall be included in
  163. -- all copies or substantial portions of the Software.
  164. --
  165. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  166. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  167. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  168. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  169. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  170. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  171. -- THE SOFTWARE.