Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 547 lines (359 sloc) 14.191 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
6b81760 @Whiteknight [pmc] we don't need need_ext anymore, so BALEETED
Whiteknight authored
23 pmclass Scheduler auto_attrs {
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 =
5a7584e @NotFound merge auto_attrs branch into trunk
NotFound authored
51 (Parrot_Scheduler_attributes *) PMC_data(SELF);
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);
4591dbb @chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in r40...
chromatic authored
55 PObj_custom_destroy_SET(SELF);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
56
57 /* Set up the core struct. */
58 core_struct->id = 0;
59 core_struct->max_tid = 0;
60 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
61 core_struct->task_index = pmc_new(interp, enum_class_ResizableIntegerArray);
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
62 core_struct->wait_index = pmc_new(interp, enum_class_ResizablePMCArray);
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passing ...
allisonrandal authored
63 core_struct->handlers = pmc_new(interp, enum_class_ResizablePMCArray);
64 core_struct->messages = pmc_new(interp, enum_class_ResizablePMCArray);
2f43c23 @allisonrandal [concurrency] Initialize interp struct member in Scheduler. Add a way to
allisonrandal authored
65 core_struct->interp = INTERP;
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passing ...
allisonrandal authored
66 MUTEX_INIT(core_struct->msg_lock);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
67 }
68
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
69
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
70 /*
71
96858ee @chromatic [PMC] Added init_pmc() to Scheduler PMC, with tests.
chromatic authored
72 =item C<void init_pmc(PMC *data)>
73
74 Initializes a new Scheduler with a C<Hash> PMC with any or all of the keys:
75
76 =over 4
77
78 =item C<id>
79
80 An C<Integer> representing the unique identifier for this scheduler.
81
82 =back
83
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
84 =cut
85
96858ee @chromatic [PMC] Added init_pmc() to Scheduler PMC, with tests.
chromatic authored
86 */
87
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
88 VTABLE void init_pmc(PMC *data) {
96858ee @chromatic [PMC] Added init_pmc() to Scheduler PMC, with tests.
chromatic authored
89 PMC *elem;
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
90 Parrot_Scheduler_attributes *core_struct;
96858ee @chromatic [PMC] Added init_pmc() to Scheduler PMC, with tests.
chromatic authored
91
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
92 if (!VTABLE_isa(INTERP, data, CONST_STRING(INTERP, "Hash")))
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
93 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passing ...
allisonrandal authored
94 "Scheduler initializer must be a Hash");
96858ee @chromatic [PMC] Added init_pmc() to Scheduler PMC, with tests.
chromatic authored
95
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passing ...
allisonrandal authored
96 SELF.init();
96858ee @chromatic [PMC] Added init_pmc() to Scheduler PMC, with tests.
chromatic authored
97
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
98 core_struct = PARROT_SCHEDULER(SELF);
99 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
100
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
101 if (!PMC_IS_NULL(elem))
102 core_struct->id = VTABLE_get_integer(INTERP, elem);
96858ee @chromatic [PMC] Added init_pmc() to Scheduler PMC, with tests.
chromatic authored
103 }
104
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
105
96858ee @chromatic [PMC] Added init_pmc() to Scheduler PMC, with tests.
chromatic authored
106 /*
107
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
108 =item C<void push_pmc(PMC *value)>
109
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
110 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
111 current maximum, and a birthtime of the current time.
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
112
113 =cut
114
115 */
116
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
117 void push_pmc(PMC *task) {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
118 Parrot_Scheduler_attributes * const core_struct = PARROT_SCHEDULER(SELF);
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
119 STRING *task_id_str;
120 INTVAL new_tid;
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
121
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
122 task = VTABLE_share_ro(INTERP, task);
123 VTABLE_set_number_native(INTERP, task, Parrot_floatval_time());
d0fb13e @allisonrandal [concurrency] Tasks are marked as shared before being inserted into the ...
allisonrandal authored
124
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
125 new_tid = ++(core_struct->max_tid);
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
126 VTABLE_set_integer_native(INTERP, task, new_tid);
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
127 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
128
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
129 VTABLE_set_pmc_keyed_str(INTERP, core_struct->task_list,
130 task_id_str, task);
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
131
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
132 if (task->vtable->base_type == enum_class_Timer)
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
133 VTABLE_push_integer(INTERP, core_struct->wait_index, new_tid);
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
134 else
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
135 VTABLE_push_integer(INTERP, core_struct->task_index, new_tid);
136
137 SCHEDULER_cache_valid_CLEAR(SELF);
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
138
139 if (task->vtable->base_type != enum_class_Exception)
140 Parrot_cx_runloop_wake(core_struct->interp, SELF);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
141 }
142
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
143
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
144 /*
145
146 =item C<PMC *pop_pmc()>
147
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
148 Retrieves the next task from the task list. If the task index is invalid,
149 recalculates it before retrieving the next task.
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
150
151 =cut
152
153 */
154
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
155 VTABLE PMC *pop_pmc() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
156 Parrot_Scheduler_attributes * core_struct = PARROT_SCHEDULER(SELF);
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
157 PMC *task = PMCNULL;
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
158
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
159 /* Pull the next valid task off the task list, skipping expired and
160 * deleted tasks. */
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
161 while (PMC_IS_NULL(task)
162 && VTABLE_elements(INTERP, core_struct->task_index) > 0) {
d0fb13e @allisonrandal [concurrency] Tasks are marked as shared before being inserted into the ...
allisonrandal authored
163 INTVAL tid = VTABLE_shift_integer(INTERP, core_struct->task_index);
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
164
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
165 if (tid > 0)
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
166 task = VTABLE_get_pmc_keyed_int(INTERP,
167 core_struct->task_list, tid);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
168 }
169
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
170 return task;
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
171 }
172
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
173
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
174 /*
175
2f43c23 @allisonrandal [concurrency] Initialize interp struct member in Scheduler. Add a way to
allisonrandal authored
176 =item C<INTVAL get_integer()>
177
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
178 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
179
180 =cut
181
182 */
183
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
184 VTABLE INTVAL get_integer() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
185 Parrot_Scheduler_attributes * core_struct = PARROT_SCHEDULER(SELF);
2f43c23 @allisonrandal [concurrency] Initialize interp struct member in Scheduler. Add a way to
allisonrandal authored
186 return VTABLE_elements(INTERP, core_struct->task_index);
187 }
188
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
189
2f43c23 @allisonrandal [concurrency] Initialize interp struct member in Scheduler. Add a way to
allisonrandal authored
190 /*
191
192 =item C<void delete_keyed_int(INTVAL key)>
193
194 Removes the task with the given task ID from the task list.
195
196 =cut
197
198 */
199
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
200 VTABLE void delete_keyed_int(INTVAL key) {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
201 Parrot_Scheduler_attributes *core_struct = PARROT_SCHEDULER(SELF);
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
202 STRING *task_id_str = Parrot_str_from_int(INTERP, key);
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
203 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
204 SCHEDULER_cache_valid_CLEAR(SELF);
205 }
206
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
207
2f43c23 @allisonrandal [concurrency] Initialize interp struct member in Scheduler. Add a way to
allisonrandal authored
208 /*
209
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
210 =item C<PMC *share_ro()>
211
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
212 Sets this PMC as shared.
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
213
214 =cut
215
216 */
217
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
218 VTABLE PMC *share_ro() {
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
219 PMC *shared_self;
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
220 Parrot_Scheduler_attributes *sched;
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
221
222 if (PObj_is_PMC_shared_TEST(SELF))
223 return SELF;
224
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
225 shared_self = pt_shared_fixup(INTERP, SELF);
226 sched = PARROT_SCHEDULER(shared_self);
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
227
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
228 sched->task_list = pt_shared_fixup(INTERP, sched->task_list);
229 sched->task_index = pt_shared_fixup(INTERP, sched->task_index);
230 sched->wait_index = pt_shared_fixup(INTERP, sched->wait_index);
231 sched->handlers = pt_shared_fixup(INTERP, sched->handlers);
232 sched->messages = pt_shared_fixup(INTERP, sched->messages);
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
233
234 return shared_self;
235 }
236
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
237
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
238 /*
239
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
240 =item C<void destroy()>
241
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
242 Frees the scheduler's underlying struct.
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
243
244 =cut
245
246 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
247 VTABLE void destroy() {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
248 Parrot_Scheduler_attributes * const core_struct = PARROT_SCHEDULER(SELF);
540d4c3 @bacek Merge context_pmc3 branch into trunk.
bacek authored
249 /* TT #946: this line is causing an order-of-destruction error
250 because the scheduler is being freed before it's tasks.
251 Commenting this out till we get a real fix (although it's a hack) */
252 /* MUTEX_DESTROY(core_struct->msg_lock); */
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
253 }
254
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
255
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
256 /*
257
258 =item C<void mark()>
259
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
260 Marks any referenced strings and PMCs as live.
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
261
262 =cut
263
264 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
265 VTABLE void mark() {
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
266 if (PARROT_SCHEDULER(SELF)) {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
267 Parrot_Scheduler_attributes * const core_struct = PARROT_SCHEDULER(SELF);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
268
18dd147 @NotFound [gc] add new mark_... _alive functions, use it in a lot of mark vtable f...
NotFound authored
269 Parrot_gc_mark_PMC_alive(interp, core_struct->task_list);
270 Parrot_gc_mark_PMC_alive(interp, core_struct->task_index);
271 Parrot_gc_mark_PMC_alive(interp, core_struct->wait_index);
272 Parrot_gc_mark_PMC_alive(interp, core_struct->handlers);
273 Parrot_gc_mark_PMC_alive(interp, core_struct->messages);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
274 }
275 }
276
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
277
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
278 /*
279
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
280 =item C<void visit(PMC *info)>
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
281
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
282 Visits the contents of the scheduler (used by freeze/thaw).
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
283
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
284 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
285
286 =cut
287
288 */
289
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
290 VTABLE void visit(PMC *info) {
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
291 /* 1) visit task list */
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored
292 VISIT_PMC_ATTR(INTERP, info, SELF, Scheduler, task_list);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
293
294 /* 2) visit the handlers */
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored
295 VISIT_PMC_ATTR(INTERP, info, SELF, Scheduler, handlers);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
296 }
297
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
298
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
299 /*
300
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
301 =item C<void freeze(PMC *info)>
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
302
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
303 Archives the scheduler.
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
304
305 =cut
306
307 */
308
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
309 VTABLE void freeze(PMC *info) {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
310 Parrot_Scheduler_attributes * const core_struct = PARROT_SCHEDULER(SELF);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
311
312 /* 1) freeze scheduler id */
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored
313 VTABLE_push_integer(INTERP, info, core_struct->id);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
314
315 /* 2) freeze maximum task id */
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored
316 VTABLE_push_integer(INTERP, info, core_struct->max_tid);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
317 }
318
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
319
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
320 /*
321
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
322 =item C<void thaw(PMC *info)>
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
323
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
324 Unarchives the scheduler.
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
325
326 =cut
327
328 */
329
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
330 VTABLE void thaw(PMC *info) {
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
331 /* 1. thaw scheduler id */
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored
332 const INTVAL id = VTABLE_shift_integer(INTERP, info);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
333
334 /* 2. thaw maximum task id */
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored
335 const INTVAL max_tid = VTABLE_shift_integer(INTERP, info);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
336
337 /* Allocate the scheduler's core data struct and set custom flags. */
338 SELF.init();
339
340 /* Set the scheduler's id to the frozen id */
341 PARROT_SCHEDULER(SELF)->id = id;
342
343 /* Set the scheduler's maximum task id to the frozen tid */
344 PARROT_SCHEDULER(SELF)->max_tid = max_tid;
345 }
346
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
347
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
348 /*
349
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
350 =item C<void thawfinish(PMC *info)>
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
351
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
352 Finishes thawing the scheduler.
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
353
354 =cut
355
356 */
357
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
358 VTABLE void thawfinish(PMC *info) {
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passing ...
allisonrandal authored
359 Parrot_cx_refresh_task_list(INTERP, SELF);
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
360 }
361
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
362
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
363 /*
364
365 =back
366
367 =head2 Methods
368
369 =over 4
370
371 =cut
372
373 */
374
375 /*
376
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
377 =item C<METHOD add_handler(PMC *handler)>
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
378
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
379 Adds a handler to the scheduler.
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
380
381 =cut
382
383 */
384
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
385 METHOD add_handler(PMC *handler) {
971e997 @NotFound rename pmc attributes struct from Parrot_<type> to Parrot_<type>_attribu...
NotFound authored
386 Parrot_Scheduler_attributes *core_struct = PARROT_SCHEDULER(SELF);
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
387 VTABLE_unshift_pmc(INTERP, core_struct->handlers, handler);
388 }
389
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
390
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
391 /*
392
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
393 =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
394
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
395 Deletes a handler from the scheduler.
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
396
397 =cut
398
399 */
400
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
401 METHOD delete_handler(STRING *type :optional, INTVAL have_type :opt_flag) {
402 PMC *handlers;
403 INTVAL elements, index;
404 STRING *except_str = CONST_STRING(INTERP, "exception");
405 STRING *event_str = CONST_STRING(INTERP, "event");
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
406
407 GET_ATTR_handlers(INTERP, SELF, handlers);
408 elements = VTABLE_elements(INTERP, handlers);
409
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
410 if (!have_type)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
411 VTABLE_shift_pmc(INTERP, handlers);
412
413 /* Loop from newest handler to oldest handler. */
414 for (index = 0; index < elements; ++index) {
415 PMC *handler = VTABLE_get_pmc_keyed_int(INTERP, handlers, index);
416 if (!PMC_IS_NULL(handler)) {
4b380b1 @Util [cage] (TT #397) PDD07 enforcement for Parrot_str_not_equal(foo,bar)==0
Util authored
417 if (Parrot_str_equal(INTERP, type, except_str)
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
418 && handler->vtable->base_type == enum_class_ExceptionHandler) {
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
419 VTABLE_set_pmc_keyed_int(INTERP, handlers, index, PMCNULL);
420 RETURN(void);
421 }
4b380b1 @Util [cage] (TT #397) PDD07 enforcement for Parrot_str_not_equal(foo,bar)==0
Util authored
422 else if (Parrot_str_equal(INTERP, type, event_str)
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
423 && handler->vtable->base_type == enum_class_EventHandler) {
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
424 VTABLE_set_pmc_keyed_int(INTERP, handlers, index, PMCNULL);
425 RETURN(void);
426 }
427 }
428 }
429
430 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
431 "No handler to delete.");
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
432 }
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
433
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
434
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
435 /*
436
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
437 =item C<METHOD find_handler(PMC *task)>
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
438
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
439 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
440 PMCNULL.
441
442 =cut
443
444 */
445
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
446 METHOD find_handler(PMC *task) {
0006ce7 @chromatic [src] Fixed all CONST_STRING macros so that they don't break across line...
chromatic authored
447 STRING * const handled_str = CONST_STRING(interp, "handled");
448 STRING * const iter_str = CONST_STRING(interp, "handler_iter");
449 PMC *iter;
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
450
451 /* Exceptions store the handler iterator for rethrow, other kinds of
452 * tasks don't (though they could). */
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
453 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
454 && VTABLE_get_integer_keyed_str(interp, task, handled_str) == -1) {
455 iter = VTABLE_get_attr_str(interp, task, iter_str);
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
456 }
457 else {
458 PMC *handlers;
459 GET_ATTR_handlers(interp, SELF, handlers);
460 iter = VTABLE_get_iter(interp, handlers);
461
462 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
463 VTABLE_set_attr_str(interp, task, iter_str, iter);
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
464 }
465
466 /* Loop from newest handler to oldest handler. */
467 while (VTABLE_get_bool(interp, iter)) {
468 PMC *handler = VTABLE_shift_pmc(INTERP, iter);
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
469
470 INTVAL valid_handler = 0;
471 if (!PMC_IS_NULL(handler)) {
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
472 (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
473 if (valid_handler) {
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
474 if (task->vtable->base_type == enum_class_Exception)
475 VTABLE_set_integer_native(interp, handler, 1);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
476 RETURN(PMC *handler);
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
477 }
478 }
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
479
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
480 }
481
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
482 RETURN(PMC *PMCNULL);
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With apolo...
allisonrandal authored
483 }
484
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to task...
allisonrandal authored
485
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
486 /*
487
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
488 =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
489
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
490 Returns the number of handlers currently held by the scheduler. If a type
491 argument is passed, only counts handlers of that type (C<event>, C<exception>).
492 If no type argument is passed, counts all handlers.
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
493
494 =cut
495
496 */
497
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
498 METHOD count_handlers(STRING *type :optional, INTVAL have_type :opt_flag) {
499 /* avoid uninitialized value warning */
500 PMC *handlers = NULL;
9f26f43 @NotFound fix count_eh opcode and add test for it, TT #212 rg++
NotFound authored
501 INTVAL elements;
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
502 INTVAL count = 0;
503 INTVAL index;
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
504
505 GET_ATTR_handlers(INTERP, SELF, handlers);
9f26f43 @NotFound fix count_eh opcode and add test for it, TT #212 rg++
NotFound authored
506 elements = VTABLE_elements(INTERP, handlers);
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
507
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
508 if (!have_type)
509 RETURN(INTVAL elements);
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
510
511 for (index = 0; index < elements; ++index) {
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
512 PMC *handler = VTABLE_get_pmc_keyed_int(INTERP, handlers, index);
513 STRING *exception = CONST_STRING(INTERP, "exception");
514 STRING *event = CONST_STRING(INTERP, "event");
515
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
516 if (!PMC_IS_NULL(handler)) {
4b380b1 @Util [cage] (TT #397) PDD07 enforcement for Parrot_str_not_equal(foo,bar)==0
Util authored
517 if ((Parrot_str_equal(INTERP, type, exception)
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
518 && handler->vtable->base_type == enum_class_ExceptionHandler)
4b380b1 @Util [cage] (TT #397) PDD07 enforcement for Parrot_str_not_equal(foo,bar)==0
Util authored
519 || (Parrot_str_equal(INTERP, type, event)
be7602b @chromatic [PMC] Fixed compiler warnings (use of uninitialized variables) and tided...
chromatic authored
520 && handler->vtable->base_type == enum_class_EventHandler))
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
521 count++;
522 }
523 }
524
525 RETURN(INTVAL count);
526 }
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
527 }
528
529 /*
530
531 =back
532
533 =head1 SEE ALSO
534
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passing ...
allisonrandal authored
535 F<docs/pdds/pdd25_concurrency.pod>.
1d259c6 @allisonrandal [concurrency] Initial implementations of the Scheduler and Task PMCs.
allisonrandal authored
536
537 =cut
538
539 */
540
541 /*
542 * Local variables:
543 * c-file-style: "parrot"
544 * End:
545 * vim: expandtab shiftwidth=4:
546 */
Something went wrong with that request. Please try again.