246 put them in the same record so that they can evolve together. |
246 put them in the same record so that they can evolve together. |
247 \end{enumerate} |
247 \end{enumerate} |
248 \end{minipage} |
248 \end{minipage} |
249 *} |
249 *} |
250 "schs (Create th prio # s) = |
250 "schs (Create th prio # s) = |
251 (let wq = waiting_queue (schs s) in |
251 (let wq = wq_fun (schs s) in |
252 (|waiting_queue = wq, cur_preced = cpreced wq (Create th prio # s)|))" |
252 (|wq_fun = wq, cprec_fun = cpreced wq (Create th prio # s)|))" |
253 | "schs (Exit th # s) = |
253 | "schs (Exit th # s) = |
254 (let wq = waiting_queue (schs s) in |
254 (let wq = wq_fun (schs s) in |
255 (|waiting_queue = wq, cur_preced = cpreced wq (Exit th # s)|))" |
255 (|wq_fun = wq, cprec_fun = cpreced wq (Exit th # s)|))" |
256 | "schs (Set th prio # s) = |
256 | "schs (Set th prio # s) = |
257 (let wq = waiting_queue (schs s) in |
257 (let wq = wq_fun (schs s) in |
258 (|waiting_queue = wq, cur_preced = cpreced wq (Set th prio # s)|))" |
258 (|wq_fun = wq, cprec_fun = cpreced wq (Set th prio # s)|))" |
259 | "schs (P th cs # s) = |
259 | "schs (P th cs # s) = |
260 (let wq = waiting_queue (schs s) in |
260 (let wq = wq_fun (schs s) in |
261 let new_wq = wq(cs := (wq cs @ [th])) in |
261 let new_wq = wq(cs := (wq cs @ [th])) in |
262 (|waiting_queue = new_wq, cur_preced = cpreced new_wq (P th cs # s)|))" |
262 (|wq_fun = new_wq, cprec_fun = cpreced new_wq (P th cs # s)|))" |
263 | "schs (V th cs # s) = |
263 | "schs (V th cs # s) = |
264 (let wq = waiting_queue (schs s) in |
264 (let wq = wq_fun (schs s) in |
265 let new_wq = wq(cs := release (wq cs)) in |
265 let new_wq = wq(cs := release (wq cs)) in |
266 (|waiting_queue = new_wq, cur_preced = cpreced new_wq (V th cs # s)|))" |
266 (|wq_fun = new_wq, cprec_fun = cpreced new_wq (V th cs # s)|))" |
267 |
267 |
268 lemma cpreced_initial: |
268 lemma cpreced_initial: |
269 "cpreced (\<lambda> cs. []) [] = (\<lambda>_. (Prc 0 0))" |
269 "cpreced (\<lambda> cs. []) [] = (\<lambda>_. (Prc 0 0))" |
270 apply(simp add: cpreced_def) |
270 apply(simp add: cpreced_def) |
271 apply(simp add: cs_dependents_def cs_depend_def cs_waiting_def cs_holding_def) |
271 apply(simp add: cs_dependents_def cs_depend_def cs_waiting_def cs_holding_def) |
272 apply(simp add: preced_def) |
272 apply(simp add: preced_def) |
273 done |
273 done |
274 |
274 |
275 lemma sch_old_def: |
275 lemma sch_old_def: |
276 "schs (e#s) = (let ps = schs s in |
276 "schs (e#s) = (let ps = schs s in |
277 let pwq = waiting_queue ps in |
277 let pwq = wq_fun ps in |
278 let nwq = case e of |
278 let nwq = case e of |
279 P th cs \<Rightarrow> pwq(cs:=(pwq cs @ [th])) | |
279 P th cs \<Rightarrow> pwq(cs:=(pwq cs @ [th])) | |
280 V th cs \<Rightarrow> let nq = case (pwq cs) of |
280 V th cs \<Rightarrow> let nq = case (pwq cs) of |
281 [] \<Rightarrow> [] | |
281 [] \<Rightarrow> [] | |
282 (_#qs) \<Rightarrow> (SOME q. distinct q \<and> set q = set qs) |
282 (_#qs) \<Rightarrow> (SOME q. distinct q \<and> set q = set qs) |
283 in pwq(cs:=nq) | |
283 in pwq(cs:=nq) | |
284 _ \<Rightarrow> pwq |
284 _ \<Rightarrow> pwq |
285 in let ncp = cpreced nwq (e#s) in |
285 in let ncp = cpreced nwq (e#s) in |
286 \<lparr>waiting_queue = nwq, cur_preced = ncp\<rparr> |
286 \<lparr>wq_fun = nwq, cprec_fun = ncp\<rparr> |
287 )" |
287 )" |
288 apply(cases e) |
288 apply(cases e) |
289 apply(simp_all) |
289 apply(simp_all) |
290 done |
290 done |
291 |
291 |
292 |
292 |
293 text {* |
293 text {* |
294 \noindent |
294 \noindent |
295 The following @{text "wq"} is a shorthand for @{text "waiting_queue"}. |
295 The following @{text "wq"} is a shorthand for @{text "wq_fun"}. |
296 *} |
296 *} |
297 definition wq :: "state \<Rightarrow> cs \<Rightarrow> thread list" |
297 definition wq :: "state \<Rightarrow> cs \<Rightarrow> thread list" |
298 where "wq s = waiting_queue (schs s)" |
298 where "wq s = wq_fun (schs s)" |
299 |
299 |
300 text {* \noindent |
300 text {* \noindent |
301 The following @{text "cp"} is a shorthand for @{text "cur_preced"}. |
301 The following @{text "cp"} is a shorthand for @{text "cprec_fun"}. |
302 *} |
302 *} |
303 definition cp :: "state \<Rightarrow> thread \<Rightarrow> precedence" |
303 definition cp :: "state \<Rightarrow> thread \<Rightarrow> precedence" |
304 where "cp s = cur_preced (schs s)" |
304 where "cp s = cprec_fun (schs s)" |
305 |
305 |
306 text {* \noindent |
306 text {* \noindent |
307 Functions @{text "holding"}, @{text "waiting"}, @{text "depend"} and |
307 Functions @{text "holding"}, @{text "waiting"}, @{text "depend"} and |
308 @{text "dependents"} still have the |
308 @{text "dependents"} still have the |
309 same meaning, but redefined so that they no longer depend on the |
309 same meaning, but redefined so that they no longer depend on the |