Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleanup Scheduler.pmc and Task.pmc. Add const for the optimizer. Fix …

…a bug in Scheduler.active_tasks() involving a bad PCC call.
  • Loading branch information...
commit 9ddac318b2cc311236f8fbf27ea49afbb95421e4 1 parent 78459c0
@Whiteknight Whiteknight authored
Showing with 29 additions and 36 deletions.
  1. +10 −10 src/pmc/scheduler.pmc
  2. +19 −26 src/pmc/task.pmc
View
20 src/pmc/scheduler.pmc
@@ -120,8 +120,8 @@ current maximum, and a birthtime of the current time.
void push_pmc(PMC *task) {
/* TODO: This doesn't appear to do anything */
Parrot_Scheduler_attributes * const core_struct = PARROT_SCHEDULER(SELF);
- PMC *const type_pmc = VTABLE_get_attr_str(interp, task, CONST_STRING(interp, "type"));
- STRING *const type = VTABLE_get_string(interp, type_pmc);
+ PMC * const type_pmc = VTABLE_get_attr_str(interp, task, CONST_STRING(interp, "type"));
+ STRING * const type = VTABLE_get_string(interp, type_pmc);
}
@@ -137,8 +137,8 @@ recalculates it before retrieving the next task.
*/
VTABLE PMC *pop_pmc() {
- Parrot_Scheduler_attributes *core_struct = PARROT_SCHEDULER(SELF);
- PMC *task = VTABLE_shift_pmc(INTERP, core_struct->task_queue);
+ Parrot_Scheduler_attributes * const core_struct = PARROT_SCHEDULER(SELF);
+ PMC * const task = VTABLE_shift_pmc(INTERP, core_struct->task_queue);
return task;
}
@@ -303,15 +303,15 @@ Returns a ResizablePMCArray containing pointers to all active tasks.
METHOD active_tasks() {
Parrot_Scheduler_attributes *sdata = PARROT_SCHEDULER(SELF);
- PMC *tasks = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
- PMC *iter = Parrot_pmc_new_init(interp, enum_class_HashIterator, sdata->all_tasks);
+ PMC * const tasks = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
+ PMC * const iter = Parrot_pmc_new_init(interp, enum_class_HashIterator, sdata->all_tasks);
while (!VTABLE_get_bool(interp, iter)) {
- PMC *pair = VTABLE_shift_pmc(interp, iter);
- PMC *task;
- STRING *value = CONST_STRING(interp, "value");
+ PMC * const pair = VTABLE_shift_pmc(interp, iter);
+ PMC * task = PMCNULL;
+ STRING * const value = CONST_STRING(interp, "value");
Parrot_pcc_invoke_method_from_c_args(interp, pair,
- value, "->P", task);
+ value, "->P", &task);
VTABLE_push_pmc(interp, tasks, task);
}
View
45 src/pmc/task.pmc
@@ -46,8 +46,9 @@ Initialize a concurrency task object.
*/
VTABLE void init() {
- Parrot_Task_attributes *const core_struct = PARROT_TASK(SELF);
- Parrot_Scheduler_attributes *sched_data = PARROT_SCHEDULER(interp->scheduler);
+ Parrot_Task_attributes * const core_struct = PARROT_TASK(SELF);
+ Parrot_Scheduler_attributes * const sched_data =
+ PARROT_SCHEDULER(interp->scheduler);
/* Set flags for custom GC mark. */
PObj_custom_mark_SET(SELF);
@@ -58,12 +59,8 @@ Initialize a concurrency task object.
core_struct->data = PMCNULL;
core_struct->interp = INTERP;
core_struct->killed = 0;
- core_struct->mailbox = PMCNULL;
- core_struct->waiters = PMCNULL;
- /*
- core_struct->mailbox = Parrot_pmc_new(interp, enum_class_PMCList);
- core_struct->waiters = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
- */
+ core_struct->mailbox = PMCNULL; /* Created lazily on demand */
+ core_struct->waiters = PMCNULL; /* Created lazily on demand */
/* Assign a unique ID */
/* TODO: Fix collisions. */
@@ -104,7 +101,7 @@ Some data that will be passed to C<code> when invoked.
VTABLE void init_pmc(PMC *data) {
PMC *elem;
- Parrot_Task_attributes *core_struct = PARROT_TASK(SELF);
+ Parrot_Task_attributes * const core_struct = PARROT_TASK(SELF);
SELF.init();
@@ -144,9 +141,10 @@ code as the first argument.
*/
VTABLE opcode_t *invoke(void *next) {
- Parrot_Task_attributes *const task = PARROT_TASK(SELF);
- Parrot_Scheduler_attributes *sdata = PARROT_SCHEDULER(interp->scheduler);
- PMC *active_tasks = sdata->all_tasks;
+ Parrot_Task_attributes * const task = PARROT_TASK(SELF);
+ Parrot_Scheduler_attributes * const sdata =
+ PARROT_SCHEDULER(interp->scheduler);
+ PMC * const active_tasks = sdata->all_tasks;
/* If a task is pre-empted, this will be set again. */
TASK_in_preempt_CLEAR(SELF);
@@ -170,20 +168,18 @@ code as the first argument.
/* The task is done. */
/* Remove it from the set of active Tasks */
- int i, n;
- PMC *task_id = Parrot_pmc_new(interp, enum_class_Integer);
+ int i, n = 0;
+ PMC * const task_id = Parrot_pmc_new(interp, enum_class_Integer);
VTABLE_set_integer_native(interp, task_id, task->id);
TASK_active_CLEAR(SELF);
VTABLE_delete_keyed(interp, active_tasks, task_id);
/* schedule any waiters. */
- if (PMC_IS_NULL(task->waiters))
- n = 0;
- else
+ if (!PMC_IS_NULL(task->waiters))
n = VTABLE_get_integer(interp, task->waiters);
for (i = 0; i < n; ++i) {
- PMC *wtask = VTABLE_get_pmc_keyed_int(interp, task->waiters, i);
+ PMC * const wtask = VTABLE_get_pmc_keyed_int(interp, task->waiters, i);
Parrot_cx_schedule_task(interp, wtask);
}
}
@@ -227,7 +223,7 @@ Gets the value of an attribute for this task.
VTABLE PMC *get_attr_str(STRING *name) {
Parrot_Task_attributes * const core_struct = PARROT_TASK(SELF);
- PMC *value;
+ PMC * value = PMCNULL;
if (Parrot_str_equal(INTERP, name, CONST_STRING(INTERP, "birthtime"))) {
value = Parrot_pmc_new(INTERP, enum_class_Float);
@@ -239,9 +235,6 @@ Gets the value of an attribute for this task.
else if (Parrot_str_equal(INTERP, name, CONST_STRING(INTERP, "data"))) {
value = core_struct->data;
}
- else {
- value = PMCNULL;
- }
return value;
}
@@ -357,9 +350,9 @@ Called after the task has been thawed.
*/
VTABLE void thawfinish(PMC *info) {
- Parrot_Task_attributes * core_struct = PARROT_TASK(SELF);
+ /* Parrot_Task_attributes * const core_struct = PARROT_TASK(SELF); */
- UNUSED(core_struct); /* Do nothing */
+ /* UNUSED(core_struct); *//* Do nothing */
}
/*
@@ -379,7 +372,7 @@ Send a message to this task.
*/
METHOD send(PMC *message) {
- Parrot_Task_attributes *tdata = PARROT_TASK(SELF);
+ Parrot_Task_attributes * const tdata = PARROT_TASK(SELF);
if (PMC_IS_NULL(tdata->mailbox))
tdata->mailbox = Parrot_pmc_new(interp, enum_class_PMCList);
VTABLE_push_pmc(interp, tdata->mailbox, message);
@@ -401,7 +394,7 @@ Kill this task.
*/
METHOD kill() {
- Parrot_Task_attributes *tdata = PARROT_TASK(SELF);
+ Parrot_Task_attributes * const tdata = PARROT_TASK(SELF);
tdata->killed = 1;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.