equal
deleted
inserted
replaced
269 Unsynchronized.ref Working)); |
269 Unsynchronized.ref Working)); |
270 |
270 |
271 |
271 |
272 (* scheduler *) |
272 (* scheduler *) |
273 |
273 |
|
274 fun ML_statistics () = |
|
275 if ! ML_Statistics.enabled then |
|
276 (case ML_Statistics.get () of |
|
277 [] => () |
|
278 | stats => Output.protocol_message (Markup.ML_statistics @ stats) "") |
|
279 else (); |
|
280 |
274 val status_ticks = Unsynchronized.ref 0; |
281 val status_ticks = Unsynchronized.ref 0; |
275 |
282 |
276 val last_round = Unsynchronized.ref Time.zeroTime; |
283 val last_round = Unsynchronized.ref Time.zeroTime; |
277 val next_round = seconds 0.05; |
284 val next_round = seconds 0.05; |
278 |
285 |
287 |
294 |
288 val _ = |
295 val _ = |
289 if tick then Unsynchronized.change status_ticks (fn i => (i + 1) mod 10) else (); |
296 if tick then Unsynchronized.change status_ticks (fn i => (i + 1) mod 10) else (); |
290 val _ = |
297 val _ = |
291 if tick andalso ! status_ticks = 0 then |
298 if tick andalso ! status_ticks = 0 then |
|
299 (ML_statistics (); |
292 Multithreading.tracing 1 (fn () => |
300 Multithreading.tracing 1 (fn () => |
293 let |
301 let |
294 val {ready, pending, running, passive} = Task_Queue.status (! queue); |
302 val {ready, pending, running, passive} = Task_Queue.status (! queue); |
295 val total = length (! workers); |
303 val total = length (! workers); |
296 val active = count_workers Working; |
304 val active = count_workers Working; |
302 string_of_int running ^ " running, " ^ |
310 string_of_int running ^ " running, " ^ |
303 string_of_int passive ^ " passive; " ^ |
311 string_of_int passive ^ " passive; " ^ |
304 string_of_int total ^ " workers, " ^ |
312 string_of_int total ^ " workers, " ^ |
305 string_of_int active ^ " active, " ^ |
313 string_of_int active ^ " active, " ^ |
306 string_of_int waiting ^ " waiting " |
314 string_of_int waiting ^ " waiting " |
307 end) |
315 end)) |
308 else (); |
316 else (); |
309 |
317 |
310 val _ = |
318 val _ = |
311 if forall (Thread.isActive o #1) (! workers) then () |
319 if forall (Thread.isActive o #1) (! workers) then () |
312 else |
320 else |
390 fun scheduler_loop () = |
398 fun scheduler_loop () = |
391 (while |
399 (while |
392 Multithreading.with_attributes |
400 Multithreading.with_attributes |
393 (Multithreading.sync_interrupts Multithreading.public_interrupts) |
401 (Multithreading.sync_interrupts Multithreading.public_interrupts) |
394 (fn _ => SYNCHRONIZED "scheduler" (fn () => scheduler_next ())) |
402 (fn _ => SYNCHRONIZED "scheduler" (fn () => scheduler_next ())) |
395 do (); last_round := Time.zeroTime); |
403 do (); last_round := Time.zeroTime; ML_statistics ()); |
396 |
404 |
397 fun scheduler_active () = (*requires SYNCHRONIZED*) |
405 fun scheduler_active () = (*requires SYNCHRONIZED*) |
398 (case ! scheduler of NONE => false | SOME thread => Thread.isActive thread); |
406 (case ! scheduler of NONE => false | SOME thread => Thread.isActive thread); |
399 |
407 |
400 fun scheduler_check () = (*requires SYNCHRONIZED*) |
408 fun scheduler_check () = (*requires SYNCHRONIZED*) |