NAME ^

src/pmc/scheduler.pmc - The concurrency scheduler

DESCRIPTION ^

Implements the core concurrency scheduler.

Vtable Functions ^

void init()

Initialize a concurrency scheduler object.

void init_pmc(PMC *data)

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

id

An Integer representing the unique identifier for this scheduler.

*/

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

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

        core_struct->max_tid     = 0;
        core_struct->task_list   = pmc_new(interp, enum_class_Hash);
        core_struct->task_index  = pmc_new(interp, enum_class_ResizableIntegerArray);
        core_struct->handlers    = pmc_new(interp, enum_class_ResizablePMCArray);
        core_struct->interp      = INTERP;
    }
/*

void push_pmc(PMC *value)

Insert a task into the task list, giving it a task ID one higher than the current maximum.

PMC *pop_pmc()

Retrieve the next task from the task list. If the task index is invalid, recalculate it before retrieving the next task.

INTVAL get_integer()

Retrieve the number of pending tasks in the scheduler's task list.

void delete_keyed_int(INTVAL key)

Removes the task with the given task ID from the task list.

PMC *share_ro()

Set this PMC as shared.

void destroy()

Free the scheduler'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 scheduler.

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

void freeze(visit_info *info)

Used to archive the scheduler.

void thaw(visit_info *info)

Used to unarchive the scheduler.

void thawfinish(visit_info *info)

Called after the scheduler has been thawed.

Methods ^

PCCMETHOD add_handler(PMC *handler)

Add a handler to the scheduler.

PCCMETHOD find_handler(PMC *task)

Search for a handler for the given task. If no handler is found, return PMCNULL.

SEE ALSO ^

docs/pdds/pdd15_objects.pod.


parrot