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