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