fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / pmc / schedulermessage.pmc
blob3fc0c0b6e5b1ef40c531e74f0785375a340fe531
1 /*
2 Copyright (C) 2001-2010, 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 /* 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. */
34 =item C<void init()>
36 Initialize a concurrency scheduler message object.
38 =cut
42     VTABLE void init() {
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. */
50         core_struct->id          = 0;
51         core_struct->type        = CONST_STRING(INTERP, "");
52         core_struct->data        = PMCNULL;
53     }
57 =item C<void init_pmc(PMC *data)>
59 Initializes a new SchedulerMessage with a C<Hash> PMC with any or all of the
60 keys:
62 =over 4
64 =item C<id>
66 An C<Integer> representing the unique identifier for this scheduler message.
68 =item C<type>
70 A C<String> representing the unique type for this scheduler message.
72 =item C<data>
74 An C<PMC> representing the data passed in this scheduler message.
76 =back
78 =cut
82     VTABLE void init_pmc(PMC *data) {
83         PMC                     *elem;
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");
90         SELF.init();
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;
104     }
108 =item C<INTVAL get_integer()>
110 Retrieve the message ID.
112 =cut
116     VTABLE INTVAL get_integer() {
117         const Parrot_SchedulerMessage_attributes * const
118             core_struct = PARROT_SCHEDULERMESSAGE(SELF);
119         UNUSED(INTERP);
121         return core_struct->id;
122     }
126 =item C<void set_integer_native(INTVAL value)>
128 Set the message ID.
130 =cut
134     VTABLE void set_integer_native(INTVAL value) {
135         Parrot_SchedulerMessage_attributes * const core_struct = PARROT_SCHEDULERMESSAGE(SELF);
136         UNUSED(INTERP);
137         core_struct->id = value;
138     }
143 =item C<STRING * get_string()>
145 Retrieve the message type.
147 =cut
151     STRING *  get_string() {
152         const Parrot_SchedulerMessage_attributes * const core_struct =
153             PARROT_SCHEDULERMESSAGE(SELF);
154         UNUSED(INTERP);
155         return core_struct->type;
156     }
160 =item C<void set_string_native(STRING *value)>
162 Set the message type.
164 =cut
168     VTABLE void set_string_native(STRING *value) {
169         Parrot_SchedulerMessage_attributes * const core_struct = PARROT_SCHEDULERMESSAGE(SELF);
170         UNUSED(INTERP);
171         core_struct->type = value;
172     }
177 =item C<PMC *share_ro()>
179 Set this PMC as shared.
181 =cut
185     VTABLE PMC *share_ro() {
186         PMC *shared_self;
187         Parrot_SchedulerMessage_attributes *shared_struct;
189         if (PObj_is_PMC_shared_TEST(SELF))
190             return 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);
196         return shared_self;
197     }
201 =item C<void mark()>
203 Mark any referenced strings and PMCs.
205 =cut
208     VTABLE void mark() {
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);
215         }
216     }
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>).
226 =cut
230     VTABLE void visit(PMC *info) {
231         /* visit message data */
232         VISIT_PMC(INTERP, info, PARROT_SCHEDULERMESSAGE(SELF)->data);
233     }
237 =item C<void freeze(PMC *info)>
239 Used to archive the scheduler message.
241 =cut
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);
254     }
258 =item C<void thaw(PMC *info)>
260 Used to unarchive the scheduler message.
262 =cut
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. */
274         SELF.init();
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;
281     }
287 =back
289 =head1 SEE ALSO
291 F<docs/pdds/pdd25_concurrency.pod>.
293 =cut
298  * Local variables:
299  *   c-file-style: "parrot"
300  * End:
301  * vim: expandtab shiftwidth=4:
302  */