Remove unsafe from executor api
This commit is contained in:
parent
e9843c3f0a
commit
4cc8bbd06c
@ -258,27 +258,24 @@ impl Executor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn a future on this executor.
|
/// Spawn a future on this executor.
|
||||||
///
|
pub fn spawn(&'static self, token: SpawnToken) -> Result<(), SpawnError> {
|
||||||
/// safety: can only be called from the executor thread
|
|
||||||
pub unsafe fn spawn(&'static self, token: SpawnToken) -> Result<(), SpawnError> {
|
|
||||||
let header = token.header;
|
let header = token.header;
|
||||||
mem::forget(token);
|
mem::forget(token);
|
||||||
|
|
||||||
match header {
|
match header {
|
||||||
Some(header) => {
|
Some(header) => unsafe {
|
||||||
let header = header.as_ref();
|
let header = header.as_ref();
|
||||||
header.executor.set(self);
|
header.executor.set(self);
|
||||||
self.enqueue(header as *const _ as _);
|
self.enqueue(header as *const _ as _);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
},
|
||||||
None => Err(SpawnError::Busy),
|
None => Err(SpawnError::Busy),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the executor until the queue is empty.
|
/// Runs the executor until the queue is empty.
|
||||||
///
|
pub fn run(&self) {
|
||||||
/// safety: can only be called from the executor thread
|
unsafe {
|
||||||
pub unsafe fn run(&self) {
|
|
||||||
self.queue.dequeue_all(|p| {
|
self.queue.dequeue_all(|p| {
|
||||||
let header = &*p;
|
let header = &*p;
|
||||||
|
|
||||||
@ -297,3 +294,4 @@ impl Executor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -34,14 +34,14 @@ impl<A: Alarm> TimerExecutor<A> {
|
|||||||
/// Spawn a future on this executor.
|
/// Spawn a future on this executor.
|
||||||
///
|
///
|
||||||
/// safety: can only be called from the executor thread
|
/// safety: can only be called from the executor thread
|
||||||
pub unsafe fn spawn(&'static self, token: SpawnToken) -> Result<(), SpawnError> {
|
pub fn spawn(&'static self, token: SpawnToken) -> Result<(), SpawnError> {
|
||||||
self.inner.spawn(token)
|
self.inner.spawn(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the executor until the queue is empty.
|
/// Runs the executor until the queue is empty.
|
||||||
///
|
///
|
||||||
/// safety: can only be called from the executor thread
|
/// safety: can only be called from the executor thread
|
||||||
pub unsafe fn run(&'static self) {
|
pub fn run(&'static self) {
|
||||||
with_timer_queue(&self.timer_queue, || {
|
with_timer_queue(&self.timer_queue, || {
|
||||||
self.timer_queue.check_expirations();
|
self.timer_queue.check_expirations();
|
||||||
self.inner.run();
|
self.inner.run();
|
||||||
|
Loading…
Reference in New Issue
Block a user