Skip to content

Commit f3a39af

Browse files
committed
using IO interface instead calling the console
1 parent 9725151 commit f3a39af

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/executor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub(crate) fn run() {
113113
)]
114114
pub(crate) fn spawn<F>(future: F)
115115
where
116-
F: Future<Output = ()> + Send + 'static,
116+
F: Future<Output = ()> + 'static,
117117
{
118118
core_local::ex().spawn(AsyncTask::new(future)).detach();
119119
}

src/wasm/mod.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use wasi::*;
1010
use wasmtime::*;
1111
use zerocopy::IntoBytes;
1212

13-
use crate::console::CONSOLE;
1413
use crate::executor::{WakerRegistration, spawn};
14+
use crate::fd;
1515
use crate::kernel::systemtime::now_micros;
1616

1717
mod capi;
@@ -271,15 +271,27 @@ pub extern "C" fn sys_unload_binary() -> i32 {
271271
}
272272

273273
async fn wasm_run() {
274-
future::poll_fn(|cx| {
275-
let mut guard = OUTPUT.lock();
276-
while let Some(data) = guard.data.pop_front() {
277-
CONSOLE.lock().write(&data);
274+
loop {
275+
let obj = crate::core_scheduler()
276+
.get_object(fd::STDOUT_FILENO)
277+
.await
278+
.unwrap();
279+
280+
while let Some(data) = OUTPUT.lock().data.pop_front() {
281+
obj.write(&data).await.unwrap();
278282
}
279-
guard.waker.register(cx.waker());
280-
Poll::<()>::Pending
281-
})
282-
.await;
283+
284+
future::poll_fn(|cx| {
285+
let mut guard = OUTPUT.lock();
286+
if guard.data.is_empty() {
287+
guard.waker.register(cx.waker());
288+
Poll::Pending
289+
} else {
290+
Poll::Ready(())
291+
}
292+
})
293+
.await;
294+
}
283295
}
284296

285297
#[hermit_macro::system]

0 commit comments

Comments
 (0)