parrotcode: A concurrent task | |
Contents | PMCs |
src/pmc/task.pmc - A concurrent task
Implements the basic task behavior for the concurrency scheduler.
void init()
void init_pmc(PMC *data)
Hash
PMC with any or all of the keys:id
Integer
representing the task's unique identifier.type
String
representing the type of the task.subtype
String
representing the subtype of the task.
(Used mostly by events and exceptions to identify appropriate handlers.)priority
Integer
representing the task's priority,
from 0 to 100.status
String
representing the task's status,
one of created
,
invoked
,
inprocess
,
or completed
.birthtime
code
Sub
or descendent PMC related to this task.interp
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)
void set_attr_str(STRING *name, PMC *value)
INTVAL get_integer()
void set_integer_native(INTVAL value)
void destroy()
void mark()
void visit(visit_info *info)
*info
is the visit info, (see include/parrot/pmc_freeze.h).void freeze(visit_info *info)
void thaw(visit_info *info)
void thawfinish(visit_info *info)
|