Skip to content

Commit

Permalink
Auto merge of rust-lang#309 - sfackler:sem, r=alexcrichton
Browse files Browse the repository at this point in the history
Add semaphore APIs
  • Loading branch information
bors committed Jun 6, 2016
2 parents eb637d2 + 41699f7 commit d1f4c2d
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fn main() {
cfg.header("termios.h");
cfg.header("poll.h");
cfg.header("syslog.h");
cfg.header("semaphore.h");
}

if android {
Expand Down Expand Up @@ -285,6 +286,8 @@ fn main() {
// uuid_t is a struct, not an integer.
"uuid_t" if dragonfly => true,
n if n.starts_with("pthread") => true,
// sem_t is a struct or pointer
"sem_t" if openbsd || freebsd || rumprun => true,

// windows-isms
n if n.starts_with("P") => true,
Expand Down Expand Up @@ -363,6 +366,10 @@ fn main() {
// we turn into an error) so just ignore it.
"daemon" if apple => true,

// Deprecated on OSX
"sem_destroy" if apple => true,
"sem_init" if apple => true,

// These functions presumably exist on netbsd but don't look like
// they're implemented on rumprun yet, just let them slide for now.
// Some of them look like they have headers but then don't have
Expand Down
3 changes: 3 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub type speed_t = ::c_ulong;
pub type tcflag_t = ::c_ulong;
pub type nl_item = ::c_int;
pub type id_t = ::c_uint;
pub type sem_t = ::c_int;

pub enum timezone {}

Expand Down Expand Up @@ -1248,6 +1249,8 @@ pub const PRIO_DARWIN_PROCESS: ::c_int = 4;
pub const PRIO_DARWIN_BG: ::c_int = 0x1000;
pub const PRIO_DARWIN_NONUI: ::c_int = 0x1001;

pub const SEM_FAILED: *mut sem_t = -1isize as *mut ::sem_t;

f! {
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
status >> 8
Expand Down
8 changes: 8 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub type tcflag_t = ::c_uint;
pub type speed_t = ::c_uint;
pub type nl_item = ::c_int;
pub type id_t = i64;
pub type sem_t = _sem;

pub enum timezone {}

Expand Down Expand Up @@ -149,6 +150,11 @@ s! {
pub int_p_sign_posn: ::c_char,
pub int_n_sign_posn: ::c_char,
}

// internal structure has changed over time
pub struct _sem {
data: [u32; 4],
}
}

pub const LC_COLLATE_MASK: ::c_int = (1 << 0);
Expand Down Expand Up @@ -677,6 +683,8 @@ pub const LOG_NFACILITIES: ::c_int = 24;
pub const TIOCGWINSZ: ::c_ulong = 0x40087468;
pub const TIOCSWINSZ: ::c_ulong = 0x80087467;

pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;

#[link(name = "util")]
extern {
pub fn getnameinfo(sa: *const ::sockaddr,
Expand Down
4 changes: 4 additions & 0 deletions src/unix/bsd/openbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ pub type tcflag_t = ::c_uint;
pub type nl_item = c_long;
pub type clockid_t = ::c_int;
pub type id_t = ::uint32_t;
pub type sem_t = *mut sem;

pub enum timezone {}
pub enum sem {}

s! {
pub struct sigaction {
Expand Down Expand Up @@ -445,6 +447,8 @@ pub const LOG_NFACILITIES: ::c_int = 24;

pub const HW_NCPU: ::c_int = 3;

pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;

#[link(name = "util")]
extern {
pub fn mincore(addr: *mut ::c_void, len: ::size_t,
Expand Down
14 changes: 14 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,20 @@ extern {
pub fn setlocale(category: ::c_int,
locale: *const ::c_char) -> *mut ::c_char;
pub fn localeconv() -> *mut lconv;

pub fn sem_destroy(sem: *mut sem_t) -> ::c_int;
pub fn sem_open(name: *const ::c_char, oflag: ::c_int, ...) -> *mut sem_t;
pub fn sem_close(sem: *mut sem_t) -> ::c_int;
pub fn sem_unlink(name: *const ::c_char) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "sem_wait$UNIX2003")]
pub fn sem_wait(sem: *mut sem_t) -> ::c_int;
pub fn sem_trywait(sem: *mut sem_t) -> ::c_int;
pub fn sem_post(sem: *mut sem_t) -> ::c_int;
pub fn sem_init(sem: *mut sem_t,
pshared: ::c_int,
value: ::c_uint)
-> ::c_int;
}

// TODO: get rid of this cfg(not(...))
Expand Down
6 changes: 6 additions & 0 deletions src/unix/notbsd/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ s! {
#[cfg(target_pointer_width = "32")]
__bits: [__CPU_BITTYPE; 1],
}

pub struct sem_t {
count: ::c_uint,
}
}

pub const BUFSIZ: ::c_uint = 1024;
Expand Down Expand Up @@ -472,6 +476,8 @@ pub const RTLD_NOLOAD: ::c_int = 0x4;
pub const RTLD_NOW: ::c_int = 0;
pub const RTLD_DEFAULT: *mut ::c_void = -1isize as *mut ::c_void;

pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;

f! {
pub fn sigemptyset(set: *mut sigset_t) -> ::c_int {
*set = 0;
Expand Down
9 changes: 9 additions & 0 deletions src/unix/notbsd/linux/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ s! {
pub mem_unit: ::c_uint,
pub _f: [::c_char; 8],
}

// FIXME this is actually a union
pub struct sem_t {
#[cfg(target_pointer_width = "32")]
__size: [::c_char; 16],
#[cfg(target_pointer_width = "64")]
__size: [::c_char; 32],
__align: [::c_long; 0],
}
}

pub const BUFSIZ: ::c_uint = 8192;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ pub const AF_NETLINK: ::c_int = 16;

pub const LOG_NFACILITIES: ::c_int = 24;

pub const SEM_FAILED: *mut ::sem_t = 0 as *mut sem_t;

f! {
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
for slot in cpuset.bits.iter_mut() {
Expand Down
4 changes: 4 additions & 0 deletions src/unix/notbsd/linux/musl/b32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ s! {
pub msg_controllen: ::socklen_t,
pub msg_flags: ::c_int,
}

pub struct sem_t {
__val: [::c_int; 4],
}
}

pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
Expand Down
4 changes: 4 additions & 0 deletions src/unix/notbsd/linux/musl/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ s! {
__pad2: ::socklen_t,
pub msg_flags: ::c_int,
}

pub struct sem_t {
__val: [::c_int; 8],
}
}

pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
Expand Down
9 changes: 9 additions & 0 deletions src/unix/notbsd/linux/other/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ s! {
__unused4: ::c_ulong,
__unused5: ::c_ulong
}

// FIXME this is actually a union
pub struct sem_t {
#[cfg(target_pointer_width = "32")]
__size: [::c_char; 16],
#[cfg(target_pointer_width = "64")]
__size: [::c_char; 32],
__align: [::c_long; 0],
}
}

pub const RLIMIT_RSS: ::c_int = 5;
Expand Down

0 comments on commit d1f4c2d

Please sign in to comment.