Skip to content

Commit de5c525

Browse files
Rollup merge of #43544 - redox-os:update_redox_sys, r=sfackler
Update redox sys - Add JoinHandleExt - Split FL and FD for fcntl
2 parents e5116b6 + a30092f commit de5c525

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

src/libstd/sys/redox/ext/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub mod ffi;
3333
pub mod fs;
3434
pub mod io;
3535
pub mod process;
36+
pub mod thread;
3637

3738
/// A prelude for conveniently writing platform-specific code.
3839
///
@@ -46,5 +47,7 @@ pub mod prelude {
4647
#[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
4748
pub use super::fs::{FileTypeExt, PermissionsExt, OpenOptionsExt, MetadataExt};
4849
#[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
50+
pub use super::thread::JoinHandleExt;
51+
#[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
4952
pub use super::process::{CommandExt, ExitStatusExt};
5053
}

src/libstd/sys/redox/ext/thread.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Unix-specific extensions to primitives in the `std::thread` module.
12+
13+
#![stable(feature = "thread_extensions", since = "1.9.0")]
14+
15+
use sys_common::{AsInner, IntoInner};
16+
use thread::JoinHandle;
17+
18+
#[stable(feature = "thread_extensions", since = "1.9.0")]
19+
#[allow(deprecated)]
20+
pub type RawPthread = usize;
21+
22+
/// Unix-specific extensions to `std::thread::JoinHandle`
23+
#[stable(feature = "thread_extensions", since = "1.9.0")]
24+
pub trait JoinHandleExt {
25+
/// Extracts the raw pthread_t without taking ownership
26+
#[stable(feature = "thread_extensions", since = "1.9.0")]
27+
fn as_pthread_t(&self) -> RawPthread;
28+
29+
/// Consumes the thread, returning the raw pthread_t
30+
///
31+
/// This function **transfers ownership** of the underlying pthread_t to
32+
/// the caller. Callers are then the unique owners of the pthread_t and
33+
/// must either detach or join the pthread_t once it's no longer needed.
34+
#[stable(feature = "thread_extensions", since = "1.9.0")]
35+
fn into_pthread_t(self) -> RawPthread;
36+
}
37+
38+
#[stable(feature = "thread_extensions", since = "1.9.0")]
39+
impl<T> JoinHandleExt for JoinHandle<T> {
40+
fn as_pthread_t(&self) -> RawPthread {
41+
self.as_inner().id() as RawPthread
42+
}
43+
44+
fn into_pthread_t(self) -> RawPthread {
45+
self.into_inner().into_id() as RawPthread
46+
}
47+
}

src/libstd/sys/redox/fd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ impl FileDesc {
5757
}
5858

5959
pub fn set_cloexec(&self) -> io::Result<()> {
60-
let mut flags = cvt(syscall::fcntl(self.fd, syscall::F_GETFL, 0))?;
60+
let mut flags = cvt(syscall::fcntl(self.fd, syscall::F_GETFD, 0))?;
6161
flags |= syscall::O_CLOEXEC;
62-
cvt(syscall::fcntl(self.fd, syscall::F_SETFL, flags)).and(Ok(()))
62+
cvt(syscall::fcntl(self.fd, syscall::F_SETFD, flags)).and(Ok(()))
6363
}
6464

6565
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {

src/libstd/sys/redox/process.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -272,21 +272,21 @@ impl Command {
272272

273273
if let Some(fd) = stdio.stderr.fd() {
274274
t!(cvt(syscall::dup2(fd, 2, &[])));
275-
let mut flags = t!(cvt(syscall::fcntl(2, syscall::F_GETFL, 0)));
275+
let mut flags = t!(cvt(syscall::fcntl(2, syscall::F_GETFD, 0)));
276276
flags &= ! syscall::O_CLOEXEC;
277-
t!(cvt(syscall::fcntl(2, syscall::F_SETFL, flags)));
277+
t!(cvt(syscall::fcntl(2, syscall::F_SETFD, flags)));
278278
}
279279
if let Some(fd) = stdio.stdout.fd() {
280280
t!(cvt(syscall::dup2(fd, 1, &[])));
281-
let mut flags = t!(cvt(syscall::fcntl(1, syscall::F_GETFL, 0)));
281+
let mut flags = t!(cvt(syscall::fcntl(1, syscall::F_GETFD, 0)));
282282
flags &= ! syscall::O_CLOEXEC;
283-
t!(cvt(syscall::fcntl(1, syscall::F_SETFL, flags)));
283+
t!(cvt(syscall::fcntl(1, syscall::F_SETFD, flags)));
284284
}
285285
if let Some(fd) = stdio.stdin.fd() {
286286
t!(cvt(syscall::dup2(fd, 0, &[])));
287-
let mut flags = t!(cvt(syscall::fcntl(0, syscall::F_GETFL, 0)));
287+
let mut flags = t!(cvt(syscall::fcntl(0, syscall::F_GETFD, 0)));
288288
flags &= ! syscall::O_CLOEXEC;
289-
t!(cvt(syscall::fcntl(0, syscall::F_SETFL, flags)));
289+
t!(cvt(syscall::fcntl(0, syscall::F_SETFD, flags)));
290290
}
291291

292292
if let Some(g) = self.gid {

src/libstd/sys/redox/syscall/flag.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ pub const EVENT_NONE: usize = 0;
2020
pub const EVENT_READ: usize = 1;
2121
pub const EVENT_WRITE: usize = 2;
2222

23-
pub const F_GETFL: usize = 1;
24-
pub const F_SETFL: usize = 2;
23+
pub const F_GETFD: usize = 1;
24+
pub const F_SETFD: usize = 2;
25+
pub const F_GETFL: usize = 3;
26+
pub const F_SETFL: usize = 4;
2527

2628
pub const FUTEX_WAIT: usize = 0;
2729
pub const FUTEX_WAKE: usize = 1;

0 commit comments

Comments
 (0)