Skip to content

Commit cc1b93e

Browse files
committed
auto merge of #11158 : alexcrichton/rust/green-bootstrap-task, r=pcwalton
Closes #11054
2 parents 00d87e0 + 3c4eb2b commit cc1b93e

File tree

2 files changed

+16
-34
lines changed

2 files changed

+16
-34
lines changed

src/libgreen/lib.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,7 @@ impl SchedPool {
214214
pool.handles.push(sched.make_handle());
215215
let sched = sched;
216216
pool.threads.push(do Thread::start {
217-
let mut sched = sched;
218-
let task = do GreenTask::new(&mut sched.stack_pool, None) {
219-
rtdebug!("boostraping a non-primary scheduler");
220-
};
221-
sched.bootstrap(task);
217+
sched.bootstrap();
222218
});
223219
}
224220

@@ -270,13 +266,7 @@ impl SchedPool {
270266
let ret = sched.make_handle();
271267
self.handles.push(sched.make_handle());
272268
let sched = sched;
273-
self.threads.push(do Thread::start {
274-
let mut sched = sched;
275-
let task = do GreenTask::new(&mut sched.stack_pool, None) {
276-
rtdebug!("boostraping a non-primary scheduler");
277-
};
278-
sched.bootstrap(task);
279-
});
269+
self.threads.push(do Thread::start { sched.bootstrap() });
280270

281271
return ret;
282272
}

src/libgreen/sched.rs

+14-22
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl Scheduler {
171171

172172
// Take a main task to run, and a scheduler to run it in. Create a
173173
// scheduler task and bootstrap into it.
174-
pub fn bootstrap(mut ~self, task: ~GreenTask) {
174+
pub fn bootstrap(mut ~self) {
175175

176176
// Build an Idle callback.
177177
let cb = ~SchedRunner as ~Callback;
@@ -187,18 +187,11 @@ impl Scheduler {
187187
self.idle_callback.get_mut_ref().resume();
188188

189189
// Now, as far as all the scheduler state is concerned, we are inside
190-
// the "scheduler" context. So we can act like the scheduler and resume
191-
// the provided task. Let it think that the currently running task is
192-
// actually the sched_task so it knows where to squirrel it away.
193-
let mut sched_task = self.resume_task_immediately(sched_task, task);
194-
195-
// Now we are back in the scheduler context, having
196-
// successfully run the input task. Start by running the
197-
// scheduler. Grab it out of TLS - performing the scheduler
198-
// action will have given it away.
199-
let sched = sched_task.sched.take_unwrap();
200-
rtdebug!("starting scheduler {}", sched.sched_id());
201-
let mut sched_task = sched.run(sched_task);
190+
// the "scheduler" context. The scheduler immediately hands over control
191+
// to the event loop, and this will only exit once the event loop no
192+
// longer has any references (handles or I/O objects).
193+
rtdebug!("starting scheduler {}", self.sched_id());
194+
let mut sched_task = self.run(sched_task);
202195

203196
// Close the idle callback.
204197
let mut sched = sched_task.sched.take_unwrap();
@@ -548,7 +541,10 @@ impl Scheduler {
548541
// We push the task onto our local queue clone.
549542
assert!(!task.is_sched());
550543
self.work_queue.push(task);
551-
self.idle_callback.get_mut_ref().resume();
544+
match self.idle_callback {
545+
Some(ref mut idle) => idle.resume(),
546+
None => {} // allow enqueuing before the scheduler starts
547+
}
552548

553549
// We've made work available. Notify a
554550
// sleeping scheduler.
@@ -1176,25 +1172,21 @@ mod test {
11761172
let mut sh = special_handle;
11771173
sh.send(Shutdown);
11781174
};
1179-
1175+
normal_sched.enqueue_task(normal_task);
11801176

11811177
let special_task = do GreenTask::new(&mut special_sched.stack_pool,
11821178
None) {
11831179
run(task1);
11841180
run(task3);
11851181
chan.send(());
11861182
};
1187-
1183+
special_sched.enqueue_task(special_task);
11881184

11891185
let normal_sched = normal_sched;
1190-
let normal_thread = do Thread::start {
1191-
normal_sched.bootstrap(normal_task);
1192-
};
1186+
let normal_thread = do Thread::start { normal_sched.bootstrap() };
11931187

11941188
let special_sched = special_sched;
1195-
let special_thread = do Thread::start {
1196-
special_sched.bootstrap(special_task);
1197-
};
1189+
let special_thread = do Thread::start { special_sched.bootstrap() };
11981190

11991191
normal_thread.join();
12001192
special_thread.join();

0 commit comments

Comments
 (0)