Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 719 lines (515 sloc) 18.013 kb
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
1 /*
fb7055f @NotFound delete nonsensical wrong check in cx_delete_task
NotFound authored
2 Copyright (C) 2007-2011, Parrot Foundation.
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
3
4 =head1 NAME
5
6 src/scheduler.c - The core routines for the concurrency scheduler
7
8 =head1 DESCRIPTION
9
10 Each interpreter has a concurrency scheduler element in its core struct. The
3c1710d @Util Fix typos.
Util authored
11 scheduler is responsible for receiving, dispatching, and monitoring events,
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
12 exceptions, async I/O, and concurrent tasks (threads).
13
14 =cut
15
16 */
17
18 #include "parrot/parrot.h"
5b00192 @NotFound add extend.h in several places that needs it because of the swith to …
NotFound authored
19 #include "parrot/extend.h"
ec73fb3 @allisonrandal [concurrency] Divide scheduler headers into public and private (for c…
allisonrandal authored
20 #include "parrot/scheduler_private.h"
ca596cb @petdance consting
petdance authored
21 #include "parrot/runcore_api.h"
fb0dfd8 @NatTuck Progress on alarms / timers.
NatTuck authored
22 #include "parrot/alarm.h"
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
23 #include "parrot/scheduler.h"
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
24
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
25 #include "pmc/pmc_scheduler.h"
26 #include "pmc/pmc_task.h"
27 #include "pmc/pmc_timer.h"
fb0dfd8 @NatTuck Progress on alarms / timers.
NatTuck authored
28 #include "pmc/pmc_alarm.h"
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
29 #include "pmc/pmc_pmclist.h"
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
30 #include "pmc/pmc_continuation.h"
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
31
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to t…
allisonrandal authored
32 #include "scheduler.str"
33
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
34 /* HEADERIZER HFILE: include/parrot/scheduler.h */
35
36 /* HEADERIZER BEGIN: static */
75c52d8 @petdance Added a "DO NOT MODIFY HERE" message at the top & bottom of headerize…
petdance authored
37 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
38
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
39 static void Parrot_cx_disable_preemption(PARROT_INTERP)
40 __attribute__nonnull__(1);
41
42 static void Parrot_cx_enable_preemption(PARROT_INTERP)
43 __attribute__nonnull__(1);
44
45 #define ASSERT_ARGS_Parrot_cx_disable_preemption __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
46 PARROT_ASSERT_ARG(interp))
47 #define ASSERT_ARGS_Parrot_cx_enable_preemption __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
48 PARROT_ASSERT_ARG(interp))
75c52d8 @petdance Added a "DO NOT MODIFY HERE" message at the top & bottom of headerize…
petdance authored
49 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
50 /* HEADERIZER END: static */
51
52 /*
53
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
54 =head2 Scheduler Interface Functions
7bfdbaa @allisonrandal [scheduler] Sorting internal and interface functions for clearer docu…
allisonrandal authored
55
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passi…
allisonrandal authored
56 Functions to interface with the concurrency scheduler.
7bfdbaa @allisonrandal [scheduler] Sorting internal and interface functions for clearer docu…
allisonrandal authored
57
58 =over 4
59
660dd90 @Infinoid Revert r37846 for now, it undid all of Coke++'s hard work in r37845.
Infinoid authored
60 =item C<void Parrot_cx_init_scheduler(PARROT_INTERP)>
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
61
3c1710d @Util Fix typos.
Util authored
62 Initialize the concurrency scheduler for the interpreter.
a895b39 @paultcochrane [core] Replaced hard tabs with spaces and removed trailing whitespace
paultcochrane authored
63
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
64 =cut
a895b39 @paultcochrane [core] Replaced hard tabs with spaces and removed trailing whitespace
paultcochrane authored
65
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
66 */
67
68 void
69 Parrot_cx_init_scheduler(PARROT_INTERP)
70 {
00f1c24 @Infinoid [cage] Attempt to work around MSVC warnings related to ASSERT_ARGS().
Infinoid authored
71 ASSERT_ARGS(Parrot_cx_init_scheduler)
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
72 interp->quantum_done = Parrot_floatval_time() + PARROT_TASK_SWITCH_QUANTUM;
73
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
74 if (!interp->parent_interpreter) {
5ad98b9 @Whiteknight Remove many references to thread-related functions. Remove share and …
Whiteknight authored
75 interp->scheduler = Parrot_pmc_new(interp, enum_class_Scheduler);
1aa959b @NatTuck [gsoc_threads] Just need a couple less explosions...
NatTuck authored
76
77 /* Make sure the program can handle alarm signals */
78 Parrot_alarm_init();
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
79 }
80 }
81
82 /*
83
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
84 =item C<void Parrot_cx_begin_execution(PARROT_INTERP, PMC *main, PMC *argv)>
c901f5c @allisonrandal [concurrency] A bit of cleanup, and checking a flag before processing…
allisonrandal authored
85
a32e48a @NatTuck [gsoc_threads] Everything is a task.
NatTuck authored
86 Construct the main task, add it to the task queue, and then execute tasks
87 until the task queue becomes empty.
c901f5c @allisonrandal [concurrency] A bit of cleanup, and checking a flag before processing…
allisonrandal authored
88
89 =cut
90
91 */
92
a32e48a @NatTuck [gsoc_threads] Everything is a task.
NatTuck authored
93 PARROT_EXPORT
c901f5c @allisonrandal [concurrency] A bit of cleanup, and checking a flag before processing…
allisonrandal authored
94 void
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
95 Parrot_cx_begin_execution(PARROT_INTERP, ARGIN(PMC *main), ARGIN(PMC *argv))
c901f5c @allisonrandal [concurrency] A bit of cleanup, and checking a flag before processing…
allisonrandal authored
96 {
a32e48a @NatTuck [gsoc_threads] Everything is a task.
NatTuck authored
97 ASSERT_ARGS(Parrot_cx_begin_execution)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
98 PMC * const scheduler = interp->scheduler;
99 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(scheduler);
100 PMC * const main_task = Parrot_pmc_new(interp, enum_class_Task);
101 Parrot_Task_attributes * const tdata = PARROT_TASK(main_task);
1d627eb @petdance removed unnecessary var initialization
petdance authored
102 INTVAL task_count;
29315c0 @NatTuck [gsoc_threads] Prep for working blocking I/O.
NatTuck authored
103
f35c165 @NatTuck [gsoc_threads] Clean up task vs. event; make timers not be tasks.
NatTuck authored
104 tdata->code = main;
105 tdata->data = argv;
e212575 @Whiteknight Make sure to GC mark interp->cur_task. Add GC write barriers in sched…
Whiteknight authored
106 PARROT_GC_WRITE_BARRIER(interp, main_task);
a32e48a @NatTuck [gsoc_threads] Everything is a task.
NatTuck authored
107
e6fa7fc @Whiteknight rename enable_event_checking -> Parrot_runcore_enable_event_checking,…
Whiteknight authored
108 sched->enable_scheduling = 1;
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
109
19bc1e1 @niner Fix preemption and hookup the scheduler to Parrot_pf_execute_bytecode…
niner authored
110 Parrot_cx_schedule_immediate(interp, main_task);
111 Parrot_cx_outer_runloop(interp);
29315c0 @NatTuck [gsoc_threads] Prep for working blocking I/O.
NatTuck authored
112
113 task_count = VTABLE_get_integer(interp, sched->all_tasks);
114 if (task_count > 0)
115 Parrot_warn(interp, PARROT_WARNINGS_ALL_FLAG,
116 "Exiting with %d active tasks.\n", task_count);
c901f5c @allisonrandal [concurrency] A bit of cleanup, and checking a flag before processing…
allisonrandal authored
117 }
118
119 /*
120
19bc1e1 @niner Fix preemption and hookup the scheduler to Parrot_pf_execute_bytecode…
niner authored
121 =item C<void Parrot_cx_outer_runloop(PARROT_INTERP)>
122
123 This is the core loop performed by each active OS thread. If it's the
124 thread that needs to be running, it invokes the Scheduler to pick a
125 task.
126
127 =cut
128
129 */
130
131 void
132 Parrot_cx_outer_runloop(PARROT_INTERP)
133 {
134 ASSERT_ARGS(Parrot_cx_outer_runloop)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
135 PMC * const scheduler = interp->scheduler;
136 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(scheduler);
137 INTVAL alarm_count;
39561be @niner Readd alarm handling to the outer runloop
niner authored
138
139 do {
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
140 while (VTABLE_get_integer(interp, sched->task_queue) > 0) {
39561be @niner Readd alarm handling to the outer runloop
niner authored
141 /* there can be no active runloops at this point, so it should be save
142 * to start counting at 0 again. This way the continuation in the next
143 * task will find a runloop with id 1 when encountering an exception */
144 interp->current_runloop_level = 0;
145 reset_runloop_id_counter(interp);
146
147 Parrot_cx_next_task(interp, scheduler);
148
884f918 @niner Fix C++ comment in src/scheduler.c
niner authored
149 /* add expired alarms to the task queue */
39561be @niner Readd alarm handling to the outer runloop
niner authored
150 Parrot_cx_check_alarms(interp, interp->scheduler);
151 }
152
153 alarm_count = VTABLE_get_integer(interp, sched->alarms);
154 if (alarm_count > 0) {
752ba61 @niner Add in missing pause() in outer runloop
niner authored
155 #ifdef _WIN32
156 /* TODO: Implement on Windows */
157 #else
158 /* Nothing to do except to wait for the next alarm to expire */
159 pause();
160 #endif
39561be @niner Readd alarm handling to the outer runloop
niner authored
161 Parrot_cx_check_alarms(interp, interp->scheduler);
162 }
163 } while (alarm_count);
19bc1e1 @niner Fix preemption and hookup the scheduler to Parrot_pf_execute_bytecode…
niner authored
164 }
165
166 /*
167
cbd81fd @niner Enable preemption only when more than one task is active.
niner authored
168 =item C<void Parrot_cx_set_scheduler_alarm(PARROT_INTERP)>
169
170 Set the task switch alarm for the scheduler.
171
172 */
173
174 void
175 Parrot_cx_set_scheduler_alarm(PARROT_INTERP)
176 {
177 ASSERT_ARGS(Parrot_cx_set_scheduler_alarm)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
178 const FLOATVAL time_now = Parrot_floatval_time();
cbd81fd @niner Enable preemption only when more than one task is active.
niner authored
179
180 interp->quantum_done = time_now + PARROT_TASK_SWITCH_QUANTUM;
181
182 Parrot_alarm_set(interp->quantum_done);
183 }
184
185 /*
186
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
187 =item C<void Parrot_cx_next_task(PARROT_INTERP, PMC *scheduler)>
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
188
dc68503 @NatTuck [gsoc_threads] Infrastructure for multiple (IO) threads per interp.
NatTuck authored
189 Run the task at the head of the task queue until it ends or is
190 pre-empted.
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
191
192 =cut
193
194 */
195
2bca579 @allisonrandal [concurrency] Implement 2 more pieces of PDD 25: each interpreter has…
allisonrandal authored
196 void
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
197 Parrot_cx_next_task(PARROT_INTERP, ARGIN(PMC *scheduler))
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
198 {
dc68503 @NatTuck [gsoc_threads] Infrastructure for multiple (IO) threads per interp.
NatTuck authored
199 ASSERT_ARGS(Parrot_cx_next_task)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
200 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(scheduler);
201 PMC * const task = VTABLE_shift_pmc(interp, sched->task_queue);
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
202
e212575 @Whiteknight Make sure to GC mark interp->cur_task. Add GC write barriers in sched…
Whiteknight authored
203 interp->cur_task = task;
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
204
19bc1e1 @niner Fix preemption and hookup the scheduler to Parrot_pf_execute_bytecode…
niner authored
205 if (!VTABLE_isa(interp, task, CONST_STRING(interp, "Task")))
206 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
207 "Found a non-Task in the task queue.\n");
752ba61 @niner Add in missing pause() in outer runloop
niner authored
208
f747ea1 @Whiteknight Remove the preemptive thread scheduling logic from the windows build.…
Whiteknight authored
209 #ifdef _WIN32
210 /* TODO: Implement on Windows */
211 #else
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
212 if (VTABLE_get_integer(interp, sched->task_queue) > 0)
213 Parrot_cx_enable_preemption(interp);
cbd81fd @niner Enable preemption only when more than one task is active.
niner authored
214 else
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
215 Parrot_cx_disable_preemption(interp);
f747ea1 @Whiteknight Remove the preemptive thread scheduling logic from the windows build.…
Whiteknight authored
216 #endif
6ee1cd8 @nwellnhof Avoid recursive calls of Parrot_cx_handle_tasks
nwellnhof authored
217
19bc1e1 @niner Fix preemption and hookup the scheduler to Parrot_pf_execute_bytecode…
niner authored
218 Parrot_ext_call(interp, task, "->");
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
219 }
220
221 /*
222
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
223 =item C<opcode_t* Parrot_cx_check_scheduler(PARROT_INTERP, opcode_t *next)>
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
224
d39dc00 @NatTuck [gsoc_threads] Naming consistency.
NatTuck authored
225 Does the scheduler need to wake up and do anything? If so, do that now.
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
226
227 =cut
228
229 */
230
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
231 PARROT_CANNOT_RETURN_NULL
232 opcode_t*
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
233 Parrot_cx_check_scheduler(PARROT_INTERP, ARGIN(opcode_t *next))
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
234 {
d39dc00 @NatTuck [gsoc_threads] Naming consistency.
NatTuck authored
235 ASSERT_ARGS(Parrot_cx_check_scheduler)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
236 PMC * const scheduler = interp->scheduler;
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
237
1aa959b @NatTuck [gsoc_threads] Just need a couple less explosions...
NatTuck authored
238 if (Parrot_alarm_check(&(interp->last_alarm))
239 || SCHEDULER_wake_requested_TEST(scheduler)) {
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
240 SCHEDULER_wake_requested_CLEAR(scheduler);
d39dc00 @NatTuck [gsoc_threads] Naming consistency.
NatTuck authored
241 return Parrot_cx_run_scheduler(interp, scheduler, next);
fb0dfd8 @NatTuck Progress on alarms / timers.
NatTuck authored
242 }
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
243
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
244 return next;
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
245 }
246
247 /*
248
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
249 =item C<opcode_t* Parrot_cx_run_scheduler(PARROT_INTERP, PMC *scheduler,
250 opcode_t *next)>
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
251
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
252 Checks to see if any tasks need to be scheduled or if the current task
253 needs to be pre-empted.
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
254
255 =cut
256
257 */
258
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
259 PARROT_CANNOT_RETURN_NULL
42d0af3 @particle #60624: [DEPRECATED] PARROT_API changes to PARROT_EXPORT
particle authored
260 PARROT_EXPORT
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
261 opcode_t*
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
262 Parrot_cx_run_scheduler(PARROT_INTERP, ARGIN(PMC *scheduler), ARGIN(opcode_t *next))
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
263 {
d39dc00 @NatTuck [gsoc_threads] Naming consistency.
NatTuck authored
264 ASSERT_ARGS(Parrot_cx_run_scheduler)
ffed5f6 @petdance const a var and fix a splint annotation
petdance authored
265 const Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(interp->scheduler);
fb0dfd8 @NatTuck Progress on alarms / timers.
NatTuck authored
266
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
267 Parrot_cx_check_alarms(interp, scheduler);
268 Parrot_cx_check_quantum(interp, scheduler);
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
269
da1be12 @mikehh fix codetest failure - there should be at least one space between a C…
mikehh authored
270 if (SCHEDULER_resched_requested_TEST(scheduler)) {
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
271 SCHEDULER_resched_requested_CLEAR(scheduler);
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
272
1aa959b @NatTuck [gsoc_threads] Just need a couple less explosions...
NatTuck authored
273 /* A task switch will only work in the outer runloop of a fully
274 booted Parrot. In a Parrot that hasn't called begin_execution,
275 or in a nested runloop, we silently ignore task switches. */
e6fa7fc @Whiteknight rename enable_event_checking -> Parrot_runcore_enable_event_checking,…
Whiteknight authored
276 if (sched->enable_scheduling && interp->current_runloop_level <= 1)
d39dc00 @NatTuck [gsoc_threads] Naming consistency.
NatTuck authored
277 return Parrot_cx_preempt_task(interp, scheduler, next);
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
278 }
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
279
f747ea1 @Whiteknight Remove the preemptive thread scheduling logic from the windows build.…
Whiteknight authored
280 #ifdef _WIN32
281 /* TODO: Implement on Windows */
282 #else
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
283 /* Some alarm seems to have fired, but not the scheduler's.
284 * Re-set the scheduler alarm */
e6fa7fc @Whiteknight rename enable_event_checking -> Parrot_runcore_enable_event_checking,…
Whiteknight authored
285 if (sched->enable_preemption)
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
286 Parrot_alarm_set(interp->quantum_done);
f747ea1 @Whiteknight Remove the preemptive thread scheduling logic from the windows build.…
Whiteknight authored
287 #endif
b3b00c1 @niner Re-set alarm if it fired before quantum is done
niner authored
288
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
289 return next;
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
290 }
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
291
292 /*
293
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
294 =item C<void Parrot_cx_check_quantum(PARROT_INTERP, PMC *scheduler)>
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
295
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
296 If the quantum has expired, schedule the next task.
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
297
298 =cut
299
300 */
301
302 void
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
303 Parrot_cx_check_quantum(PARROT_INTERP, ARGIN(PMC *scheduler))
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
304 {
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
305 ASSERT_ARGS(Parrot_cx_check_quantum)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
306 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(scheduler);
307 const FLOATVAL time_now = Parrot_floatval_time();
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
308
e6fa7fc @Whiteknight rename enable_event_checking -> Parrot_runcore_enable_event_checking,…
Whiteknight authored
309 if (sched->enable_preemption && time_now >= interp->quantum_done)
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
310 SCHEDULER_resched_requested_SET(scheduler);
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
311 }
312
313 /*
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
314 =item C<PMC* Parrot_cx_stop_task(PARROT_INTERP, opcode_t *next)>
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
315
a97158c @NatTuck [gsoc_threads] First half of the Task API.
NatTuck authored
316 Stop the current task and pack it up into a PMC what can be used to resume later.
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
317
318 =cut
319 */
320
42d0af3 @particle #60624: [DEPRECATED] PARROT_API changes to PARROT_EXPORT
particle authored
321 PARROT_EXPORT
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
322 PARROT_CANNOT_RETURN_NULL
a97158c @NatTuck [gsoc_threads] First half of the Task API.
NatTuck authored
323 PMC*
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
324 Parrot_cx_stop_task(PARROT_INTERP, ARGIN(opcode_t *next))
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
325 {
a97158c @NatTuck [gsoc_threads] First half of the Task API.
NatTuck authored
326 ASSERT_ARGS(Parrot_cx_stop_task)
524fd09 @Whiteknight rename Parrot_task_current to Parrot_cx_current_task for pleasantness…
Whiteknight authored
327 PMC * const task = Parrot_cx_current_task(interp);
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
328 Parrot_Task_attributes * const tdata = PARROT_TASK(task);
329 PMC * const cont = Parrot_pmc_new(interp, enum_class_Continuation);
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
330
331 VTABLE_set_pointer(interp, cont, next);
332
286a4db @NatTuck [gsoc_threads] Can now kill blocked threads.
NatTuck authored
333 if (PMC_IS_NULL(task) || !VTABLE_isa(interp, task, CONST_STRING(interp, "Task")))
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
334 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
a97158c @NatTuck [gsoc_threads] First half of the Task API.
NatTuck authored
335 "Attempt to stop invalid interp->current_task.\n");
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
336
78cd6aa @NatTuck [gsoc_threads] Task queue only has tasks in it. Also, skip scheduler …
NatTuck authored
337 tdata->code = cont;
e212575 @Whiteknight Make sure to GC mark interp->cur_task. Add GC write barriers in sched…
Whiteknight authored
338 PARROT_GC_WRITE_BARRIER(interp, task);
a97158c @NatTuck [gsoc_threads] First half of the Task API.
NatTuck authored
339 TASK_in_preempt_SET(task);
340
341 return task;
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
342 }
343
344 /*
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
345 =item C<opcode_t* Parrot_cx_preempt_task(PARROT_INTERP, PMC *scheduler, opcode_t
346 *next)>
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
347
a97158c @NatTuck [gsoc_threads] First half of the Task API.
NatTuck authored
348 Pre-empt the current task. It goes on the foot of the task queue,
349 and then we jump all the way back to the task scheduling loop.
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
350
351 =cut
352 */
353
ffed5f6 @petdance const a var and fix a splint annotation
petdance authored
354 PARROT_CAN_RETURN_NULL
a97158c @NatTuck [gsoc_threads] First half of the Task API.
NatTuck authored
355 opcode_t*
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
356 Parrot_cx_preempt_task(PARROT_INTERP, ARGIN(PMC *scheduler), ARGIN(opcode_t *next))
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
357 {
a97158c @NatTuck [gsoc_threads] First half of the Task API.
NatTuck authored
358 ASSERT_ARGS(Parrot_cx_preempt_task)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
359 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(scheduler);
360 PMC * const task = Parrot_cx_stop_task(interp, next);
78cd6aa @NatTuck [gsoc_threads] Task queue only has tasks in it. Also, skip scheduler …
NatTuck authored
361 VTABLE_push_pmc(interp, sched->task_queue, task);
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
362
0935a0f @petdance use NULL for NULL, not a zero
petdance authored
363 return (opcode_t*)NULL;
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to t…
allisonrandal authored
364 }
365
366 /*
367
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
368 =item C<void Parrot_cx_runloop_wake(PARROT_INTERP, PMC *scheduler)>
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
369
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
370 Wake a sleeping scheduler runloop (generally called when new tasks are added to
371 the scheduler's task list).
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
372
373 =cut
374
375 */
376
377 void
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
378 Parrot_cx_runloop_wake(PARROT_INTERP, ARGIN(PMC *scheduler))
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
379 {
00f1c24 @Infinoid [cage] Attempt to work around MSVC warnings related to ASSERT_ARGS().
Infinoid authored
380 ASSERT_ARGS(Parrot_cx_runloop_wake)
e6fa7fc @Whiteknight rename enable_event_checking -> Parrot_runcore_enable_event_checking,…
Whiteknight authored
381 Parrot_runcore_enable_event_checking(interp);
c901f5c @allisonrandal [concurrency] A bit of cleanup, and checking a flag before processing…
allisonrandal authored
382 SCHEDULER_wake_requested_SET(scheduler);
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
383 }
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
384
385
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
386 /*
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
387
660dd90 @Infinoid Revert r37846 for now, it undid all of Coke++'s hard work in r37845.
Infinoid authored
388 =item C<void Parrot_cx_runloop_end(PARROT_INTERP)>
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
389
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
390 Schedule an event to terminate the scheduler runloop.
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
391
e922116 @allisonrandal [concurrency] Initial implementation of concurrency scheduler runloop.
allisonrandal authored
392 =cut
393
394 */
395
396 void
397 Parrot_cx_runloop_end(PARROT_INTERP)
398 {
00f1c24 @Infinoid [cage] Attempt to work around MSVC warnings related to ASSERT_ARGS().
Infinoid authored
399 ASSERT_ARGS(Parrot_cx_runloop_end)
2f3987e @Infinoid [headerizer] Use the new assert macros in a bunch of functions.
Infinoid authored
400 SCHEDULER_terminate_requested_SET(interp->scheduler);
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
401 /* Chandon TODO: Why is this here? */
402 /* Parrot_cx_handle_tasks(interp, interp->scheduler); */
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
403 }
404
405 /*
406
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
407 =item C<void Parrot_cx_schedule_task(PARROT_INTERP, PMC *task_or_sub)>
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
408
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
409 Add a task to to the task queue for execution.
410
da1be12 @mikehh fix codetest failure - there should be at least one space between a C…
mikehh authored
411 Probably cannot be called across interpreters/threads, must instead be
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
412 called from within the interpreter's runloop.
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
413
414 =cut
415
416 */
417
42d0af3 @particle #60624: [DEPRECATED] PARROT_API changes to PARROT_EXPORT
particle authored
418 PARROT_EXPORT
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
419 void
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
420 Parrot_cx_schedule_task(PARROT_INTERP, ARGIN(PMC *task_or_sub))
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
421 {
00f1c24 @Infinoid [cage] Attempt to work around MSVC warnings related to ASSERT_ARGS().
Infinoid authored
422 ASSERT_ARGS(Parrot_cx_schedule_task)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
423 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(interp->scheduler);
424 PMC * task = PMCNULL;
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
425
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
426 if (!interp->scheduler)
427 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
428 "Scheduler was not initialized for this interpreter.\n");
429
78cd6aa @NatTuck [gsoc_threads] Task queue only has tasks in it. Also, skip scheduler …
NatTuck authored
430 if (VTABLE_isa(interp, task_or_sub, CONST_STRING(interp, "Task"))) {
431 task = task_or_sub;
432 }
433 else if (VTABLE_isa(interp, task_or_sub, CONST_STRING(interp, "Sub"))) {
434 Parrot_Task_attributes *tdata;
435 task = Parrot_pmc_new(interp, enum_class_Task);
436 tdata = PARROT_TASK(task);
437 tdata->code = task_or_sub;
e212575 @Whiteknight Make sure to GC mark interp->cur_task. Add GC write barriers in sched…
Whiteknight authored
438 PARROT_GC_WRITE_BARRIER(interp, task);
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
439 }
78cd6aa @NatTuck [gsoc_threads] Task queue only has tasks in it. Also, skip scheduler …
NatTuck authored
440 else {
d39dc00 @NatTuck [gsoc_threads] Naming consistency.
NatTuck authored
441 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
78cd6aa @NatTuck [gsoc_threads] Task queue only has tasks in it. Also, skip scheduler …
NatTuck authored
442 "Can only schedule Tasks and Subs.\n");
443 }
d39dc00 @NatTuck [gsoc_threads] Naming consistency.
NatTuck authored
444
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
445 VTABLE_push_pmc(interp, sched->task_queue, task);
cbd81fd @niner Enable preemption only when more than one task is active.
niner authored
446
f747ea1 @Whiteknight Remove the preemptive thread scheduling logic from the windows build.…
Whiteknight authored
447 #ifdef _WIN32
448 /* TODO: Implement on Windows */
449 #else
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
450 /* going from single to multi tasking? */
cbd81fd @niner Enable preemption only when more than one task is active.
niner authored
451 if (VTABLE_get_integer(interp, sched->task_queue) == 1)
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
452 Parrot_cx_enable_preemption(interp);
f747ea1 @Whiteknight Remove the preemptive thread scheduling logic from the windows build.…
Whiteknight authored
453 #endif
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
454 }
455
456 /*
457
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
458 =item C<void Parrot_cx_schedule_immediate(PARROT_INTERP, PMC *task_or_sub)>
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
459
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
460 Add a task to the task queue for immediate execution.
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
461
462 =cut
463
464 */
465
42d0af3 @particle #60624: [DEPRECATED] PARROT_API changes to PARROT_EXPORT
particle authored
466 PARROT_EXPORT
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
467 void
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
468 Parrot_cx_schedule_immediate(PARROT_INTERP, ARGIN(PMC *task_or_sub))
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
469 {
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
470 ASSERT_ARGS(Parrot_cx_schedule_immediate)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
471 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(interp->scheduler);
78cd6aa @NatTuck [gsoc_threads] Task queue only has tasks in it. Also, skip scheduler …
NatTuck authored
472 PMC *task;
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
473
78cd6aa @NatTuck [gsoc_threads] Task queue only has tasks in it. Also, skip scheduler …
NatTuck authored
474 if (VTABLE_isa(interp, task_or_sub, CONST_STRING(interp, "Task"))) {
475 task = task_or_sub;
476 }
477 else if (VTABLE_isa(interp, task_or_sub, CONST_STRING(interp, "Sub"))) {
478 Parrot_Task_attributes *tdata;
479 task = Parrot_pmc_new(interp, enum_class_Task);
480 tdata = PARROT_TASK(task);
481 tdata->code = task_or_sub;
e212575 @Whiteknight Make sure to GC mark interp->cur_task. Add GC write barriers in sched…
Whiteknight authored
482 PARROT_GC_WRITE_BARRIER(interp, task);
78cd6aa @NatTuck [gsoc_threads] Task queue only has tasks in it. Also, skip scheduler …
NatTuck authored
483 }
484 else {
485 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
486 "Can only schedule Tasks and Subs.\n");
487 }
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
488
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
489 VTABLE_unshift_pmc(interp, sched->task_queue, task);
da1be12 @mikehh fix codetest failure - there should be at least one space between a C…
mikehh authored
490 SCHEDULER_wake_requested_SET(interp->scheduler);
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
491 SCHEDULER_resched_requested_SET(interp->scheduler);
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
492 }
493
494 /*
495
524fd09 @Whiteknight rename Parrot_task_current to Parrot_cx_current_task for pleasantness…
Whiteknight authored
496 =item C<PMC* Parrot_cx_current_task(PARROT_INTERP)>
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
497
286a4db @NatTuck [gsoc_threads] Can now kill blocked threads.
NatTuck authored
498 Returns the task that is currently running.
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
499
500 =cut
501
502 */
503
286a4db @NatTuck [gsoc_threads] Can now kill blocked threads.
NatTuck authored
504 PARROT_CANNOT_RETURN_NULL
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
505 PARROT_PURE_FUNCTION
286a4db @NatTuck [gsoc_threads] Can now kill blocked threads.
NatTuck authored
506 PMC*
524fd09 @Whiteknight rename Parrot_task_current to Parrot_cx_current_task for pleasantness…
Whiteknight authored
507 Parrot_cx_current_task(PARROT_INTERP)
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
508 {
524fd09 @Whiteknight rename Parrot_task_current to Parrot_cx_current_task for pleasantness…
Whiteknight authored
509 ASSERT_ARGS(Parrot_cx_current_task)
856f3b2 @niner Cleanup green_threads/kill_threads merge, builds now
niner authored
510 return interp->cur_task;
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
511 }
512
513 /*
514
515 =back
516
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passi…
allisonrandal authored
517 =head2 Scheduler Message Interface Functions
518
519 Functions that are used to interface with the message queue in the concurrency
520 scheduler.
521
522 =over 4
523
4dc854f @coke [cage] run 'make headerizer'
coke authored
524 =item C<void Parrot_cx_send_message(PARROT_INTERP, STRING *messagetype, PMC
525 *payload)>
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passi…
allisonrandal authored
526
527 Send a message to a scheduler in a different interpreter/thread.
528
529 =cut
530
531 */
532
42d0af3 @particle #60624: [DEPRECATED] PARROT_API changes to PARROT_EXPORT
particle authored
533 PARROT_EXPORT
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passi…
allisonrandal authored
534 void
0004e42 @petdance Make the headerizer not propagate SHIMness to function declarations. …
petdance authored
535 Parrot_cx_send_message(PARROT_INTERP, ARGIN(STRING *messagetype), ARGIN(SHIM(PMC *payload)))
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passi…
allisonrandal authored
536 {
00f1c24 @Infinoid [cage] Attempt to work around MSVC warnings related to ASSERT_ARGS().
Infinoid authored
537 ASSERT_ARGS(Parrot_cx_send_message)
09317ab @coke [codingstd]
coke authored
538 if (interp->scheduler) {
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
539 Parrot_Scheduler_attributes * const sched_struct =
540 PARROT_SCHEDULER(interp->scheduler);
541 PMC * const message = Parrot_pmc_new(interp, enum_class_SchedulerMessage);
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passi…
allisonrandal authored
542 VTABLE_set_string_native(interp, message, messagetype);
543
544 VTABLE_push_pmc(interp, sched_struct->messages, message);
545 Parrot_cx_runloop_wake(interp, interp->scheduler);
546 }
547 }
548
549 /*
550
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
551 =item C<void Parrot_cx_schedule_alarm(PARROT_INTERP, PMC *alarm)>
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to t…
allisonrandal authored
552
fb0dfd8 @NatTuck Progress on alarms / timers.
NatTuck authored
553 Schedule an alarm.
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to t…
allisonrandal authored
554
555 =cut
556
557 */
558
fb0dfd8 @NatTuck Progress on alarms / timers.
NatTuck authored
559 void
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
560 Parrot_cx_schedule_alarm(PARROT_INTERP, ARGIN(PMC *alarm))
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to t…
allisonrandal authored
561 {
fb0dfd8 @NatTuck Progress on alarms / timers.
NatTuck authored
562 ASSERT_ARGS(Parrot_cx_schedule_alarm)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
563 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(interp->scheduler);
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
564 FLOATVAL alarm_time = VTABLE_get_number(interp, alarm);
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
565
fb0dfd8 @NatTuck Progress on alarms / timers.
NatTuck authored
566 Parrot_alarm_set(alarm_time);
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
567
fb0dfd8 @NatTuck Progress on alarms / timers.
NatTuck authored
568 /* Insert new alarm at correct (ordered by time) position in array. */
569 Parrot_pmc_list_insert_by_number(interp, sched->alarms, alarm);
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to t…
allisonrandal authored
570 }
571
7bfdbaa @allisonrandal [scheduler] Sorting internal and interface functions for clearer docu…
allisonrandal authored
572 /*
573
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
574 =item C<void Parrot_cx_check_alarms(PARROT_INTERP, PMC *scheduler)>
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
575
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
576 Add the subs attached to any expired alarms to the task queue.
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
577
578 =cut
579
580 */
581
42d0af3 @particle #60624: [DEPRECATED] PARROT_API changes to PARROT_EXPORT
particle authored
582 PARROT_EXPORT
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
583 void
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
584 Parrot_cx_check_alarms(PARROT_INTERP, ARGIN(PMC *scheduler))
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
585 {
62b52c9 @NatTuck [gsoc_threads] Added callback PMC to handle NCI.
NatTuck authored
586 ASSERT_ARGS(Parrot_cx_check_alarms)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
587 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(scheduler);
588 INTVAL alarm_count = VTABLE_get_integer(interp, sched->alarms);
589 const FLOATVAL now_time = Parrot_floatval_time();
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
590
da1be12 @mikehh fix codetest failure - there should be at least one space between a C…
mikehh authored
591 while (alarm_count) {
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
592 PMC * const alarm = VTABLE_shift_pmc(interp, sched->alarms);
593 const FLOATVAL alarm_time = VTABLE_get_number(interp, alarm);
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
594
da1be12 @mikehh fix codetest failure - there should be at least one space between a C…
mikehh authored
595 if (alarm_time < now_time) {
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
596 Parrot_Alarm_attributes *data = PARROT_ALARM(alarm);
78cd6aa @NatTuck [gsoc_threads] Task queue only has tasks in it. Also, skip scheduler …
NatTuck authored
597 Parrot_cx_schedule_immediate(interp, data->alarm_task);
540d4c3 @bacek Merge context_pmc3 branch into trunk.
bacek authored
598 }
599 else {
49b30bb @NatTuck [gsoc_threads] Now with less segfaults.
NatTuck authored
600 Parrot_alarm_set(alarm_time);
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
601 VTABLE_unshift_pmc(interp, sched->alarms, alarm);
602 break;
540d4c3 @bacek Merge context_pmc3 branch into trunk.
bacek authored
603 }
fd65e37 @NotFound [core] less drastic way of handling recursive throwing
NotFound authored
604
9f3e20d @NatTuck [gsoc_threads] Alarms work, at least the easy way.
NatTuck authored
605 alarm_count--;
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
606 }
607 }
608
609 /*
610
611 =back
612
613 =head2 Opcode Functions
614
615 Functions that are called from within opcodes, that take and return an
616 opcode_t* to allow for changing the code flow.
617
618 =over 4
619
4dc854f @coke [cage] run 'make headerizer'
coke authored
620 =item C<opcode_t * Parrot_cx_schedule_sleep(PARROT_INTERP, FLOATVAL time,
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
621 opcode_t *next)>
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
622
623 Add a sleep timer to the scheduler. This function is called by the C<sleep>
624 opcode.
625
626 =cut
627
628 */
629
42d0af3 @particle #60624: [DEPRECATED] PARROT_API changes to PARROT_EXPORT
particle authored
630 PARROT_EXPORT
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
631 PARROT_WARN_UNUSED_RESULT
632 PARROT_CAN_RETURN_NULL
633 opcode_t *
06088a5 @petdance removed unnecessary const modifiers of function parameters. Removed a…
petdance authored
634 Parrot_cx_schedule_sleep(PARROT_INTERP, FLOATVAL time, ARGIN_NULLOK(opcode_t *next))
98ca8df @allisonrandal [concurrency] Further work on the new concurrency scheduler. (With ap…
allisonrandal authored
635 {
00f1c24 @Infinoid [cage] Attempt to work around MSVC warnings related to ASSERT_ARGS().
Infinoid authored
636 ASSERT_ARGS(Parrot_cx_schedule_sleep)
db1e323 @Whiteknight code cleanup in scheduler.c. Add const to give the optimizer a fighti…
Whiteknight authored
637 const FLOATVAL now_time = Parrot_floatval_time();
638 const FLOATVAL done_time = now_time + time;
639 PMC * const alarm = Parrot_pmc_new(interp, enum_class_Alarm);
640 Parrot_Alarm_attributes * const adata = PARROT_ALARM(alarm);
641 PMC * const task = Parrot_cx_stop_task(interp, next);
7bfdbaa @allisonrandal [scheduler] Sorting internal and interface functions for clearer docu…
allisonrandal authored
642
8e922a5 @NatTuck [gsoc_threads] Can both save *and* restore running tasks.
NatTuck authored
643 adata->alarm_time = done_time;
78cd6aa @NatTuck [gsoc_threads] Task queue only has tasks in it. Also, skip scheduler …
NatTuck authored
644 adata->alarm_task = task;
e212575 @Whiteknight Make sure to GC mark interp->cur_task. Add GC write barriers in sched…
Whiteknight authored
645 PARROT_GC_WRITE_BARRIER(interp, alarm);
25443f2 @petdance Use a proper NULL, not 0
petdance authored
646 (void) VTABLE_invoke(interp, alarm, NULL);
7bfdbaa @allisonrandal [scheduler] Sorting internal and interface functions for clearer docu…
allisonrandal authored
647
25443f2 @petdance Use a proper NULL, not 0
petdance authored
648 return (opcode_t*) NULL;
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passi…
allisonrandal authored
649 }
7bfdbaa @allisonrandal [scheduler] Sorting internal and interface functions for clearer docu…
allisonrandal authored
650
4d9c960 @allisonrandal [concurrency] Next stage of concurrency implementation, message passi…
allisonrandal authored
651 /*
652
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
653 =back
654
655 =head2 Internal functions
656
657 Functions that are used by the scheduler itself.
658
659 =over 4
660
661 =item C<static void Parrot_cx_enable_preemption(PARROT_INTERP)>
662
663 Enable preemption. Used when more than one task is runnable.
664
665 =cut
666
667 */
668
669 static void
670 Parrot_cx_enable_preemption(PARROT_INTERP)
671 {
672 ASSERT_ARGS(Parrot_cx_enable_preemption)
f747ea1 @Whiteknight Remove the preemptive thread scheduling logic from the windows build.…
Whiteknight authored
673 #ifdef _WIN32
674 /* TODO: Implement on Windows */
675 #else
e6fa7fc @Whiteknight rename enable_event_checking -> Parrot_runcore_enable_event_checking,…
Whiteknight authored
676 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(interp->scheduler);
677 sched->enable_preemption = 1;
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
678 Parrot_cx_set_scheduler_alarm(interp);
f747ea1 @Whiteknight Remove the preemptive thread scheduling logic from the windows build.…
Whiteknight authored
679 #endif
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
680 }
681
682 /*
683
684 =item C<static void Parrot_cx_disable_preemption(PARROT_INTERP)>
685
686 Disable preemption. Used when only one task is runnable.
687
688 =cut
689
690 */
691
692 static void
693 Parrot_cx_disable_preemption(PARROT_INTERP)
694 {
695 ASSERT_ARGS(Parrot_cx_disable_preemption)
e6fa7fc @Whiteknight rename enable_event_checking -> Parrot_runcore_enable_event_checking,…
Whiteknight authored
696 Parrot_Scheduler_attributes * const sched = PARROT_SCHEDULER(interp->scheduler);
697 sched->enable_preemption = 0;
f1329e5 @niner Reworked the zero overhead patch to reduce overhead
niner authored
698 }
699
700 /*
701
7bfdbaa @allisonrandal [scheduler] Sorting internal and interface functions for clearer docu…
allisonrandal authored
702 =back
703
4b296a2 @soh-cah-toa Fixed several perldoc rendering issues and added a few "SEE ALSO" sec…
soh-cah-toa authored
704 =head1 SEE ALSO
705
706 F<include/parrot/scheduler.h>
707
7bfdbaa @allisonrandal [scheduler] Sorting internal and interface functions for clearer docu…
allisonrandal authored
708 =cut
709
710 */
711
d6808fe @allisonrandal [events] Add interface for event handling, add subtype attribute to t…
allisonrandal authored
712
713 /*
ec73fb3 @allisonrandal [concurrency] Divide scheduler headers into public and private (for c…
allisonrandal authored
714 * Local variables:
715 * c-file-style: "parrot"
716 * End:
1d7dded @plobsing update C file vim modelines
plobsing authored
717 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
ec73fb3 @allisonrandal [concurrency] Divide scheduler headers into public and private (for c…
allisonrandal authored
718 */
Something went wrong with that request. Please try again.