[svn:parrot] r48105 - in branches/gsoc_threads: include/parrot src src/ops src/pmc t/native_pbc t/pmc
Chandon at svn.parrot.org
Chandon at svn.parrot.org
Sun Jul 18 23:38:22 UTC 2010
Author: Chandon
Date: Sun Jul 18 23:38:22 2010
New Revision: 48105
URL: https://trac.parrot.org/parrot/changeset/48105
Log:
[gsoc_threads] Naming consistency.
Modified:
branches/gsoc_threads/include/parrot/scheduler.h
branches/gsoc_threads/src/events.c
branches/gsoc_threads/src/ops/core.ops
branches/gsoc_threads/src/ops/core_ops.c
branches/gsoc_threads/src/pmc/task.pmc
branches/gsoc_threads/src/scheduler.c
branches/gsoc_threads/t/native_pbc/annotations.pbc
branches/gsoc_threads/t/native_pbc/integer.pbc
branches/gsoc_threads/t/native_pbc/number.pbc
branches/gsoc_threads/t/native_pbc/string.pbc
branches/gsoc_threads/t/pmc/task.t (contents, props changed)
Modified: branches/gsoc_threads/include/parrot/scheduler.h
==============================================================================
--- branches/gsoc_threads/include/parrot/scheduler.h Sun Jul 18 20:53:14 2010 (r48104)
+++ branches/gsoc_threads/include/parrot/scheduler.h Sun Jul 18 23:38:22 2010 (r48105)
@@ -48,9 +48,13 @@
PMC * Parrot_cx_delete_suspend_for_gc(PARROT_INTERP)
__attribute__nonnull__(1);
+PARROT_EXPORT
+void Parrot_cx_request_suspend_for_gc(PARROT_INTERP)
+ __attribute__nonnull__(1);
+
PARROT_CANNOT_RETURN_NULL
PARROT_EXPORT
-opcode_t* Parrot_cx_handle_tasks(PARROT_INTERP,
+opcode_t* Parrot_cx_run_scheduler(PARROT_INTERP,
ARGMOD(PMC *scheduler),
ARGIN(opcode_t *next))
__attribute__nonnull__(1)
@@ -59,10 +63,6 @@
FUNC_MODIFIES(*scheduler);
PARROT_EXPORT
-void Parrot_cx_request_suspend_for_gc(PARROT_INTERP)
- __attribute__nonnull__(1);
-
-PARROT_EXPORT
void Parrot_cx_runloop_end(PARROT_INTERP)
__attribute__nonnull__(1);
@@ -102,7 +102,7 @@
FUNC_MODIFIES(*scheduler);
PARROT_CANNOT_RETURN_NULL
-opcode_t* Parrot_cx_check_tasks(PARROT_INTERP, ARGIN(opcode_t* next))
+opcode_t* Parrot_cx_check_scheduler(PARROT_INTERP, ARGIN(opcode_t* next))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
@@ -115,7 +115,7 @@
FUNC_MODIFIES(*scheduler);
PARROT_CANNOT_RETURN_NULL
-opcode_t* Parrot_cx_reschedule(PARROT_INTERP,
+opcode_t* Parrot_cx_preempt_task(PARROT_INTERP,
ARGMOD(PMC *scheduler),
ARGIN(opcode_t *next))
__attribute__nonnull__(1)
@@ -141,13 +141,13 @@
#define ASSERT_ARGS_Parrot_cx_delete_suspend_for_gc \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_Parrot_cx_handle_tasks __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(scheduler) \
- , PARROT_ASSERT_ARG(next))
#define ASSERT_ARGS_Parrot_cx_request_suspend_for_gc \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_cx_run_scheduler __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(scheduler) \
+ , PARROT_ASSERT_ARG(next))
#define ASSERT_ARGS_Parrot_cx_runloop_end __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_cx_schedule_alarm __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -167,7 +167,7 @@
#define ASSERT_ARGS_Parrot_cx_check_quantum __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(scheduler))
-#define ASSERT_ARGS_Parrot_cx_check_tasks __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+#define ASSERT_ARGS_Parrot_cx_check_scheduler __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(next))
#define ASSERT_ARGS_Parrot_cx_init_scheduler __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -175,7 +175,7 @@
#define ASSERT_ARGS_Parrot_cx_next_task __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(scheduler))
-#define ASSERT_ARGS_Parrot_cx_reschedule __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+#define ASSERT_ARGS_Parrot_cx_preempt_task __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(scheduler) \
, PARROT_ASSERT_ARG(next))
Modified: branches/gsoc_threads/src/events.c
==============================================================================
--- branches/gsoc_threads/src/events.c Sun Jul 18 20:53:14 2010 (r48104)
+++ branches/gsoc_threads/src/events.c Sun Jul 18 23:38:22 2010 (r48105)
@@ -23,6 +23,48 @@
/* HEADERIZER HFILE: include/parrot/events.h */
+
+
+#ifdef PARROT_CX_BUILD_OLD_STUFF
+ Parrot_cx_refresh_task_list(interp, scheduler);
+
+ while (VTABLE_get_integer(interp, scheduler) > 0) {
+ PMC * const task = VTABLE_pop_pmc(interp, scheduler);
+ if (!PMC_IS_NULL(task)) {
+ PMC * const type_pmc = VTABLE_get_attr_str(interp, task, CONST_STRING(interp, "type"));
+ STRING * const type = VTABLE_get_string(interp, type_pmc);
+
+ if (Parrot_str_equal(interp, type, CONST_STRING(interp, "callback"))) {
+ Parrot_cx_invoke_callback(interp, task);
+ }
+ else if (Parrot_str_equal(interp, type, CONST_STRING(interp, "timer"))) {
+ Parrot_cx_timer_invoke(interp, task);
+ }
+ else if (Parrot_str_equal(interp, type, CONST_STRING(interp, "event"))) {
+ PMC * const handler = Parrot_cx_find_handler_for_task(interp, task);
+ if (!PMC_IS_NULL(handler)) {
+ PMC * const handler_sub = VTABLE_get_attr_str(interp, handler, CONST_STRING(interp, "code"));
+ Parrot_pcc_invoke_sub_from_c_args(interp, handler_sub,
+ "PP->", handler, task);
+ }
+ }
+ else {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Unknown task type '%Ss'.\n", type);
+ }
+
+ Parrot_cx_delete_task(interp, task);
+ }
+
+ /* If the scheduler was flagged to terminate, make sure you process all
+ * tasks. */
+ if (SCHEDULER_terminate_requested_TEST(scheduler))
+ Parrot_cx_refresh_task_list(interp, scheduler);
+
+ } /* end of pending tasks */
+#endif
+
+
/*
=item C<void Parrot_cx_add_handler_local(PARROT_INTERP, PMC *handler)>
Modified: branches/gsoc_threads/src/ops/core.ops
==============================================================================
--- branches/gsoc_threads/src/ops/core.ops Sun Jul 18 20:53:14 2010 (r48104)
+++ branches/gsoc_threads/src/ops/core.ops Sun Jul 18 23:38:22 2010 (r48105)
@@ -97,7 +97,7 @@
inline op check_events() :base_core :flow {
opcode_t *next = expr NEXT();
- next = Parrot_cx_check_tasks(interp, next);
+ next = Parrot_cx_check_scheduler(interp, next);
goto ADDRESS(next); /* force this being a branch op */
}
@@ -153,7 +153,7 @@
=cut
inline op branch(in LABEL) :base_loop :flow {
- if(Parrot_cx_check_tasks(interp, cur_opcode + $1) == 0)
+ if(Parrot_cx_check_scheduler(interp, cur_opcode + $1) == 0)
return 0;
goto OFFSET($1);
}
Modified: branches/gsoc_threads/src/ops/core_ops.c
==============================================================================
--- branches/gsoc_threads/src/ops/core_ops.c Sun Jul 18 20:53:14 2010 (r48104)
+++ branches/gsoc_threads/src/ops/core_ops.c Sun Jul 18 23:38:22 2010 (r48105)
@@ -14182,7 +14182,7 @@
Parrot_check_events(opcode_t *cur_opcode, PARROT_INTERP) {
const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
opcode_t *next = cur_opcode + 1;
- next = Parrot_cx_check_tasks(interp, next);return (opcode_t *)next; /* force this being a branch op */
+ next = Parrot_cx_check_scheduler(interp, next);return (opcode_t *)next; /* force this being a branch op */
}
opcode_t *
@@ -14231,14 +14231,14 @@
opcode_t *
Parrot_branch_i(opcode_t *cur_opcode, PARROT_INTERP) {
const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
- if(Parrot_cx_check_tasks(interp, cur_opcode + IREG(1)) == 0)
+ if(Parrot_cx_check_scheduler(interp, cur_opcode + IREG(1)) == 0)
return 0;return (opcode_t *)cur_opcode + IREG(1);
}
opcode_t *
Parrot_branch_ic(opcode_t *cur_opcode, PARROT_INTERP) {
const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
- if(Parrot_cx_check_tasks(interp, cur_opcode + cur_opcode[1]) == 0)
+ if(Parrot_cx_check_scheduler(interp, cur_opcode + cur_opcode[1]) == 0)
return 0;return (opcode_t *)cur_opcode + cur_opcode[1];
}
Modified: branches/gsoc_threads/src/pmc/task.pmc
==============================================================================
--- branches/gsoc_threads/src/pmc/task.pmc Sun Jul 18 20:53:14 2010 (r48104)
+++ branches/gsoc_threads/src/pmc/task.pmc Sun Jul 18 23:38:22 2010 (r48105)
@@ -29,6 +29,7 @@
ATTR Parrot_Interp interp; /* The interpreter that created the task. */
ATTR PMC *code; /* An (optional) code for the task. */
ATTR PMC *data; /* Additional data for the task. */
+ ATTR INTVAL killed; /* Dead tasks don't get run. */
/*
@@ -51,6 +52,7 @@
core_struct->code = PMCNULL;
core_struct->data = PMCNULL;
core_struct->interp = INTERP;
+ core_struct->killed = 0;
}
/*
@@ -85,31 +87,34 @@
VTABLE void init_pmc(PMC *data) {
PMC *elem;
- Parrot_Task_attributes *core_struct;
-
- if (! VTABLE_isa(INTERP, data, CONST_STRING(INTERP, "Hash")))
- Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
- "Task initializer must be a Hash");
+ Parrot_Task_attributes *core_struct = PARROT_TASK(SELF);
SELF.init();
- core_struct = (Parrot_Task_attributes *) PMC_data(SELF);
-
- elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "birthtime"));
- if (! PMC_IS_NULL(elem))
- core_struct->birthtime = VTABLE_get_number(INTERP, elem);
-
- elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "code"));
- if (! PMC_IS_NULL(elem))
- core_struct->code = elem;
-
- elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "data"));
- if (! PMC_IS_NULL(elem))
- core_struct->data = elem;
-
- elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "interp"));
- if (! PMC_IS_NULL(elem))
- core_struct->interp = elem;
+ if (VTABLE_isa(INTERP, data, CONST_STRING(INTERP, "Sub"))) {
+ core_struct->code = data;
+ }
+ else if (VTABLE_isa(INTERP, data, CONST_STRING(INTERP, "Hash"))) {
+ elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "birthtime"));
+ if (! PMC_IS_NULL(elem))
+ core_struct->birthtime = VTABLE_get_number(INTERP, elem);
+
+ elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "code"));
+ if (! PMC_IS_NULL(elem))
+ core_struct->code = elem;
+
+ elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "data"));
+ if (! PMC_IS_NULL(elem))
+ core_struct->data = elem;
+
+ elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "interp"));
+ if (! PMC_IS_NULL(elem))
+ core_struct->interp = elem;
+ }
+ else {
+ Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
+ "Task initializer must be a Hash or Sub");
+ }
}
/*
@@ -128,6 +133,9 @@
VTABLE opcode_t *invoke(void *next) {
Parrot_Task_attributes *const task = PARROT_TASK(SELF);
+ if (task->killed)
+ return (opcode_t*) 0;
+
if (PMC_IS_NULL(task->code))
return (opcode_t*) next;
@@ -174,6 +182,7 @@
=cut
*/
+
VTABLE PMC *get_attr_str(STRING *name) {
Parrot_Task_attributes * const core_struct = PARROT_TASK(SELF);
PMC *value;
@@ -336,6 +345,53 @@
UNUSED(core_struct); /* Do nothing */
}
+/*
+
+=back
+
+=head2 Methdods
+
+=over 4
+
+=item METHOD send(PMC *message)
+
+Send a message to this task.
+
+=cut
+
+*/
+
+ METHOD send(PMC *message) {
+ fprintf(stderr, "Task#send not implemented.\n");
+ }
+
+/*
+
+=item METHOD wait()
+
+Block until this task ends.
+
+=cut
+
+*/
+
+ METHOD wait() {
+ fprintf(stderr, "Task#wait not implemented.\n");
+ }
+
+/*
+
+=item METHOD kill()
+
+Kill this task.
+
+=cut
+
+*/
+
+ METHOD kill() {
+ fprintf(stderr, "Task#kill not implemented.\n");
+ }
}
/*
Modified: branches/gsoc_threads/src/scheduler.c
==============================================================================
--- branches/gsoc_threads/src/scheduler.c Sun Jul 18 20:53:14 2010 (r48104)
+++ branches/gsoc_threads/src/scheduler.c Sun Jul 18 23:38:22 2010 (r48105)
@@ -147,10 +147,9 @@
/*
-=item C<opcode_t* Parrot_cx_check_tasks(PARROT_INTERP, opcode_t* next)>
+=item C<opcode_t* Parrot_cx_check_scheduler(PARROT_INTERP, opcode_t* next)>
-If a wake request has been received or an OS timer has expired
-then deal with that.
+Does the scheduler need to wake up and do anything? If so, do that now.
=cut
@@ -158,15 +157,15 @@
PARROT_CANNOT_RETURN_NULL
opcode_t*
-Parrot_cx_check_tasks(PARROT_INTERP, ARGIN(opcode_t* next))
+Parrot_cx_check_scheduler(PARROT_INTERP, ARGIN(opcode_t* next))
{
- ASSERT_ARGS(Parrot_cx_check_tasks)
+ ASSERT_ARGS(Parrot_cx_check_scheduler)
PMC *scheduler = interp->scheduler;
if (Parrot_alarm_check(&(interp->last_alarm))
|| SCHEDULER_wake_requested_TEST(scheduler)) {
SCHEDULER_wake_requested_CLEAR(scheduler);
- return Parrot_cx_handle_tasks(interp, scheduler, next);
+ return Parrot_cx_run_scheduler(interp, scheduler, next);
}
return next;
@@ -174,8 +173,8 @@
/*
-=item C<opcode_t* Parrot_cx_handle_tasks(PARROT_INTERP, PMC *scheduler, opcode_t
-*next)>
+=item C<opcode_t* Parrot_cx_run_scheduler(PARROT_INTERP, PMC *scheduler,
+opcode_t *next)>
Checks to see if any tasks need to be scheduled or if the current task
needs to be pre-empted.
@@ -187,9 +186,9 @@
PARROT_CANNOT_RETURN_NULL
PARROT_EXPORT
opcode_t*
-Parrot_cx_handle_tasks(PARROT_INTERP, ARGMOD(PMC *scheduler), ARGIN(opcode_t *next))
+Parrot_cx_run_scheduler(PARROT_INTERP, ARGMOD(PMC *scheduler), ARGIN(opcode_t *next))
{
- ASSERT_ARGS(Parrot_cx_handle_tasks)
+ ASSERT_ARGS(Parrot_cx_run_scheduler)
Parrot_cx_check_alarms(interp, scheduler);
Parrot_cx_check_quantum(interp, scheduler);
@@ -200,49 +199,10 @@
/* Exiting the runloop to swap tasks doesn't play
nice with nested runloops */
if (interp->current_runloop_level <= 1)
- return Parrot_cx_reschedule(interp, scheduler, next);
+ return Parrot_cx_preempt_task(interp, scheduler, next);
}
return next;
-
-#ifdef PARROT_CX_BUILD_OLD_STUFF
- Parrot_cx_refresh_task_list(interp, scheduler);
-
- while (VTABLE_get_integer(interp, scheduler) > 0) {
- PMC * const task = VTABLE_pop_pmc(interp, scheduler);
- if (!PMC_IS_NULL(task)) {
- PMC * const type_pmc = VTABLE_get_attr_str(interp, task, CONST_STRING(interp, "type"));
- STRING * const type = VTABLE_get_string(interp, type_pmc);
-
- if (Parrot_str_equal(interp, type, CONST_STRING(interp, "callback"))) {
- Parrot_cx_invoke_callback(interp, task);
- }
- else if (Parrot_str_equal(interp, type, CONST_STRING(interp, "timer"))) {
- Parrot_cx_timer_invoke(interp, task);
- }
- else if (Parrot_str_equal(interp, type, CONST_STRING(interp, "event"))) {
- PMC * const handler = Parrot_cx_find_handler_for_task(interp, task);
- if (!PMC_IS_NULL(handler)) {
- PMC * const handler_sub = VTABLE_get_attr_str(interp, handler, CONST_STRING(interp, "code"));
- Parrot_pcc_invoke_sub_from_c_args(interp, handler_sub,
- "PP->", handler, task);
- }
- }
- else {
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Unknown task type '%Ss'.\n", type);
- }
-
- Parrot_cx_delete_task(interp, task);
- }
-
- /* If the scheduler was flagged to terminate, make sure you process all
- * tasks. */
- if (SCHEDULER_terminate_requested_TEST(scheduler))
- Parrot_cx_refresh_task_list(interp, scheduler);
-
- } /* end of pending tasks */
-#endif
}
/*
@@ -297,7 +257,7 @@
}
/*
-=item C<opcode_t* Parrot_cx_reschedule(PARROT_INTERP, PMC *scheduler, opcode_t
+=item C<opcode_t* Parrot_cx_preempt_task(PARROT_INTERP, PMC *scheduler, opcode_t
*next)>
Pre-empt the current task. It goes on the foot of the task queue,
@@ -308,9 +268,9 @@
PARROT_CANNOT_RETURN_NULL
opcode_t*
-Parrot_cx_reschedule(PARROT_INTERP, ARGMOD(PMC *scheduler), ARGIN(opcode_t *next))
+Parrot_cx_preempt_task(PARROT_INTERP, ARGMOD(PMC *scheduler), ARGIN(opcode_t *next))
{
- ASSERT_ARGS(Parrot_cx_reschedule)
+ ASSERT_ARGS(Parrot_cx_preempt_task)
Parrot_Scheduler_attributes *sched = PARROT_SCHEDULER(scheduler);
PMC *cont = Parrot_pmc_new(interp, enum_class_Continuation);
@@ -386,6 +346,12 @@
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Scheduler was not initialized for this interpreter.\n");
+/*
+ if (!VTABLE_isa(interp, subclass, CONST_S TRING(interp, "Task")))
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Cannot schedule stuff other than Tasks.\n");
+*/
+
VTABLE_push_pmc(interp, sched->task_queue, task);
}
Modified: branches/gsoc_threads/t/native_pbc/annotations.pbc
==============================================================================
Binary file (source and/or target). No diff available.
Modified: branches/gsoc_threads/t/native_pbc/integer.pbc
==============================================================================
Binary file (source and/or target). No diff available.
Modified: branches/gsoc_threads/t/native_pbc/number.pbc
==============================================================================
Binary file (source and/or target). No diff available.
Modified: branches/gsoc_threads/t/native_pbc/string.pbc
==============================================================================
Binary file (source and/or target). No diff available.
Modified: branches/gsoc_threads/t/pmc/task.t
==============================================================================
--- branches/gsoc_threads/t/pmc/task.t Sun Jul 18 20:53:14 2010 (r48104)
+++ branches/gsoc_threads/t/pmc/task.t Sun Jul 18 23:38:22 2010 (r48105)
@@ -0,0 +1,23 @@
+#! parrot
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+.sub main
+ .include 'test_more.pir'
+
+ plan(1)
+
+ ok1()
+
+ $P0 = new 'Task'
+.end
+
+.sub ok1
+ say "ok 1"
+.end
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
More information about the parrot-commits
mailing list