Skip to content

Commit

Permalink
Unify implementations in Parrot_thread_schedule_task and schedule_pro…
Browse files Browse the repository at this point in the history
…xied

Unified the implementations and moved them into
Parrot_thread_create_local_task
  • Loading branch information
niner committed Dec 16, 2011
1 parent 8aa61aa commit 37b624a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
13 changes: 13 additions & 0 deletions include/parrot/thread.h
Expand Up @@ -130,6 +130,14 @@ PARROT_CANNOT_RETURN_NULL
PMC * Parrot_thread_create(PARROT_INTERP, INTVAL type, INTVAL clone_flags)
__attribute__nonnull__(1);

PARROT_CANNOT_RETURN_NULL
PMC* Parrot_thread_create_local_task(PARROT_INTERP,
ARGIN(Parrot_Interp const thread_interp),
ARGIN(PMC *task))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);

PARROT_CANNOT_RETURN_NULL
PMC* Parrot_thread_create_proxy(PARROT_INTERP,
ARGIN(Parrot_Interp const thread),
Expand Down Expand Up @@ -194,6 +202,11 @@ PMC * Parrot_thread_transfer_sub(
#define ASSERT_ARGS_Parrot_clone_code __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_thread_create __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_thread_create_local_task \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(thread_interp) \
, PARROT_ASSERT_ARG(task))
#define ASSERT_ARGS_Parrot_thread_create_proxy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(thread) \
Expand Down
15 changes: 1 addition & 14 deletions src/pmc/parrotinterpreter.pmc
Expand Up @@ -759,21 +759,8 @@ Schedules the given task on the proxy's interpreter.
METHOD schedule_proxied(PMC *task, PMC *proxy) {
Parrot_Proxy_attributes * const core_struct = PARROT_PROXY(proxy);
Interp * const proxied_interp = core_struct->interp;
Parrot_Task_attributes * const task_struct = PARROT_TASK(task);

PMC * const local_task =
Parrot_pmc_new(proxied_interp, enum_class_Task);
Parrot_Task_attributes * const new_struct = PARROT_TASK(local_task);

if (task_struct->code->vtable->base_type == enum_class_Proxy)
new_struct->code = PARROT_PROXY(task_struct->code)->target;
else
new_struct->code =
Parrot_thread_make_local_copy(proxied_interp, interp, task_struct->code);
if (task_struct->data) {
new_struct->data = PARROT_PROXY(task_struct->data)->target;
}
PARROT_GC_WRITE_BARRIER(proxied_interp, local_task);
Parrot_thread_create_local_task(INTERP, proxied_interp, task);

Parrot_cx_schedule_immediate(proxied_interp, local_task);
/*TODO: investigate why it's not neccessary to send a signal to the process here
Expand Down
50 changes: 40 additions & 10 deletions src/thread.c
Expand Up @@ -139,29 +139,39 @@ Parrot_thread_create_proxy(PARROT_INTERP, ARGIN(Parrot_Interp const thread), ARG

/*
=item C<void Parrot_thread_schedule_task(PARROT_INTERP, Interp *thread_interp,
PMC *task)>
=item C<PMC* Parrot_thread_create_local_task(PARROT_INTERP, Parrot_Interp const
thread_interp, PMC *task)>
Schedule a task with the thread's scheduler.
Create a copy of the task coming from interp local to thread.
=cut
*/

void
Parrot_thread_schedule_task(PARROT_INTERP, ARGIN(Interp *thread_interp), ARGIN(PMC *task))
PARROT_CANNOT_RETURN_NULL
PMC*
Parrot_thread_create_local_task(PARROT_INTERP, ARGIN(Parrot_Interp const thread_interp), ARGIN(PMC *task))
{
ASSERT_ARGS(Parrot_thread_schedule_task)
ASSERT_ARGS(Parrot_thread_create_local_task)

PMC * const local_task = Parrot_pmc_new(thread_interp, enum_class_Task);
Parrot_Task_attributes * const new_struct = PARROT_TASK(local_task),
* const old_struct = PARROT_TASK(task);
PMC * const shared = old_struct->shared;
INTVAL i, elements = VTABLE_get_integer(interp, shared);

new_struct->code = Parrot_clone(thread_interp, old_struct->code);
new_struct->data = PMC_IS_NULL(old_struct->data)
? PMCNULL
: Parrot_clone(thread_interp, old_struct->data);

if (old_struct->code->vtable->base_type == enum_class_Proxy)
new_struct->code = PARROT_PROXY(old_struct->code)->target;
else
new_struct->code = Parrot_clone(thread_interp, old_struct->code);

if (old_struct->data && ! PMC_IS_NULL(old_struct->data))
if (old_struct->data->vtable->base_type == enum_class_Proxy)
new_struct->data = PARROT_PROXY(old_struct->data)->target;
else
new_struct->data = Parrot_clone(thread_interp, old_struct->data);

PARROT_GC_WRITE_BARRIER(thread_interp, local_task);

for (i = 0; i < elements; i++) {
Expand All @@ -171,6 +181,26 @@ Parrot_thread_schedule_task(PARROT_INTERP, ARGIN(Interp *thread_interp), ARGIN(P
Parrot_thread_create_proxy(interp, thread_interp, data));
}

return local_task;
}

/*
=item C<void Parrot_thread_schedule_task(PARROT_INTERP, Interp *thread_interp,
PMC *task)>
Schedule a task with the thread's scheduler.
=cut
*/

void
Parrot_thread_schedule_task(PARROT_INTERP, ARGIN(Interp *thread_interp), ARGIN(PMC *task))
{
ASSERT_ARGS(Parrot_thread_schedule_task)
PMC * const local_task = Parrot_thread_create_local_task(interp, thread_interp, task);

VTABLE_push_pmc(thread_interp, thread_interp->scheduler, local_task);
}

Expand Down

0 comments on commit 37b624a

Please sign in to comment.