[svn:parrot] r48694 - in trunk: src src/pmc t/pmc
nwellnhof at svn.parrot.org
nwellnhof at svn.parrot.org
Fri Aug 27 14:34:16 UTC 2010
Author: nwellnhof
Date: Fri Aug 27 14:34:16 2010
New Revision: 48694
URL: https://trac.parrot.org/parrot/changeset/48694
Log:
Avoid recursive calls of Parrot_cx_handle_tasks
Fixes TT #484
Modified:
trunk/src/pmc/scheduler.pmc
trunk/src/scheduler.c
trunk/t/pmc/timer.t
Modified: trunk/src/pmc/scheduler.pmc
==============================================================================
--- trunk/src/pmc/scheduler.pmc Fri Aug 27 12:20:44 2010 (r48693)
+++ trunk/src/pmc/scheduler.pmc Fri Aug 27 14:34:16 2010 (r48694)
@@ -30,6 +30,7 @@
ATTR INTVAL max_tid; /* The highest assigned task ID. */
ATTR INTVAL pending; /* A count of pending tasks (cached for fast
lookup). */
+ ATTR INTVAL in_handler; /* Set during execution of a handler. */
ATTR PMC *task_list; /* The current list of tasks. */
ATTR PMC *task_index; /* An index into the current list of tasks,
ordered by priority. */
Modified: trunk/src/scheduler.c
==============================================================================
--- trunk/src/scheduler.c Fri Aug 27 12:20:44 2010 (r48693)
+++ trunk/src/scheduler.c Fri Aug 27 14:34:16 2010 (r48694)
@@ -111,8 +111,7 @@
=item C<void Parrot_cx_handle_tasks(PARROT_INTERP, PMC *scheduler)>
Handle the pending tasks in the scheduler's task list. Returns when there are
-no more pending tasks. Returns 0 to terminate the scheduler runloop, or 1 to
-continue the runloop.
+no more pending tasks.
=cut
@@ -123,6 +122,13 @@
Parrot_cx_handle_tasks(PARROT_INTERP, ARGMOD(PMC *scheduler))
{
ASSERT_ARGS(Parrot_cx_handle_tasks)
+ Parrot_Scheduler_attributes * sched_struct = PARROT_SCHEDULER(scheduler);
+
+ /* avoid recursive calls */
+ if (sched_struct->in_handler)
+ return;
+ sched_struct->in_handler = 1;
+
SCHEDULER_wake_requested_CLEAR(scheduler);
Parrot_cx_refresh_task_list(interp, scheduler);
@@ -159,6 +165,8 @@
Parrot_cx_refresh_task_list(interp, scheduler);
} /* end of pending tasks */
+
+ sched_struct->in_handler = 0;
}
/*
Modified: trunk/t/pmc/timer.t
==============================================================================
--- trunk/t/pmc/timer.t Fri Aug 27 12:20:44 2010 (r48693)
+++ trunk/t/pmc/timer.t Fri Aug 27 14:34:16 2010 (r48694)
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 6;
+use Parrot::Test tests => 7;
use Parrot::Config;
=head1 NAME
@@ -200,6 +200,38 @@
0
OUTPUT
+pir_output_is( << 'CODE', << 'OUTPUT', "Timer - many repetitions" );
+
+.include 'timer.pasm'
+
+.sub expired
+ $P0 = get_global "expired_count"
+ inc $P0
+.end
+
+.sub main :main
+ $P2 = new 'Integer'
+ set_global "expired_count", $P2
+
+ $P0 = new 'Timer'
+ $P1 = get_global "expired"
+
+ $P0[.PARROT_TIMER_HANDLER] = $P1
+ $P0[.PARROT_TIMER_SEC] = 0
+ $P0[.PARROT_TIMER_REPEAT] = 9999
+ $P0[.PARROT_TIMER_RUNNING] = 1
+
+loop:
+ sleep 0
+ if $P2 < 10000 goto loop
+
+ sleep 0.5
+ say $P2
+.end
+CODE
+10000
+OUTPUT
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
More information about the parrot-commits
mailing list