Skip to content

Commit 2c9bb3f

Browse files
committed
Runtime removal: fully remove rtio
This patch cleans up the remnants of the runtime IO interface. Because this eliminates APIs in `libnative` and `librustrt`, it is a: [breaking-change] This functionality is likely to be available publicly, in some form, from `std` in the future.
1 parent 67b123b commit 2c9bb3f

File tree

11 files changed

+11
-276
lines changed

11 files changed

+11
-276
lines changed

src/libgreen/basic.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use alloc::arc::Arc;
1919
use std::sync::atomic;
2020
use std::mem;
21-
use std::rt::rtio::{EventLoop, IoFactory, RemoteCallback};
21+
use std::rt::rtio::{EventLoop, RemoteCallback};
2222
use std::rt::rtio::{PausableIdleCallback, Callback};
2323
use std::rt::exclusive::Exclusive;
2424

@@ -150,8 +150,6 @@ impl EventLoop for BasicLoop {
150150
Box<RemoteCallback + Send>
151151
}
152152

153-
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory> { None }
154-
155153
fn has_active_io(&self) -> bool { false }
156154
}
157155

src/libgreen/simple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std::mem;
1616
use std::rt::Runtime;
1717
use std::rt::local::Local;
1818
use std::rt::mutex::NativeMutex;
19-
use std::rt::rtio;
2019
use std::rt::task::{Task, BlockedTask, TaskOpts};
2120

2221
struct SimpleTask {
@@ -79,9 +78,10 @@ impl Runtime for SimpleTask {
7978
_f: proc():Send) {
8079
panic!()
8180
}
82-
fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> { None }
81+
8382
fn stack_bounds(&self) -> (uint, uint) { panic!() }
8483
fn stack_guard(&self) -> Option<uint> { panic!() }
84+
8585
fn can_block(&self) -> bool { true }
8686
fn wrap(self: Box<SimpleTask>) -> Box<Any+'static> { panic!() }
8787
}

src/libgreen/task.rs

-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use std::raw;
2424
use std::rt::Runtime;
2525
use std::rt::local::Local;
2626
use std::rt::mutex::NativeMutex;
27-
use std::rt::rtio;
2827
use std::rt::stack;
2928
use std::rt::task::{Task, BlockedTask, TaskOpts};
3029
use std::rt;
@@ -468,14 +467,6 @@ impl Runtime for GreenTask {
468467
sched.run_task(me, sibling)
469468
}
470469

