Skip to content

Commit 66534ff

Browse files
committed
---
yaml --- r: 88851 b: refs/heads/snap-stage3 c: 1a6d920 h: refs/heads/master i: 88849: 41dde35 88847: 2f0ee9f v: v3
1 parent dc7a38b commit 66534ff

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: deeca5d586bfaa4aa60246f671a8d611d38f6248
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 8be66e212b37045b927138965a76abe3608325ca
4+
refs/heads/snap-stage3: 1a6d920e3df3d48168b22879a194538ec10c951a
55
refs/heads/try: b160761e35efcd1207112b3b782c06633cf441a8
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libgreen/lib.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ pub fn run(main: proc()) -> int {
115115
pub struct PoolConfig {
116116
/// The number of schedulers (OS threads) to spawn into this M:N pool.
117117
threads: uint,
118+
/// A factory function used to create new event loops. If this is not
119+
/// specified then the default event loop factory is used.
120+
event_loop_factory: Option<fn() -> ~rtio::EventLoop>,
118121
}
119122

120123
impl PoolConfig {
@@ -123,6 +126,7 @@ impl PoolConfig {
123126
pub fn new() -> PoolConfig {
124127
PoolConfig {
125128
threads: rt::default_sched_threads(),
129+
event_loop_factory: None,
126130
}
127131
}
128132
}
@@ -138,6 +142,7 @@ pub struct SchedPool {
138142
priv stack_pool: StackPool,
139143
priv deque_pool: deque::BufferPool<~task::GreenTask>,
140144
priv sleepers: SleeperList,
145+
priv factory: fn() -> ~rtio::EventLoop,
141146
}
142147

143148
impl SchedPool {
@@ -148,7 +153,11 @@ impl SchedPool {
148153
pub fn new(config: PoolConfig) -> SchedPool {
149154
static mut POOL_ID: AtomicUint = INIT_ATOMIC_UINT;
150155

151-
let PoolConfig { threads: nscheds } = config;
156+
let PoolConfig {
157+
threads: nscheds,
158+
event_loop_factory: factory
159+
} = config;
160+
let factory = factory.unwrap_or(default_event_loop_factory());
152161
assert!(nscheds > 0);
153162

154163
// The pool of schedulers that will be returned from this function
@@ -161,6 +170,7 @@ impl SchedPool {
161170
stack_pool: StackPool::new(),
162171
deque_pool: deque::BufferPool::new(),
163172
next_friend: 0,
173+
factory: factory,
164174
};
165175

166176
// Create a work queue for each scheduler, ntimes. Create an extra
@@ -176,7 +186,7 @@ impl SchedPool {
176186
rtdebug!("inserting a regular scheduler");
177187

178188
let mut sched = ~Scheduler::new(pool.id,
179-
new_event_loop(),
189+
(pool.factory)(),
180190
worker,
181191
pool.stealers.clone(),
182192
pool.sleepers.clone());
@@ -232,7 +242,7 @@ impl SchedPool {
232242
// other schedulers as well as having a stealer handle to all other
233243
// schedulers.
234244
let mut sched = ~Scheduler::new(self.id,
235-
new_event_loop(),
245+
(self.factory)(),
236246
worker,
237247
self.stealers.clone(),
238248
self.sleepers.clone());
@@ -270,19 +280,19 @@ impl Drop for SchedPool {
270280
}
271281
}
272282

273-
fn new_event_loop() -> ~rtio::EventLoop {
283+
fn default_event_loop_factory() -> fn() -> ~rtio::EventLoop {
274284
match crate_map::get_crate_map() {
275285
None => {}
276286
Some(map) => {
277287
match map.event_loop_factory {
278288
None => {}
279-
Some(factory) => return factory()
289+
Some(factory) => return factory
280290
}
281291
}
282292
}
283293

284294
// If the crate map didn't specify a factory to create an event loop, then
285295
// instead just use a basic event loop missing all I/O services to at least
286296
// get the scheduler running.
287-
return basic::event_loop();
297+
return basic::event_loop;
288298
}

branches/snap-stage3/src/librustuv/homing.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ mod test {
161161
#[test]
162162
fn test_homing_closes_correctly() {
163163
let (port, chan) = Chan::new();
164-
let mut pool = SchedPool::new(PoolConfig { threads: 1 });
164+
let mut pool = SchedPool::new(PoolConfig {
165+
threads: 1,
166+
event_loop_factory: None,
167+
});
165168

166169
do pool.spawn(TaskOpts::new()) {
167170
let listener = UdpWatcher::bind(local_loop(), next_test_ip4());
@@ -179,7 +182,10 @@ mod test {
179182
#[test]
180183
fn test_homing_read() {
181184
let (port, chan) = Chan::new();
182-
let mut pool = SchedPool::new(PoolConfig { threads: 1 });
185+
let mut pool = SchedPool::new(PoolConfig {
186+
threads: 1,
187+
event_loop_factory: None,
188+
});
183189

184190
do pool.spawn(TaskOpts::new()) {
185191
let addr1 = next_test_ip4();

branches/snap-stage3/src/librustuv/uvio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl rtio::EventLoop for UvEventLoop {
9696

9797
#[cfg(not(test))]
9898
#[lang = "event_loop_factory"]
99-
pub extern "C" fn new_loop() -> ~rtio::EventLoop {
99+
pub fn new_loop() -> ~rtio::EventLoop {
100100
~UvEventLoop::new() as ~rtio::EventLoop
101101
}
102102

branches/snap-stage3/src/libstd/rt/crate_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct CrateMap<'a> {
3030
version: i32,
3131
entries: &'a [ModEntry<'a>],
3232
children: &'a [&'a CrateMap<'a>],
33-
event_loop_factory: Option<extern "C" fn() -> ~EventLoop>,
33+
event_loop_factory: Option<fn() -> ~EventLoop>,
3434
}
3535

3636
#[cfg(not(windows))]

0 commit comments

Comments
 (0)