NAME ^

src/pmc/task.pmc - A concurrent task

DESCRIPTION ^

Implements the basic task behavior for the concurrency scheduler.

Functions ^

void init()

Initialize a concurrency task object.

void init_pmc(PMC *data)

Initializes a new Task with a Hash PMC with any or all of the keys:

id

An Integer representing the task's unique identifier.

type

A String representing the type of the task.

subtype

A String representing the subtype of the task. (Used mostly by events and exceptions to identify appropriate handlers.)

priority

An Integer representing the task's priority, from 0 to 100.

status

A String representing the task's status, one of created, invoked, inprocess, or completed.

birthtime

The time at which this Task was inserted into the task list.

code

A Sub or descendent PMC related to this task.

interp

An interpreter in which to execute this task.

*/

    void init_pmc(PMC *data) {
        PMC         *elem;
        Parrot_Task *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_Task);

        /* 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;

        elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "type"));
        if (! PMC_IS_NULL(elem))
            core_struct->type = VTABLE_get_string(INTERP, elem);
        else
            core_struct->type = CONST_STRING(INTERP, "");

        elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "subtype"));
        if (! PMC_IS_NULL(elem))
            core_struct->subtype = VTABLE_get_string(INTERP, elem);
        else
            core_struct->subtype = CONST_STRING(INTERP, "");

        elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "priority"));
        if (! PMC_IS_NULL(elem))
            core_struct->priority = VTABLE_get_integer(INTERP, elem);
        else
            core_struct->priority = 0;

        elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "status"));
        if (! PMC_IS_NULL(elem))
            core_struct->status = VTABLE_get_string(INTERP, elem);
        else
            core_struct->status = CONST_STRING(INTERP, "created");

        elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "birthtime"));
        if (! PMC_IS_NULL(elem))
            core_struct->birthtime = VTABLE_get_integer(INTERP, elem);
        else
            core_struct->birthtime = 0;

        core_struct->codeblock =
            VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "code"));
        core_struct->interp =
            VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "interp"));
    }
/*

PMC *get_attr_str(STRING *name)

Gets the value of an attribute for this task.

void set_attr_str(STRING *name, PMC *value)

Sets the value of an attribute for this task.

INTVAL get_integer()

Retrieves the task ID for this task.

void set_integer_native(INTVAL value)

Sets the task ID of the task.

void destroy()

Free the task's underlying struct.

void mark()

Mark any referenced strings and PMCs.

void visit(visit_info *info)

This is used by freeze/thaw to visit the contents of the task.

*info is the visit info, (see include/parrot/pmc_freeze.h).

void freeze(visit_info *info)

Used to archive the task.

void thaw(visit_info *info)

Used to unarchive the task.

void thawfinish(visit_info *info)

Called after the task has been thawed.

SEE ALSO ^

docs/pdds/pdd15_objects.pod.


parrot