Skip to content
Browse files

Don't switch stacks on yield if there are no other tasks

  • Loading branch information...
1 parent 35c894d commit c80b5216b50b1881012bf6339b08837af281b251 @doublec committed Sep 4, 2012
Showing with 24 additions and 21 deletions.
  1. +23 −19 DATS/task.dats
  2. +1 −2 TEST/test2.dats
View
42 DATS/task.dats
@@ -275,25 +275,29 @@ implement task_spawn_lin (ss, func) = task_schedule (task_create (ss, __cast(fun
}
-implement task_yield () = {
- val (pff_sch | sch) = get_global_scheduler ()
- prval pfat_sch = sch.pfat
- val () = assertloc (option_vt_is_some (sch.p->running))
- val tsk = option_vt_unsome<task> (sch.p->running)
- val (pff_running | running) = __borrow (tsk) where {
- extern castfn __borrow {l:agz} (tsk: !task l): (task l -<lin,prf> void | task l)
- }
- val () = sch.p->running := Some_vt tsk
-
- prval pfat_tsk = running.pfat
- val r = swapcontext (running.p->ctx, sch.p->ctx)
- val () = assertloc (r = 0)
- prval () = running.pfat := pfat_tsk
-
- prval () = pff_running (running)
- prval () = sch.pfat := pfat_sch
- prval () = pff_sch (sch)
-}
+implement task_yield () = let
+ fn yield (): void = {
+ val (pff_sch | sch) = get_global_scheduler ()
+ prval pfat_sch = sch.pfat
+ val () = assertloc (option_vt_is_some (sch.p->running))
+ val tsk = option_vt_unsome<task> (sch.p->running)
+ val (pff_running | running) = __borrow (tsk) where {
+ extern castfn __borrow {l:agz} (tsk: !task l): (task l -<lin,prf> void | task l)
+ }
+ val () = sch.p->running := Some_vt tsk
+
+ prval pfat_tsk = running.pfat
+ val r = swapcontext (running.p->ctx, sch.p->ctx)
+ val () = assertloc (r = 0)
+ prval () = running.pfat := pfat_tsk
+
+ prval () = pff_running (running)
+ prval () = sch.pfat := pfat_sch
+ prval () = pff_sch (sch)
+ }
+in
+ if task_queue_count () > 0 then yield ()
+end
implement task_queue_count () = let
val (pff_sch | sch) = get_global_scheduler ()
View
3 TEST/test2.dats
@@ -139,10 +139,9 @@ fn do_main (): void = {
fun event_loop_task (events_queued: bool): void = let
prval vbox pf = pf_the_base
val () = $effmask_ref task_yield ()
-
in
(* If no events are queued and if no tasks are also queued we can exit *)
- if (not events_queued && task_queue_count () = 0) then ()
+ if (not events_queued && task_queue_count () + task_paused_count () = 0) then ()
(* We're the only active task left, safe to block *)
else if task_queue_count () = 0 then $effmask_ref event_loop_task ($effmask_ref event_base_loop (the_base, EVLOOP_ONCE) = 0)

0 comments on commit c80b521

Please sign in to comment.
Something went wrong with that request. Please try again.