Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[PMC] Added init_pmc() to Scheduler PMC, with tests.

There's not much to initialize here, per my reading of PDD 25.

git-svn-id: https://svn.parrot.org/parrot/trunk@23386 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
commit 96858eea9c2cf8cb34ac012e8d3cdefcd77df93a 1 parent 9d7fb7f
@chromatic chromatic authored
Showing with 93 additions and 1 deletion.
  1. +47 −0 src/pmc/scheduler.pmc
  2. +46 −1 t/pmc/scheduler.t
View
47 src/pmc/scheduler.pmc
@@ -52,6 +52,53 @@ Initialize a concurrency scheduler object.
/*
+=item C<void init_pmc(PMC *data)>
+
+Initializes a new Scheduler with a C<Hash> PMC with any or all of the keys:
+
+=over 4
+
+=item C<id>
+
+An C<Integer> representing the unique identifier for this scheduler.
+
+=back
+
+*/
+
+ void init_pmc(PMC *data) {
+ PMC *elem;
+ Parrot_Scheduler *core_struct;
+
+ if (! VTABLE_isa(INTERP, data, CONST_STRING(INTERP, "Hash")))
+ real_exception(INTERP, NULL, INVALID_OPERATION,
+ "Task initializer must be a Hash");
+
+ core_struct = mem_allocate_zeroed_typed(Parrot_Scheduler);
+
+ /* Set flags for custom DOD mark and destroy. */
+ PObj_custom_mark_SET(SELF);
+ PObj_active_destroy_SET(SELF);
+
+ /* Set up the core struct. */
+ PMC_data(SELF) = core_struct;
+
+ elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "id"));
+
+ if (! PMC_IS_NULL(elem))
+ core_struct->id = VTABLE_get_integer(INTERP, elem);
+ else
+ core_struct->id = 0;
+
+ core_struct->max_tid = 0;
+ core_struct->task_list = pmc_new(interp, enum_class_Hash);
+ core_struct->task_index = pmc_new(interp, enum_class_ResizablePMCArray);
+ core_struct->handlers = pmc_new(interp, enum_class_ResizablePMCArray);
+ core_struct->interp = INTERP;
+ }
+
+/*
+
=item C<void push_pmc(PMC *value)>
Insert a task into the task list, giving it a task ID one higher than the
View
47 t/pmc/scheduler.t
@@ -6,7 +6,7 @@ use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 1;
+use Parrot::Test tests => 2;
=head1 NAME
@@ -51,6 +51,51 @@ created
1
OUT
+pir_output_is( <<'CODE', <<'OUT', "create a concurrency scheduler with initializer" );
+ .sub main :main
+ .local pmc data
+ data = new 'Hash'
+
+ .local pmc id
+ id = new 'Integer'
+ id = 128
+ data['id'] = id
+
+ $P0 = new 'Scheduler', data
+ $P1 = new 'Task'
+
+ push $P0, $P1
+
+ $P2 = pop $P0
+
+ if null $P2 goto no_task
+ $P3 = getattribute $P2, 'status'
+ say $P3
+ goto got_task
+
+ no_task:
+ say 'no task to retrieve'
+
+ got_task:
+ say 1
+
+ push_eh bad_initializer
+ $P0 = new 'Scheduler', id
+ pop_eh
+
+ say "No exception on invalid initializer? Uh oh!"
+ end
+
+ bad_initializer:
+ say "Caught exception on bad initializer"
+ end
+ .end
+CODE
+created
+1
+Caught exception on bad initializer
+OUT
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Please sign in to comment.
Something went wrong with that request. Please try again.