2 Copyright (C) 2001-2010, 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 /* HEADERIZER HFILE: none */
24 /* HEADERIZER BEGIN: static */
25 /* HEADERIZER END: static */
27 pmclass SchedulerMessage auto_attrs {
28 ATTR INTVAL id; /* The message's ID. */
29 ATTR STRING *type; /* The message's type. */
30 ATTR PMC *data; /* Additional data for the message. */
36 Initialize a concurrency scheduler message object.
43 Parrot_SchedulerMessage_attributes * const core_struct
44 = (Parrot_SchedulerMessage_attributes *) PMC_data(SELF);
46 /* Set flags for custom GC mark. */
47 PObj_custom_mark_SET(SELF);
49 /* Set up the core struct. */
51 core_struct->type = CONST_STRING(INTERP, "");
52 core_struct->data = PMCNULL;
57 =item C<void init_pmc(PMC *data)>
59 Initializes a new SchedulerMessage with a C<Hash> PMC with any or all of the
66 An C<Integer> representing the unique identifier for this scheduler message.
70 A C<String> representing the unique type for this scheduler message.
74 An C<PMC> representing the data passed in this scheduler message.
82 VTABLE void init_pmc(PMC *data) {
84 Parrot_SchedulerMessage_attributes *core_struct;
86 if (! VTABLE_isa(INTERP, data, CONST_STRING(INTERP, "Hash")))
87 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
88 "message initializer must be a Hash");
91 core_struct = PARROT_SCHEDULERMESSAGE(SELF);
93 elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "id"));
94 if (! PMC_IS_NULL(elem))
95 core_struct->id = VTABLE_get_integer(INTERP, elem);
97 elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "type"));
98 if (! PMC_IS_NULL(elem))
99 core_struct->type = VTABLE_get_string(INTERP, elem);
101 elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "data"));
102 if (! PMC_IS_NULL(elem))
103 core_struct->data = elem;
108 =item C<INTVAL get_integer()>
110 Retrieve the message ID.
116 VTABLE INTVAL get_integer() {
117 const Parrot_SchedulerMessage_attributes * const
118 core_struct = PARROT_SCHEDULERMESSAGE(SELF);
121 return core_struct->id;
126 =item C<void set_integer_native(INTVAL value)>
134 VTABLE void set_integer_native(INTVAL value) {
135 Parrot_SchedulerMessage_attributes * const core_struct = PARROT_SCHEDULERMESSAGE(SELF);
137 core_struct->id = value;
143 =item C<STRING * get_string()>
145 Retrieve the message type.
151 STRING * get_string() {
152 const Parrot_SchedulerMessage_attributes * const core_struct =
153 PARROT_SCHEDULERMESSAGE(SELF);
155 return core_struct->type;
160 =item C<void set_string_native(STRING *value)>
162 Set the message type.
168 VTABLE void set_string_native(STRING *value) {
169 Parrot_SchedulerMessage_attributes * const core_struct = PARROT_SCHEDULERMESSAGE(SELF);
171 core_struct->type = value;
177 =item C<PMC *share_ro()>
179 Set this PMC as shared.
185 VTABLE PMC *share_ro() {
187 Parrot_SchedulerMessage_attributes *shared_struct;
189 if (PObj_is_PMC_shared_TEST(SELF))
192 shared_self = pt_shared_fixup(INTERP, SELF);
193 shared_struct = PARROT_SCHEDULERMESSAGE(shared_self);
194 shared_struct->data = pt_shared_fixup(INTERP, shared_struct->data);
203 Mark any referenced strings and PMCs.
209 if (PARROT_SCHEDULERMESSAGE(SELF)) {
210 Parrot_SchedulerMessage_attributes * const core_struct =
211 PARROT_SCHEDULERMESSAGE(SELF);
213 Parrot_gc_mark_STRING_alive(INTERP, core_struct->type);
214 Parrot_gc_mark_PMC_alive(INTERP, core_struct->data);
220 =item C<void visit(PMC *info)>
222 This is used by freeze/thaw to visit the contents of the scheduler message.
224 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
230 VTABLE void visit(PMC *info) {
231 /* visit message data */
232 VISIT_PMC(INTERP, info, PARROT_SCHEDULERMESSAGE(SELF)->data);
237 =item C<void freeze(PMC *info)>
239 Used to archive the scheduler message.
245 VTABLE void freeze(PMC *info) {
246 Parrot_SchedulerMessage_attributes * const core_struct =
247 PARROT_SCHEDULERMESSAGE(SELF);
249 /* 1) freeze message id */
250 VTABLE_push_integer(INTERP, info, core_struct->id);
252 /* 2) freeze message type */
253 VTABLE_push_string(INTERP, info, core_struct->type);
258 =item C<void thaw(PMC *info)>
260 Used to unarchive the scheduler message.
266 VTABLE void thaw(PMC *info) {
267 /* 1. thaw message id */
268 const INTVAL id = VTABLE_shift_integer(INTERP, info);
270 /* 2. thaw message type */
271 STRING * const type = VTABLE_shift_string(INTERP, info);
273 /* Allocate the message's core data struct and set custom flags. */
276 /* Set the message's id to the frozen id */
277 PARROT_SCHEDULERMESSAGE(SELF)->id = id;
279 /* Set the message's type to the frozen type */
280 PARROT_SCHEDULERMESSAGE(SELF)->type = type;
291 F<docs/pdds/pdd25_concurrency.pod>.
299 * c-file-style: "parrot"
301 * vim: expandtab shiftwidth=4: