Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 248 lines (157 sloc) 5.11 kB
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
1 /*
2 Copyright (C) 2001-2007, The Perl Foundation.
3 $Id$
4
5 =head1 NAME
6
7 src/pmc/scheduler.pmc - The concurrency scheduler
8
9 =head1 DESCRIPTION
10
11 Implements the core concurrency scheduler.
12
13 =head2 Functions
14
15 =over 4
16
17 =cut
18
19 */
20
21 #include "parrot/parrot.h"
22
23 pmclass Scheduler need_ext {
24
25 /*
26
27 =item C<void init()>
28
29 Initialize a concurrency scheduler object.
30
31 =cut
32
33 */
34
35 void init() {
728a876 @petdance consting, and removed two unused vars
petdance authored
36 Parrot_Scheduler * const core_struct = mem_allocate_zeroed_typed(Parrot_Scheduler);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
37
38 /* Set flags for custom DOD mark and destroy. */
39 PObj_custom_mark_SET(SELF);
40 PObj_active_destroy_SET(SELF);
41
42 /* Set up the core struct. */
43 PMC_data(SELF) = core_struct;
44 core_struct->id = 0;
45 core_struct->max_tid = 0;
46 core_struct->task_list = pmc_new(interp, enum_class_Hash);
47 core_struct->task_index = pmc_new(interp, enum_class_ResizablePMCArray);
48 core_struct->handlers = pmc_new(interp, enum_class_ResizablePMCArray);
49
50 }
51
52 /*
53
54 =item C<void push_pmc(PMC *value)>
55
56 Insert a task into the task list, giving it a task ID one higher than the
57 current maximum.
58
59 =cut
60
61 */
62
63 void push_pmc(PMC *value) {
728a876 @petdance consting, and removed two unused vars
petdance authored
64 Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
65 PMC * const key = pmc_new(INTERP, enum_class_Integer);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
66
67 core_struct->max_tid++;
68 VTABLE_set_integer_native(INTERP, key, core_struct->max_tid);
69
70 VTABLE_set_pmc_keyed(INTERP, core_struct->task_list, key, value);
71 VTABLE_push_pmc(INTERP, core_struct->task_index, key);
72 }
73
74 /*
75
76 =item C<PMC *pop_pmc()>
77
78 Retrieve the next task from the task list. If the task index is invalid,
79 recalculate it before retrieving the next task.
80
81 =cut
82
83 */
84
85 PMC *pop_pmc() {
86 Parrot_Scheduler * core_struct = PARROT_SCHEDULER(SELF);
87
88 /* if (!SCHEDULER_cache_valid_TEST(SELF))
89 Parrot_task_recalculate_index(INTERP, SELF); */
90
91 if (VTABLE_elements(INTERP, core_struct->task_index) > 0) {
92 PMC *key = VTABLE_pop_pmc(INTERP, core_struct->task_index);
93 return VTABLE_get_pmc_keyed(INTERP, core_struct->task_list, key);
94 }
95 else
96 return PMCNULL;
97
98 }
99
100 /*
101
102 =item C<void destroy()>
103
104 Free the scheduler's underlying struct.
105
106 =cut
107
108 */
109 void destroy() {
110 mem_sys_free(PMC_data(SELF));
111 }
112
113 /*
114
115 =item C<void mark()>
116
117 Mark any referenced strings and PMCs.
118
119 =cut
120
121 */
122 void mark() {
123 if (PARROT_SCHEDULER(SELF)) {
124 Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
125
126 if (core_struct->task_list)
127 pobject_lives(interp, (PObj*)core_struct->task_list);
128 if (core_struct->task_index)
129 pobject_lives(interp, (PObj*)core_struct->task_index);
130 if (core_struct->handlers)
131 pobject_lives(interp, (PObj*)core_struct->handlers);
132 }
133 }
134
135 /*
136
137 =item C<void visit(visit_info *info)>
138
139 This is used by freeze/thaw to visit the contents of the scheduler.
140
141 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
142
143 =cut
144
145 */
146
147 void visit(visit_info *info) {
728a876 @petdance consting, and removed two unused vars
petdance authored
148 Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
149 PMC **pos;
150
151 /* 1) visit task list */
152 pos = &core_struct->task_list;
153 info->thaw_ptr = pos;
154 (info->visit_pmc_now)(INTERP, *pos, info);
155
156 /* 2) visit the handlers */
157 pos = &core_struct->handlers;
158 info->thaw_ptr = pos;
159 (info->visit_pmc_now)(INTERP, *pos, info);
160 }
161
162 /*
163
164 =item C<void freeze(visit_info *info)>
165
166 Used to archive the scheduler.
167
168 =cut
169
170 */
171
172 void freeze(visit_info *info) {
173 IMAGE_IO *io = info->image_io;
174 Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
175
176 /* 1) freeze scheduler id */
177 VTABLE_push_integer(INTERP, io, core_struct->id);
178
179 /* 2) freeze maximum task id */
180 VTABLE_push_integer(INTERP, io, core_struct->max_tid);
181 }
182
183 /*
184
185 =item C<void thaw(visit_info *info)>
186
187 Used to unarchive the scheduler.
188
189 =cut
190
191 */
192
193 void thaw(visit_info *info) {
728a876 @petdance consting, and removed two unused vars
petdance authored
194 IMAGE_IO * const io = info->image_io;
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
195
196 /* 1. thaw scheduler id */
728a876 @petdance consting, and removed two unused vars
petdance authored
197 const INTVAL id = VTABLE_shift_integer(INTERP, io);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
198
199 /* 2. thaw maximum task id */
728a876 @petdance consting, and removed two unused vars
petdance authored
200 const INTVAL max_tid = VTABLE_shift_integer(INTERP, io);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
201
202 /* Allocate the scheduler's core data struct and set custom flags. */
203 SELF.init();
204
205 /* Set the scheduler's id to the frozen id */
206 PARROT_SCHEDULER(SELF)->id = id;
207
208 /* Set the scheduler's maximum task id to the frozen tid */
209 PARROT_SCHEDULER(SELF)->max_tid = max_tid;
210 }
211
212 /*
213
214 =item C<void thawfinish(visit_info *info)>
215
216 Called after the scheduler has been thawed.
217
218 =cut
219
220 */
221
222 void thawfinish(visit_info *info) {
728a876 @petdance consting, and removed two unused vars
petdance authored
223 Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
224
225 /* TODO: Rebuild the task index. */
226 }
227
228 }
229
230 /*
231
232 =back
233
234 =head1 SEE ALSO
235
236 F<docs/pdds/pdd15_objects.pod>.
237
238 =cut
239
240 */
241
242 /*
243 * Local variables:
244 * c-file-style: "parrot"
245 * End:
246 * vim: expandtab shiftwidth=4:
247 */
Something went wrong with that request. Please try again.