471-
// Local I/O is provided by the scheduler's event loop
472-
fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> {
473-
match self.sched.as_mut().unwrap().event_loop.io() {
474-
Some(io) => Some(rtio::LocalIo::new(io)),
475-
None => None,
476-
}
477-
}
478-
479470
fn stack_bounds(&self) -> (uint, uint) {
480471
let c = self.coroutine.as_ref()
481472
.expect("GreenTask.stack_bounds called without a coroutine");

src/libnative/io/mod.rs

-102
This file was deleted.

src/libnative/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ use std::str;
7474

7575
pub use task::NativeTaskBuilder;
7676

77-
pub mod io;
7877
pub mod task;
7978

8079
#[cfg(any(windows, android))]

src/libnative/task.rs

-8
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ use std::mem;
1919
use std::rt::bookkeeping;
2020
use std::rt::local::Local;
2121
use std::rt::mutex::NativeMutex;
22-
use std::rt::rtio;
2322
use std::rt::stack;
2423
use std::rt::task::{Task, BlockedTask, TaskOpts};
2524
use std::rt::thread::Thread;
2625
use std::rt;
2726

28-
use io;
2927
use std::task::{TaskBuilder, Spawner};
3028

3129
/// Creates a new Task which is ready to execute as a 1:1 task.
@@ -42,7 +40,6 @@ fn ops() -> Box<Ops> {
4240
box Ops {
4341
lock: unsafe { NativeMutex::new() },
4442
awoken: false,
45-
io: io::IoFactory::new(),
4643
// these *should* get overwritten
4744
stack_bounds: (0, 0),
4845
stack_guard: 0
@@ -112,7 +109,6 @@ impl<S: Spawner> NativeTaskBuilder for TaskBuilder<S> {
112109
struct Ops {
113110
lock: NativeMutex, // native synchronization
114111
awoken: bool, // used to prevent spurious wakeups
115-
io: io::IoFactory, // local I/O factory
116112

117113
// This field holds the known bounds of the stack in (lo, hi) form. Not all
118114
// native tasks necessarily know their precise bounds, hence this is
@@ -272,10 +268,6 @@ impl rt::Runtime for Ops {
272268

273269
NativeSpawner.spawn(opts, f);
274270
}
275-
276-
fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> {
277-
Some(rtio::LocalIo::new(&mut self.io as &mut rtio::IoFactory))
278-
}
279271
}
280272

281273
#[cfg(test)]

src/librustrt/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub trait Runtime {
9090
cur_task: Box<Task>,
9191
opts: TaskOpts,
9292
f: proc():Send);
93-
fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>>;
9493
/// The (low, high) edges of the current stack.
9594
fn stack_bounds(&self) -> (uint, uint); // (lo, hi)
9695
/// The last writable byte of the stack next to the guard page

src/librustrt/rtio.rs

+1-129
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
1313
use core::prelude::*;
1414
use alloc::boxed::Box;
15-
use collections::string::String;
16-
use core::mem;
17-
use libc::c_int;
18-
19-
use local::Local;
20-
use task::Task;
2115

2216
pub trait EventLoop {
2317
fn run(&mut self);
@@ -27,8 +21,7 @@ pub trait EventLoop {
2721
fn remote_callback(&mut self, Box<Callback + Send>)
2822
-> Box<RemoteCallback + Send>;
2923

30-
/// The asynchronous I/O services. Not all event loops may provide one.
31-
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory>;
24+
// last vestige of IoFactory
3225
fn has_active_io(&self) -> bool;
3326
}
3427

@@ -46,128 +39,7 @@ pub trait RemoteCallback {
4639
fn fire(&mut self);
4740
}
4841

49-
pub struct LocalIo<'a> {
50-
factory: &'a mut IoFactory+'a,
51-
}
52-
53-
#[unsafe_destructor]
54-
impl<'a> Drop for LocalIo<'a> {
55-
fn drop(&mut self) {
56-
// FIXME(pcwalton): Do nothing here for now, but eventually we may want
57-
// something. For now this serves to make `LocalIo` noncopyable.
58-
}
59-
}
60-
61-
impl<'a> LocalIo<'a> {
62-
/// Returns the local I/O: either the local scheduler's I/O services or
63-
/// the native I/O services.
64-
pub fn borrow() -> Option<LocalIo<'a>> {
65-
// FIXME(#11053): bad
66-
//
67-
// This is currently very unsafely implemented. We don't actually
68-
// *take* the local I/O so there's a very real possibility that we
69-
// can have two borrows at once. Currently there is not a clear way
70-
// to actually borrow the local I/O factory safely because even if
71-
// ownership were transferred down to the functions that the I/O
72-
// factory implements it's just too much of a pain to know when to
73-
// relinquish ownership back into the local task (but that would be
74-
// the safe way of implementing this function).
75-
//
76-
// In order to get around this, we just transmute a copy out of the task
77-
// in order to have what is likely a static lifetime (bad).
78-
let mut t: Box<Task> = match Local::try_take() {
79-
Some(t) => t,
80-
None => return None,
81-
};
82-
let ret = t.local_io().map(|t| {
83-
unsafe { mem::transmute_copy(&t) }
84-
});
85-
Local::put(t);
86-
return ret;
87-
}
88-
89-
pub fn maybe_raise<T>(f: |io: &mut IoFactory| -> IoResult<T>)
90-
-> IoResult<T>
91-
{
92-
#[cfg(unix)] use libc::EINVAL as ERROR;
93-
#[cfg(windows)] use libc::ERROR_CALL_NOT_IMPLEMENTED as ERROR;
94-
match LocalIo::borrow() {
95-
Some(mut io) => f(io.get()),
96-
None => Err(IoError {
97-
code: ERROR as uint,
98-
extra: 0,
99-
detail: None,
100-
}),
101-
}
102-
}
103-
104-
pub fn new<'a>(io: &'a mut IoFactory+'a) -> LocalIo<'a> {
105-
LocalIo { factory: io }
106-
}
107-
108-
/// Returns the underlying I/O factory as a trait reference.
109-
#[inline]
110-
pub fn get<'a>(&'a mut self) -> &'a mut IoFactory {
111-
let f: &'a mut IoFactory = self.factory;
112-
f
113-
}
114-
}
115-
116-
pub trait IoFactory {
117-
fn timer_init(&mut self) -> IoResult<Box<RtioTimer + Send>>;
118-
fn tty_open(&mut self, fd: c_int, readable: bool)
119-
-> IoResult<Box<RtioTTY + Send>>;
120-
}
121-
122-
pub trait RtioTimer {
123-
fn sleep(&mut self, msecs: u64);
124-
fn oneshot(&mut self, msecs: u64, cb: Box<Callback + Send>);
125-
fn period(&mut self, msecs: u64, cb: Box<Callback + Send>);
126-
}
127-
128-
pub trait RtioPipe {
129-
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint>;
130-
fn write(&mut self, buf: &[u8]) -> IoResult<()>;
131-
fn clone(&self) -> Box<RtioPipe + Send>;
132-
133-
fn close_write(&mut self) -> IoResult<()>;
134-
fn close_read(&mut self) -> IoResult<()>;
135-
fn set_timeout(&mut self, timeout_ms: Option<u64>);
136-
fn set_read_timeout(&mut self, timeout_ms: Option<u64>);
137-
fn set_write_timeout(&mut self, timeout_ms: Option<u64>);
138-
}
139-
140-
pub trait RtioUnixListener {
141-
fn listen(self: Box<Self>) -> IoResult<Box<RtioUnixAcceptor + Send>>;
142-
}
143-
144-
pub trait RtioUnixAcceptor {
145-
fn accept(&mut self) -> IoResult<Box<RtioPipe + Send>>;
146-
fn set_timeout(&mut self, timeout: Option<u64>);
147-
fn clone(&self) -> Box<RtioUnixAcceptor + Send>;
148-
fn close_accept(&mut self) -> IoResult<()>;
149-
}
150-
151-
pub trait RtioTTY {
152-
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint>;
153-
fn write(&mut self, buf: &[u8]) -> IoResult<()>;
154-
fn set_raw(&mut self, raw: bool) -> IoResult<()>;
155-
fn get_winsize(&mut self) -> IoResult<(int, int)>;
156-
fn isatty(&self) -> bool;
157-
}
158-
15942
pub trait PausableIdleCallback {
16043
fn pause(&mut self);
16144
fn resume(&mut self);
16245
}
163-
164-
pub trait RtioSignal {}
165-
166-
#[deriving(Show)]
167-
pub struct IoError {
168-
pub code: uint,
169-
pub extra: uint,
170-
pub detail: Option<String>,
171-
}
172-
173-
pub type IoResult<T> = Result<T, IoError>;

src/librustrt/task.rs

-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use core::raw;
2626
use local_data;
2727
use Runtime;
2828
use local::Local;
29-
use rtio::LocalIo;
3029
use unwind;
3130
use unwind::Unwinder;
3231
use collections::str::SendStr;
@@ -421,13 +420,6 @@ impl Task {
421420
ops.maybe_yield(self);
422421
}
423422

424-
/// Acquires a handle to the I/O factory that this task contains, normally
425-
/// stored in the task's runtime. This factory may not always be available,
426-
/// which is why the return type is `Option`
427-
pub fn local_io<'a>(&'a mut self) -> Option<LocalIo<'a>> {
428-
self.imp.as_mut().unwrap().local_io()
429-
}
430-
431423
/// Returns the stack bounds for this task in (lo, hi) format. The stack
432424
/// bounds may not be known for all tasks, so the return value may be
433425
/// `None`.

0 commit comments

Comments
 (0)