Skip to content

Commit

Permalink
Implement Sync for `process::Command on unix and vxworks
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSeulArtichaut committed May 22, 2020
1 parent a9ca1ec commit 01630b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/libstd/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2105,8 +2105,8 @@ mod tests {
}

#[test]
fn test_command_implements_send() {
fn take_send_type<T: Send>(_: T) {}
take_send_type(Command::new(""))
fn test_command_implements_send_sync() {
fn take_send_sync_type<T: Send + Sync>(_: T) {}
take_send_sync_type(Command::new(""))
}
}
6 changes: 4 additions & 2 deletions src/libstd/sys/unix/process/process_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ pub struct Command {
stderr: Option<Stdio>,
}

// Create a new type for argv, so that we can make it `Send`
// Create a new type for argv, so that we can make it `Send` and `Sync`
struct Argv(Vec<*const c_char>);

// It is safe to make Argv Send, because it contains pointers to memory owned by `Command.args`
// It is safe to make `Argv` `Send` and `Sync`, because it contains
// pointers to memory owned by `Command.args`
unsafe impl Send for Argv {}
unsafe impl Sync for Argv {}

// passed back to std::process with the pipes connected to the child, if any
// were requested
Expand Down
6 changes: 4 additions & 2 deletions src/libstd/sys/vxworks/process/process_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ pub struct Command {
stderr: Option<Stdio>,
}

// Create a new type for argv, so that we can make it `Send`
// Create a new type for `Argv`, so that we can make it `Send` and `Sync`
struct Argv(Vec<*const c_char>);

// It is safe to make Argv Send, because it contains pointers to memory owned by `Command.args`
// It is safe to make `Argv` `Send` and `Sync`, because it contains
// pointers to memory owned by `Command.args`
unsafe impl Send for Argv {}
unsafe impl Sync for Argv {}

// passed back to std::process with the pipes connected to the child, if any
// were requested
Expand Down

0 comments on commit 01630b2

Please sign in to comment.