Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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