2 Copyright (C) 2001-2009, Parrot Foundation.
7 src/pmc/schedulermessage.pmc - The concurrency scheduler
11 Implements a message passed between concurrency schedulers.
13 =head2 Vtable Functions
21 #include "parrot/scheduler_private.h"
23 pmclass SchedulerMessage auto_attrs {
24 ATTR INTVAL id; /* The message's ID. */
25 ATTR STRING *type; /* The message's type. */
26 ATTR PMC *data; /* Additional data for the message. */
32 Initialize a concurrency scheduler message object.
39 Parrot_SchedulerMessage_attributes * const core_struct
40 = (Parrot_SchedulerMessage_attributes *) PMC_data(SELF);
42 /* Set flags for custom GC mark. */
43 PObj_custom_mark_SET(SELF);
45 /* Set up the core struct. */
47 core_struct->type = CONST_STRING(INTERP, "");
48 core_struct->data = PMCNULL;
53 =item C<void init_pmc(PMC *data)>
55 Initializes a new SchedulerMessage with a C<Hash> PMC with any or all of the
62 An C<Integer> representing the unique identifier for this scheduler message.
66 A C<String> representing the unique type for this scheduler message.
70 An C<PMC> representing the data passed in this scheduler message.
78 VTABLE void init_pmc(PMC *data) {
80 Parrot_SchedulerMessage_attributes *core_struct;
82 if (! VTABLE_isa(INTERP, data, CONST_STRING(INTERP, "Hash")))
83 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
84 "message initializer must be a Hash");
87 core_struct = PARROT_SCHEDULERMESSAGE(SELF);
89 elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "id"));
90 if (! PMC_IS_NULL(elem))
91 core_struct->id = VTABLE_get_integer(INTERP, elem);
93 elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "type"));
94 if (! PMC_IS_NULL(elem))
95 core_struct->type = VTABLE_get_string(INTERP, elem);
97 elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "data"));
98 if (! PMC_IS_NULL(elem))
99 core_struct->data = elem;
104 =item C<INTVAL get_integer()>
106 Retrieve the message ID.
112 VTABLE INTVAL get_integer() {
113 Parrot_SchedulerMessage_attributes * core_struct = PARROT_SCHEDULERMESSAGE(SELF);
114 return core_struct->id;
119 =item C<void set_integer_native(INTVAL value)>
127 VTABLE void set_integer_native(INTVAL value) {
128 Parrot_SchedulerMessage_attributes * core_struct = PARROT_SCHEDULERMESSAGE(SELF);
129 core_struct->id = value;
135 =item C<STRING * get_string()>
137 Retrieve the message type.
143 STRING * get_string() {
144 Parrot_SchedulerMessage_attributes * core_struct = PARROT_SCHEDULERMESSAGE(SELF);
145 return core_struct->type;
150 =item C<void set_string_native(STRING *value)>
152 Set the message type.
158 VTABLE void set_string_native(STRING *value) {
159 Parrot_SchedulerMessage_attributes * core_struct = PARROT_SCHEDULERMESSAGE(SELF);
160 core_struct->type = value;
166 =item C<PMC *share_ro()>
168 Set this PMC as shared.
174 VTABLE PMC *share_ro() {
176 Parrot_SchedulerMessage_attributes *shared_struct;
178 if (PObj_is_PMC_shared_TEST(SELF))
181 shared_self = pt_shared_fixup(INTERP, SELF);
182 shared_struct = PARROT_SCHEDULERMESSAGE(shared_self);
183 shared_struct->data = pt_shared_fixup(INTERP, shared_struct->data);
192 Mark any referenced strings and PMCs.
198 if (PARROT_SCHEDULERMESSAGE(SELF)) {
199 Parrot_SchedulerMessage_attributes * const core_struct =
200 PARROT_SCHEDULERMESSAGE(SELF);
202 Parrot_gc_mark_STRING_alive(interp, core_struct->type);
203 Parrot_gc_mark_PMC_alive(interp, core_struct->data);
209 =item C<void visit(PMC *info)>
211 This is used by freeze/thaw to visit the contents of the scheduler message.
213 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
219 VTABLE void visit(PMC *info) {
220 /* visit message data */
221 VISIT_PMC(INTERP, info, PARROT_SCHEDULERMESSAGE(SELF)->data);
226 =item C<void freeze(PMC *info)>
228 Used to archive the scheduler message.
234 VTABLE void freeze(PMC *info) {
235 Parrot_SchedulerMessage_attributes * const core_struct =
236 PARROT_SCHEDULERMESSAGE(SELF);
238 /* 1) freeze message id */
239 VTABLE_push_integer(INTERP, info, core_struct->id);
241 /* 2) freeze message type */
242 VTABLE_push_string(INTERP, info, core_struct->type);
247 =item C<void thaw(PMC *info)>
249 Used to unarchive the scheduler message.
255 VTABLE void thaw(PMC *info) {
256 /* 1. thaw message id */
257 const INTVAL id = VTABLE_shift_integer(INTERP, info);
259 /* 2. thaw message type */
260 STRING * const type = VTABLE_shift_string(INTERP, info);
262 /* Allocate the message's core data struct and set custom flags. */
265 /* Set the message's id to the frozen id */
266 PARROT_SCHEDULERMESSAGE(SELF)->id = id;
268 /* Set the message's type to the frozen type */
269 PARROT_SCHEDULERMESSAGE(SELF)->type = type;
280 F<docs/pdds/pdd25_concurrency.pod>.
288 * c-file-style: "parrot"
290 * vim: expandtab shiftwidth=4: