Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base: master
...
compare: rurban/task_interp
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 13, 2012
Reini Urban rurban add Task.get_integer, test wrong getinterp in Task
Inside a task getinterp should not return the global interp PMC from
the parent thread. Any function should know in which thread tid or task.id it runs.
We have no introspection to get the curent task nor interp.
e704427
Reini Urban rurban parrotinterpreter.t: add interp.current_task test (also fails) 5ebe7e9
6 src/pmc/parrotinterpreter.pmc
View
@@ -207,7 +207,7 @@ create_interp(ARGIN(PMC *self), ARGIN_NULLOK(Parrot_Interp parent))
pmclass ParrotInterpreter no_ro manual_attrs provides invokable {
ATTR struct parrot_interp_t *interp; /* this PMC's interpreter */
- ATTR INTVAL tid; /* thread id. Unused, see get_integer() */
+ ATTR INTVAL tid; /* thread id. See get_integer() */
ATTR PMC *args; /* args passed to this thread */
ATTR PMC *sub; /* this thread's sub */
@@ -259,6 +259,8 @@ Initializes the interpreter.
if (!PMC_interp(SELF))
create_interp(SELF, INTERP);
PObj_custom_destroy_SET(SELF);
+ if (INTERP->thread_data)
+ SETATTR_ParrotInterpreter_tid(INTERP, SELF, INTERP->thread_data->tid);
}
/*
@@ -282,6 +284,8 @@ C<parent> and uses that thread.
if (!PMC_interp(SELF))
create_interp(SELF, PMC_interp(parent));
PObj_custom_destroy_SET(SELF);
+ if (INTERP->thread_data)
+ SETATTR_ParrotInterpreter_tid(INTERP, SELF, INTERP->thread_data->tid);
}
14 src/pmc/task.pmc
View
@@ -250,6 +250,20 @@ Create a copy of the task, resetting status, ID, and birthtime.
/*
+=item C<INTVAL get_integer()>
+
+Returns the unique id of the task.
+
+=cut
+
+*/
+
+ VTABLE INTVAL get_integer() {
+ return PARROT_TASK(SELF)->id;
+ }
+
+/*
+
=item C<PMC *get_attr_str(STRING *name)>
Gets the value of an attribute for this task.
52 t/pmc/parrotinterpreter.t
View
@@ -1,5 +1,5 @@
#!./parrot
-# Copyright (C) 2006-2010, Parrot Foundation.
+# Copyright (C) 2006-2012, Parrot Foundation.
=head1 NAME
@@ -21,7 +21,7 @@ Tests the ParrotInterpreter PMC.
.sub main :main
.include 'test_more.pir'
- plan(14)
+ plan(19)
test_new() # 1 test
test_hll_map() # 3 tests
test_hll_map_invalid() # 1 tests
@@ -95,27 +95,27 @@ Tests the ParrotInterpreter PMC.
.lex 'foo', interp
$P0 = interp['sub';0]
- is($P0, 'test_inspect', 'Got ParrotInterp.sub')
+ is($P0, 'test_inspect', 'Got ParrotInterpreter.sub')
$P0 = interp['lexpad';0]
$I0 = isa $P0, 'LexPad'
- ok($I0, 'Got ParrotInterp.lexpad')
+ ok($I0, 'Got ParrotInterpreter.lexpad')
$P0 = interp['namespace';0]
$I0 = isa $P0, 'NameSpace'
- ok($I0, 'Got ParrotInterp.namespace')
+ ok($I0, 'Got ParrotInterpreter.namespace')
$P0 = interp['continuation';0]
$I0 = isa $P0, 'Continuation'
- ok($I0, 'Got ParrotInterp.continuation')
+ ok($I0, 'Got ParrotInterpreter.continuation')
$P0 = interp['annotations';1]
$S0 = $P0['foo']
- is($S0, 'bar', 'Got ParrotInterp.annotations')
+ is($S0, 'bar', 'Got ParrotInterpreter.annotations')
$P0 = interp['context';0]
$I0 = isa $P0, 'CallContext'
- ok($I0, 'Got ParrotInterp.context')
+ ok($I0, 'Got ParrotInterpreter.context')
# Add more tests for Context. E.g. it is correct Context by inspecting it.
$P0 = interp['packfile']
@@ -138,8 +138,44 @@ Tests the ParrotInterpreter PMC.
pop_eh
ok($I0, "Access to wrong depth throws exception")
+ $I0 = interp.'recursion_limit'()
+ ok($I0, "Got recursion_limit")
+
+ $I0 = interp
+ is($I0, 0, "Got parent tid==0")
+
+ $P0 = get_global 'task1'
+ $P1 = new 'Task', $P0
+ $I0 = $P1
+ $I1 = $I0 > 0
+ ok($I1, "child task.id > 0")
+ schedule $P1
+ wait $P1
+.end
+
+.sub task1
+ .local pmc interp, task
+ interp = getinterp
+ task = interp.'current_task'()
+ $I0 = interp
+ if $I0 > 0 goto t1
+ print "not "
+t1:
+ print "ok 18 #TODO no task interp yet, child.tid="
+ say $I0
+
+ $I0 = task
+ if $I0 > 0 goto t2
+ print "not "
+t2:
+ print "ok 19 #TODO reflection in child task.id="
+ say $I0
+
+
+ exit 0
.end
+
# Local Variables:
# mode: pir
# fill-column: 100

No commit comments for this range

Something went wrong with that request. Please try again.