Skip to content

Commit

Permalink
Merge pull request #100 from second-state/fix/tokio_block
Browse files Browse the repository at this point in the history
[Fix] tokio block
  • Loading branch information
L-jasmine authored Feb 5, 2024
2 parents fa3f3ce + e45b1e3 commit 1ef2434
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-build-release-lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ jobs:
- name: Build WasmEdge with Release mode
working-directory: WasmEdge
run: |
git checkout $(git describe --tags --abbrev=0)
git checkout $(git describe --abbrev=0)
$vsPath = (vswhere -latest -property installationPath)
Import-Module (Join-Path $vsPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64 -winsdk=10.0.19041.0"
Expand Down
15 changes: 8 additions & 7 deletions crates/async-wasi/src/snapshots/common/net/async_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use socket2::{SockAddr, Socket};
use std::{
ops::DerefMut,
os::unix::prelude::{AsRawFd, FromRawFd, RawFd},
sync::atomic::AtomicBool,
sync::atomic::{AtomicBool, AtomicI8, AtomicU8},
};
use tokio::io::{
unix::{AsyncFd, AsyncFdReadyGuard, TryIoError},
Expand Down Expand Up @@ -150,25 +150,25 @@ impl AsyncWasiSocketInner {
}

#[derive(Debug)]
pub(crate) struct SocketWritable(pub(crate) AtomicBool);
pub(crate) struct SocketWritable(pub(crate) AtomicI8);
impl SocketWritable {
pub(crate) async fn writable(&self) {
let b = self.0.swap(false, std::sync::atomic::Ordering::Acquire);
let b = self.0.fetch_sub(1, std::sync::atomic::Ordering::Acquire);
SocketWritableFuture(b).await;
}

pub(crate) fn set_writable(&self) {
self.0.store(true, std::sync::atomic::Ordering::Release)
self.0.store(2, std::sync::atomic::Ordering::Release)
}
}
impl Default for SocketWritable {
fn default() -> Self {
Self(AtomicBool::new(true))
Self(AtomicI8::new(2))
}
}

#[derive(Debug, Clone, Copy)]
pub(crate) struct SocketWritableFuture(bool);
pub(crate) struct SocketWritableFuture(i8);

impl Future for SocketWritableFuture {
type Output = ();
Expand All @@ -177,7 +177,8 @@ impl Future for SocketWritableFuture {
self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
if self.0 {
log::trace!("SocketWritableFuture self.0={}", self.0);
if self.0 >= 0 {
std::task::Poll::Ready(())
} else {
std::task::Poll::Pending
Expand Down
2 changes: 2 additions & 0 deletions crates/async-wasi/src/snapshots/preview_1/async_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub async fn sock_recv<M: Memory>(
)?;
}

s.writable.set_writable();
mem.write_data(ro_data_len_ptr, (n as u32).to_le())?;
Ok(())
}
Expand Down Expand Up @@ -245,6 +246,7 @@ pub async fn sock_recv_from<M: Memory>(
)?;
}

s.writable.set_writable();
mem.write_data(ro_data_len_ptr, (n as u32).to_le())?;
Ok(())
}
Expand Down

0 comments on commit 1ef2434

Please sign in to comment.