Skip to content

Commit

Permalink
implement Send and Sync for raw connection handle on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
apparebit committed Feb 7, 2025
1 parent 04feb38 commit 6cd4ed1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/prettytty/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ pub struct Connection {
connection: RawConnection,
}

fn _assert_connection_is_sync_send() {
fn is_sync_send<T: Sync + Send>() {}
is_sync_send::<Connection>();
fn _assert_connection_is_send_sync() {
fn is_send_sync<T: Send + Sync>() {}
is_send_sync::<Connection>();
}

impl Connection {
Expand Down
7 changes: 7 additions & 0 deletions crates/prettytty/src/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ impl RawConnectionHandle {
}
}

// SAFETY: Windows HANDLE is defined as a *mut c_void but most instances are
// thread-safe. In fact, Rust's standard library [implements `Send` and
// `Sync`](https://github.com/rust-lang/rust/blob/8e37e151835d96d6a7415e93e6876561485a3354/library/std/src/os/windows/io/handle.rs#L111),
// for wrapped handles, too. Also, access to raw input is gated by a mutex.
impl Send for RawConnectionHandle {}
impl Sync for RawConnectionHandle {}

/// A connection to a terminal device.
#[derive(Debug)]
pub(crate) struct RawConnection {
Expand Down

0 comments on commit 6cd4ed1

Please sign in to comment.