fix codetest failure - trailing whitespace
[parrot.git] / src / pmc / schedulermessage.pmc
blobb6b6c322ac29cb1bd05cf7b4aca2d1cb4042ee13
1 /*
2 Copyright (C) 2001-2009, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 src/pmc/schedulermessage.pmc - The concurrency scheduler
9 =head1 DESCRIPTION
11 Implements a message passed between concurrency schedulers.
13 =head2 Vtable Functions
15 =over 4
17 =cut
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. */
30 =item C<void init()>
32 Initialize a concurrency scheduler message object.
34 =cut
38     VTABLE void init() {
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. */
46         core_struct->id          = 0;
47         core_struct->type        = CONST_STRING(INTERP, "");
48         core_struct->data        = PMCNULL;
49     }
53 =item C<void init_pmc(PMC *data)>
55 Initializes a new SchedulerMessage with a C<Hash> PMC with any or all of the
56 keys:
58 =over 4
60 =item C<id>
62 An C<Integer> representing the unique identifier for this scheduler message.
64 =item C<type>
66 A C<String> representing the unique type for this scheduler message.
68 =item C<data>
70 An C<PMC> representing the data passed in this scheduler message.
72 =back
74 =cut
78     VTABLE void init_pmc(PMC *data) {
79         PMC                     *elem;
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");
86         SELF.init();
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;
100     }
104 =item C<INTVAL get_integer()>
106 Retrieve the message ID.
108 =cut
112     VTABLE INTVAL get_integer() {
113         Parrot_SchedulerMessage_attributes * core_struct = PARROT_SCHEDULERMESSAGE(SELF);
114         return core_struct->id;
115     }
119 =item C<void set_integer_native(INTVAL value)>
121 Set the message ID.
123 =cut
127     VTABLE void set_integer_native(INTVAL value) {
128         Parrot_SchedulerMessage_attributes * core_struct = PARROT_SCHEDULERMESSAGE(SELF);
129         core_struct->id = value;
130     }
135 =item C<STRING * get_string()>
137 Retrieve the message type.
139 =cut
143     STRING *  get_string() {
144         Parrot_SchedulerMessage_attributes * core_struct = PARROT_SCHEDULERMESSAGE(SELF);
145         return core_struct->type;
146     }
150 =item C<void set_string_native(STRING *value)>
152 Set the message type.
154 =cut
158     VTABLE void set_string_native(STRING *value) {
159         Parrot_SchedulerMessage_attributes * core_struct = PARROT_SCHEDULERMESSAGE(SELF);
160         core_struct->type = value;
161     }
166 =item C<PMC *share_ro()>
168 Set this PMC as shared.
170 =cut
174     VTABLE PMC *share_ro() {
175         PMC *shared_self;
176         Parrot_SchedulerMessage_attributes *shared_struct;
178         if (PObj_is_PMC_shared_TEST(SELF))
179             return 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);
185         return shared_self;
186     }
190 =item C<void mark()>
192 Mark any referenced strings and PMCs.
194 =cut
197     VTABLE void mark() {
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);
204         }
205     }
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>).
215 =cut
219     VTABLE void visit(PMC *info) {
220         /* visit message data */
221         VISIT_PMC(INTERP, info, PARROT_SCHEDULERMESSAGE(SELF)->data);
222     }
226 =item C<void freeze(PMC *info)>
228 Used to archive the scheduler message.
230 =cut
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);
243     }
247 =item C<void thaw(PMC *info)>
249 Used to unarchive the scheduler message.
251 =cut
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. */
263         SELF.init();
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;
270     }
276 =back
278 =head1 SEE ALSO
280 F<docs/pdds/pdd25_concurrency.pod>.
282 =cut
287  * Local variables:
288  *   c-file-style: "parrot"
289  * End:
290  * vim: expandtab shiftwidth=4:
291  */