Skip to content

Commit

Permalink
Fix alignment of pthread types on NetBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
gandro committed Sep 22, 2015
1 parent 318cd84 commit 428bb16
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/libstd/sys/unix/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,53 +254,61 @@ mod os {
mod os {
use libc;

// size of the type minus width of the magic int field
// size of the type minus width of the magic and alignment field
#[cfg(target_arch = "x86_64")]
const __PTHREAD_MUTEX_SIZE__: usize = 48 - 4;
const __PTHREAD_MUTEX_SIZE__: usize = 48 - 4 - 8;

#[cfg(target_arch = "x86_64")]
const __PTHREAD_COND_SIZE__: usize = 40 - 4;
const __PTHREAD_MUTEXATTR_SIZE__: usize = 16 - 8; // no magic field

#[cfg(target_arch = "x86_64")]
const __PTHREAD_RWLOCK_SIZE__: usize = 64 - 4;
const __PTHREAD_COND_SIZE__: usize = 40 - 4 - 8;

#[cfg(target_arch = "x86_64")]
const __PTHREAD_RWLOCK_SIZE__: usize = 64 - 4 - 8;

const _PTHREAD_MUTEX_MAGIC_INIT: libc::c_uint = 0x33330003;
const _PTHREAD_COND_MAGIC_INIT: libc::c_uint = 0x55550005;
const _PTHREAD_RWLOCK_MAGIC_INIT: libc::c_uint = 0x99990009;

// note the actual structs are smaller

#[repr(C, packed)]
#[repr(C)]
pub struct pthread_mutex_t {
__magic: libc::c_uint,
__opaque: [u8; __PTHREAD_MUTEX_SIZE__],
__align: libc::c_longlong,
}
#[repr(C, packed)]
#[repr(C)]
pub struct pthread_mutexattr_t {
__opaque: [u8; 16],
__opaque: [u8; __PTHREAD_MUTEXATTR_SIZE__],
__align: libc::c_longlong,
}
#[repr(C, packed)]
#[repr(C)]
pub struct pthread_cond_t {
__magic: libc::c_uint,
__opaque: [u8; __PTHREAD_COND_SIZE__],
__align: libc::c_longlong,
}
#[repr(C, packed)]
#[repr(C)]
pub struct pthread_rwlock_t {
__magic: libc::c_uint,
__opaque: [u8; __PTHREAD_RWLOCK_SIZE__],
__align: libc::c_longlong,
}

pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
__magic: _PTHREAD_MUTEX_MAGIC_INIT,
__opaque: [0; __PTHREAD_MUTEX_SIZE__],
__align: 0,
};
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
__magic: _PTHREAD_COND_MAGIC_INIT,
__opaque: [0; __PTHREAD_COND_SIZE__],
__align: 0,
};
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
__magic: _PTHREAD_RWLOCK_MAGIC_INIT,
__opaque: [0; __PTHREAD_RWLOCK_SIZE__],
__align: 0,
};

pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2;
Expand Down

0 comments on commit 428bb16

Please sign in to comment.