Skip to content
This repository
Newer
Older
100644 562 lines (372 sloc) 14.481 kb
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
1 /*
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
2 Copyright (C) 2001-2008, The Perl Foundation.
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
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
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
13 =head2 Vtable Functions
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
14
15 =over 4
16
17 =cut
18
19 */
20
21 #include "parrot/parrot.h"
ec73fb31 »
2007-12-06 [concurrency] Divide scheduler headers into public and private (for c…
22 #include "parrot/scheduler_private.h"
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
23
24 pmclass Scheduler need_ext {
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
25
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
26 ATTR INTVAL id; /* The scheduler's ID. */
27 ATTR INTVAL max_tid; /* The highest assigned task ID. */
28 ATTR INTVAL pending; /* A count of pending tasks (cached for fast
29 lookup). */
30 ATTR PMC *task_list; /* The current list of tasks. */
31 ATTR PMC *task_index; /* An index into the current list of tasks,
32 ordered by priority. */
33 ATTR PMC *wait_index; /* An unordered index of inactive tasks. */
34 ATTR PMC *handlers; /* The list of currently active handlers. */
35 ATTR PMC *messages; /* A message queue used for communication
36 between schedulers. */
37 ATTR Parrot_mutex msg_lock; /* Lock to synchronize the message queue. */
38 ATTR Parrot_Interp interp; /* A link to the scheduler's interpreter. */
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
39
40 /*
41
42 =item C<void init()>
43
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
44 Initializes a concurrency scheduler object.
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
45
46 =cut
47
48 */
49
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
50 VTABLE void init() {
51 Parrot_Scheduler * const core_struct =
52 mem_allocate_zeroed_typed(Parrot_Scheduler);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
53
54 /* Set flags for custom DOD mark and destroy. */
55 PObj_custom_mark_SET(SELF);
56 PObj_active_destroy_SET(SELF);
57
58 /* Set up the core struct. */
59 PMC_data(SELF) = core_struct;
60 core_struct->id = 0;
61 core_struct->max_tid = 0;
62 core_struct->task_list = pmc_new(interp, enum_class_Hash);
245b0a8f »
2007-12-06 [concurrency] Change an array of task IDs to an integer array rather …
63 core_struct->task_index = pmc_new(interp, enum_class_ResizableIntegerArray);
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
64 core_struct->wait_index = pmc_new(interp, enum_class_ResizablePMCArray);
4d9c9604 »
2008-01-05 [concurrency] Next stage of concurrency implementation, message passi…
65 core_struct->handlers = pmc_new(interp, enum_class_ResizablePMCArray);
66 core_struct->messages = pmc_new(interp, enum_class_ResizablePMCArray);
2f43c232 »
2007-12-02 [concurrency] Initialize interp struct member in Scheduler. Add a way to
67 core_struct->interp = INTERP;
4d9c9604 »
2008-01-05 [concurrency] Next stage of concurrency implementation, message passi…
68 MUTEX_INIT(core_struct->msg_lock);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
69 }
70
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
71
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
72 /*
73
96858eea »
2007-12-03 [PMC] Added init_pmc() to Scheduler PMC, with tests.
74 =item C<void init_pmc(PMC *data)>
75
76 Initializes a new Scheduler with a C<Hash> PMC with any or all of the keys:
77
78 =over 4
79
80 =item C<id>
81
82 An C<Integer> representing the unique identifier for this scheduler.
83
84 =back
85
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
86 =cut
87
96858eea »
2007-12-03 [PMC] Added init_pmc() to Scheduler PMC, with tests.
88 */
89
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
90 VTABLE void init_pmc(PMC *data) {
96858eea »
2007-12-03 [PMC] Added init_pmc() to Scheduler PMC, with tests.
91 PMC *elem;
92 Parrot_Scheduler *core_struct;
93
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
94 if (!VTABLE_isa(INTERP, data, CONST_STRING(INTERP, "Hash")))
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
95 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
4d9c9604 »
2008-01-05 [concurrency] Next stage of concurrency implementation, message passi…
96 "Scheduler initializer must be a Hash");
96858eea »
2007-12-03 [PMC] Added init_pmc() to Scheduler PMC, with tests.
97
4d9c9604 »
2008-01-05 [concurrency] Next stage of concurrency implementation, message passi…
98 SELF.init();
96858eea »
2007-12-03 [PMC] Added init_pmc() to Scheduler PMC, with tests.
99
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
100 core_struct = PARROT_SCHEDULER(SELF);
101 elem = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "id"));
96858eea »
2007-12-03 [PMC] Added init_pmc() to Scheduler PMC, with tests.
102
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
103 if (!PMC_IS_NULL(elem))
104 core_struct->id = VTABLE_get_integer(INTERP, elem);
96858eea »
2007-12-03 [PMC] Added init_pmc() to Scheduler PMC, with tests.
105 }
106
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
107
96858eea »
2007-12-03 [PMC] Added init_pmc() to Scheduler PMC, with tests.
108 /*
109
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
110 =item C<void push_pmc(PMC *value)>
111
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
112 Inserts a task into the task list, giving it a task ID one higher than the
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
113 current maximum, and a birthtime of the current time.
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
114
115 =cut
116
117 */
118
e9221160 »
2007-12-04 [concurrency] Initial implementation of concurrency scheduler runloop.
119 void push_pmc(PMC *task) {
728a8769 »
2007-11-28 consting, and removed two unused vars
120 Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
121 STRING *task_id_str;
122 INTVAL new_tid;
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
123
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
124 task = VTABLE_share_ro(INTERP, task);
125 VTABLE_set_number_native(INTERP, task, Parrot_floatval_time());
d0fb13e6 »
2007-12-06 [concurrency] Tasks are marked as shared before being inserted into t…
126
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
127 new_tid = ++(core_struct->max_tid);
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
128 VTABLE_set_integer_native(INTERP, task, new_tid);
129 task_id_str = string_from_int(INTERP, new_tid);
245b0a8f »
2007-12-06 [concurrency] Change an array of task IDs to an integer array rather …
130
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
131 VTABLE_set_pmc_keyed_str(INTERP, core_struct->task_list,
132 task_id_str, task);
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
133
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
134 if (task->vtable->base_type == enum_class_Timer)
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
135 VTABLE_push_integer(INTERP, core_struct->wait_index, new_tid);
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
136 else
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
137 VTABLE_push_integer(INTERP, core_struct->task_index, new_tid);
138
139 SCHEDULER_cache_valid_CLEAR(SELF);
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
140
141 if (task->vtable->base_type != enum_class_Exception)
142 Parrot_cx_runloop_wake(core_struct->interp, SELF);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
143 }
144
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
145
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
146 /*
147
148 =item C<PMC *pop_pmc()>
149
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
150 Retrieves the next task from the task list. If the task index is invalid,
151 recalculates it before retrieving the next task.
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
152
153 =cut
154
155 */
156
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
157 VTABLE PMC *pop_pmc() {
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
158 Parrot_Scheduler * core_struct = PARROT_SCHEDULER(SELF);
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
159 PMC *task = PMCNULL;
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
160
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
161 /* Pull the next valid task off the task list, skipping expired and
162 * deleted tasks. */
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
163 while (PMC_IS_NULL(task)
164 && VTABLE_elements(INTERP, core_struct->task_index) > 0) {
d0fb13e6 »
2007-12-06 [concurrency] Tasks are marked as shared before being inserted into t…
165 INTVAL tid = VTABLE_shift_integer(INTERP, core_struct->task_index);
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
166
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
167 if (tid > 0)
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
168 task = VTABLE_get_pmc_keyed_int(INTERP,
169 core_struct->task_list, tid);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
170 }
171
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
172 return task;
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
173 }
174
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
175
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
176 /*
177
2f43c232 »
2007-12-02 [concurrency] Initialize interp struct member in Scheduler. Add a way to
178 =item C<INTVAL get_integer()>
179
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
180 Retrieves the number of pending tasks in the scheduler's task list.
2f43c232 »
2007-12-02 [concurrency] Initialize interp struct member in Scheduler. Add a way to
181
182 =cut
183
184 */
185
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
186 VTABLE INTVAL get_integer() {
2f43c232 »
2007-12-02 [concurrency] Initialize interp struct member in Scheduler. Add a way to
187 Parrot_Scheduler * core_struct = PARROT_SCHEDULER(SELF);
188 return VTABLE_elements(INTERP, core_struct->task_index);
189 }
190
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
191
2f43c232 »
2007-12-02 [concurrency] Initialize interp struct member in Scheduler. Add a way to
192 /*
193
194 =item C<void delete_keyed_int(INTVAL key)>
195
196 Removes the task with the given task ID from the task list.
197
198 =cut
199
200 */
201
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
202 VTABLE void delete_keyed_int(INTVAL key) {
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
203 Parrot_Scheduler *core_struct = PARROT_SCHEDULER(SELF);
204 STRING *task_id_str = string_from_int(INTERP, key);
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
205 VTABLE_delete_keyed_str(INTERP, core_struct->task_list, task_id_str);
2f43c232 »
2007-12-02 [concurrency] Initialize interp struct member in Scheduler. Add a way to
206 SCHEDULER_cache_valid_CLEAR(SELF);
207 }
208
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
209
2f43c232 »
2007-12-02 [concurrency] Initialize interp struct member in Scheduler. Add a way to
210 /*
211
e9221160 »
2007-12-04 [concurrency] Initial implementation of concurrency scheduler runloop.
212 =item C<PMC *share_ro()>
213
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
214 Sets this PMC as shared.
e9221160 »
2007-12-04 [concurrency] Initial implementation of concurrency scheduler runloop.
215
216 =cut
217
218 */
219
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
220 VTABLE PMC *share_ro() {
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
221 PMC *shared_self;
222 Parrot_Scheduler *sched;
e9221160 »
2007-12-04 [concurrency] Initial implementation of concurrency scheduler runloop.
223
224 if (PObj_is_PMC_shared_TEST(SELF))
225 return SELF;
226
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
227 shared_self = pt_shared_fixup(INTERP, SELF);
228 sched = PARROT_SCHEDULER(shared_self);
e9221160 »
2007-12-04 [concurrency] Initial implementation of concurrency scheduler runloop.
229
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
230 sched->task_list = pt_shared_fixup(INTERP, sched->task_list);
231 sched->task_index = pt_shared_fixup(INTERP, sched->task_index);
232 sched->wait_index = pt_shared_fixup(INTERP, sched->wait_index);
233 sched->handlers = pt_shared_fixup(INTERP, sched->handlers);
234 sched->messages = pt_shared_fixup(INTERP, sched->messages);
e9221160 »
2007-12-04 [concurrency] Initial implementation of concurrency scheduler runloop.
235
236 return shared_self;
237 }
238
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
239
e9221160 »
2007-12-04 [concurrency] Initial implementation of concurrency scheduler runloop.
240 /*
241
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
242 =item C<void destroy()>
243
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
244 Frees the scheduler's underlying struct.
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
245
246 =cut
247
248 */
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
249 VTABLE void destroy() {
e9221160 »
2007-12-04 [concurrency] Initial implementation of concurrency scheduler runloop.
250 Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
4d9c9604 »
2008-01-05 [concurrency] Next stage of concurrency implementation, message passi…
251 MUTEX_DESTROY(core_struct->msg_lock);
a61e8b1f »
2008-01-03 [GC] During global destruction of the Parrot interpreter, mark the pa…
252 mem_sys_free(core_struct);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
253 }
254
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
255
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
256 /*
257
258 =item C<void mark()>
259
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
260 Marks any referenced strings and PMCs as live.
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
261
262 =cut
263
264 */
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
265 VTABLE void mark() {
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
266 if (PARROT_SCHEDULER(SELF)) {
267 Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
268
269 if (core_struct->task_list)
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
270 pobject_lives(interp, (PObj *)core_struct->task_list);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
271 if (core_struct->task_index)
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
272 pobject_lives(interp, (PObj *)core_struct->task_index);
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
273 if (core_struct->wait_index)
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
274 pobject_lives(interp, (PObj *)core_struct->wait_index);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
275 if (core_struct->handlers)
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
276 pobject_lives(interp, (PObj *)core_struct->handlers);
4d9c9604 »
2008-01-05 [concurrency] Next stage of concurrency implementation, message passi…
277 if (core_struct->messages)
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
278 pobject_lives(interp, (PObj *)core_struct->messages);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
279 }
280 }
281
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
282
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
283 /*
284
285 =item C<void visit(visit_info *info)>
286
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
287 Visits the contents of the scheduler (used by freeze/thaw).
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
288
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
289 C<*info> is the visit info (see F<include/parrot/pmc_freeze.h>).
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
290
291 =cut
292
293 */
294
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
295 VTABLE void visit(visit_info *info) {
728a8769 »
2007-11-28 consting, and removed two unused vars
296 Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
297 PMC **pos;
298
299 /* 1) visit task list */
300 pos = &core_struct->task_list;
301 info->thaw_ptr = pos;
302 (info->visit_pmc_now)(INTERP, *pos, info);
303
304 /* 2) visit the handlers */
305 pos = &core_struct->handlers;
306 info->thaw_ptr = pos;
307 (info->visit_pmc_now)(INTERP, *pos, info);
308 }
309
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
310
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
311 /*
312
313 =item C<void freeze(visit_info *info)>
314
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
315 Archives the scheduler.
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
316
317 =cut
318
319 */
320
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
321 VTABLE void freeze(visit_info *info) {
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
322 IMAGE_IO *io = info->image_io;
323 Parrot_Scheduler * const core_struct = PARROT_SCHEDULER(SELF);
324
325 /* 1) freeze scheduler id */
326 VTABLE_push_integer(INTERP, io, core_struct->id);
327
328 /* 2) freeze maximum task id */
329 VTABLE_push_integer(INTERP, io, core_struct->max_tid);
330 }
331
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
332
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
333 /*
334
335 =item C<void thaw(visit_info *info)>
336
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
337 Unarchives the scheduler.
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
338
339 =cut
340
341 */
342
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
343 VTABLE void thaw(visit_info *info) {
728a8769 »
2007-11-28 consting, and removed two unused vars
344 IMAGE_IO * const io = info->image_io;
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
345
346 /* 1. thaw scheduler id */
728a8769 »
2007-11-28 consting, and removed two unused vars
347 const INTVAL id = VTABLE_shift_integer(INTERP, io);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
348
349 /* 2. thaw maximum task id */
728a8769 »
2007-11-28 consting, and removed two unused vars
350 const INTVAL max_tid = VTABLE_shift_integer(INTERP, io);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
351
352 /* Allocate the scheduler's core data struct and set custom flags. */
353 SELF.init();
354
355 /* Set the scheduler's id to the frozen id */
356 PARROT_SCHEDULER(SELF)->id = id;
357
358 /* Set the scheduler's maximum task id to the frozen tid */
359 PARROT_SCHEDULER(SELF)->max_tid = max_tid;
360 }
361
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
362
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
363 /*
364
365 =item C<void thawfinish(visit_info *info)>
366
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
367 Finishes thawing the scheduler.
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
368
369 =cut
370
371 */
372
373 void thawfinish(visit_info *info) {
4d9c9604 »
2008-01-05 [concurrency] Next stage of concurrency implementation, message passi…
374 Parrot_cx_refresh_task_list(INTERP, SELF);
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
375 }
376
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
377
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
378 /*
379
380 =back
381
382 =head2 Methods
383
384 =over 4
385
386 =cut
387
388 */
389
390 /*
391
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
392 =item C<METHOD add_handler(PMC *handler)>
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
393
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
394 Adds a handler to the scheduler.
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
395
396 =cut
397
398 */
399
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
400 METHOD add_handler(PMC *handler) {
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
401 Parrot_Scheduler *core_struct = PARROT_SCHEDULER(SELF);
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
402 VTABLE_unshift_pmc(INTERP, core_struct->handlers, handler);
403 }
404
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
405
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
406 /*
407
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
408 =item C<METHOD delete_handler(STRING *type :optional, INTVAL have_type :opt_flag)>
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
409
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
410 Deletes a handler from the scheduler.
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
411
412 =cut
413
414 */
415
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
416 METHOD delete_handler(STRING *type :optional, INTVAL have_type :opt_flag) {
417 PMC *handlers;
418 INTVAL elements, index;
419 STRING *except_str = CONST_STRING(INTERP, "exception");
420 STRING *event_str = CONST_STRING(INTERP, "event");
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
421
422 GET_ATTR_handlers(INTERP, SELF, handlers);
423 elements = VTABLE_elements(INTERP, handlers);
424
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
425 if (!have_type)
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
426 VTABLE_shift_pmc(INTERP, handlers);
427
428 /* Loop from newest handler to oldest handler. */
429 for (index = 0; index < elements; ++index) {
430 PMC *handler = VTABLE_get_pmc_keyed_int(INTERP, handlers, index);
431 if (!PMC_IS_NULL(handler)) {
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
432 if (string_equal(INTERP, type, except_str) == 0
433 && handler->vtable->base_type == enum_class_ExceptionHandler) {
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
434 VTABLE_set_pmc_keyed_int(INTERP, handlers, index, PMCNULL);
435 RETURN(void);
436 }
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
437 else if (string_equal(INTERP, type, event_str) == 0
438 && handler->vtable->base_type == enum_class_EventHandler) {
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
439 VTABLE_set_pmc_keyed_int(INTERP, handlers, index, PMCNULL);
440 RETURN(void);
441 }
442 }
443 }
444
445 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
446 "No handler to delete.");
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
447 }
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
448
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
449
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
450 /*
451
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
452 =item C<METHOD find_handler(PMC *task)>
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
453
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
454 Searchs for a handler for the given task. If no handler is found, returns
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
455 PMCNULL.
456
457 =cut
458
459 */
460
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
461 METHOD find_handler(PMC *task) {
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
462 PMC *iter;
463
464 /* Exceptions store the handler iterator for rethrow, other kinds of
465 * tasks don't (though they could). */
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
466 if (task->vtable->base_type == enum_class_Exception
467 && VTABLE_get_integer_keyed_str(interp, task,
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
468 CONST_STRING(interp, "handled")) == -1) {
469 iter = VTABLE_get_attr_str(interp, task,
470 CONST_STRING(interp, "handler_iter"));
471 }
472 else {
473 PMC *handlers;
474 GET_ATTR_handlers(interp, SELF, handlers);
475 iter = VTABLE_get_iter(interp, handlers);
476
477 if (task->vtable->base_type == enum_class_Exception)
478 VTABLE_set_attr_str(interp, task,
479 CONST_STRING(interp, "handler_iter"), iter);
480 }
481
482 /* Loop from newest handler to oldest handler. */
483 while (VTABLE_get_bool(interp, iter)) {
484 PMC *handler = VTABLE_shift_pmc(INTERP, iter);
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
485
486 INTVAL valid_handler = 0;
487 if (!PMC_IS_NULL(handler)) {
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
488 (INTVAL valid_handler) = PCCINVOKE(INTERP, handler, "can_handle", PMC *task);
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
489 if (valid_handler) {
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
490 if (task->vtable->base_type == enum_class_Exception)
491 VTABLE_set_integer_native(interp, handler, 1);
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
492 RETURN(PMC *handler);
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
493 }
494 }
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
495
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
496 }
497
59661f18 »
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
498 RETURN(PMC *PMCNULL);
98ca8df8 »
2007-12-31 [concurrency] Further work on the new concurrency scheduler. (With ap…
499 }
500
d6808fe8 »
2007-12-12 [events] Add interface for event handling, add subtype attribute to t…
501
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
502 /*
503
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
504 =item C<METHOD count_handlers(STRING *type :optional, INTVAL have_type :opt_flag)>
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
505
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
506 Returns the number of handlers currently held by the scheduler. If a type
507 argument is passed, only counts handlers of that type (C<event>, C<exception>).
508 If no type argument is passed, counts all handlers.
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
509
510 =cut
511
512 */
513
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
514 METHOD count_handlers(STRING *type :optional, INTVAL have_type :opt_flag) {
515 /* avoid uninitialized value warning */
516 PMC *handlers = NULL;
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
517 INTVAL elements = VTABLE_elements(INTERP, handlers);
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
518 INTVAL count = 0;
519 INTVAL index;
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
520
521 GET_ATTR_handlers(INTERP, SELF, handlers);
522
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
523 if (!have_type)
524 RETURN(INTVAL elements);
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
525
526 for (index = 0; index < elements; ++index) {
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
527 PMC *handler = VTABLE_get_pmc_keyed_int(INTERP, handlers, index);
528 STRING *exception = CONST_STRING(INTERP, "exception");
529 STRING *event = CONST_STRING(INTERP, "event");
530
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
531 if (!PMC_IS_NULL(handler)) {
be7602b4 »
2008-08-09 [PMC] Fixed compiler warnings (use of uninitialized variables) and ti…
532 if (((string_equal(INTERP, type, exception) == 0)
533 && handler->vtable->base_type == enum_class_ExceptionHandler)
534 || ((string_equal(INTERP, type, event) == 0)
535 && handler->vtable->base_type == enum_class_EventHandler))
2255840f »
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
536 count++;
537 }
538 }
539
540 RETURN(INTVAL count);
541 }
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
542 }
543
544 /*
545
546 =back
547
548 =head1 SEE ALSO
549
4d9c9604 »
2008-01-05 [concurrency] Next stage of concurrency implementation, message passi…
550 F<docs/pdds/pdd25_concurrency.pod>.
1d259c67 »
2007-11-25 [concurrency] Initial implementations of the Scheduler and Task PMCs.
551
552 =cut
553
554 */
555
556 /*
557 * Local variables:
558 * c-file-style: "parrot"
559 * End:
560 * vim: expandtab shiftwidth=4:
561 */
Something went wrong with that request. Please try again.