Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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