Skip to content

Commit 76ebf0c

Browse files
committed
Auto merge of #3347 - 4lDO2:redox_pthreads, r=JohnTitor
Redox pthreads This updates the pthread typedefs and sigset_t, following the [relatively recent Redox pthreads rewrite](https://gitlab.redox-os.org/redox-os/relibc/-/merge_requests/380).
2 parents f6f46ae + a778aba commit 76ebf0c

File tree

1 file changed

+77
-11
lines changed

1 file changed

+77
-11
lines changed

src/unix/redox/mod.rs

+77-11
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,13 @@ pub type nfds_t = ::c_ulong;
2828
pub type nlink_t = ::c_ulong;
2929
pub type off_t = ::c_longlong;
3030
pub type pthread_t = *mut ::c_void;
31-
pub type pthread_attr_t = *mut ::c_void;
32-
pub type pthread_cond_t = *mut ::c_void;
33-
pub type pthread_condattr_t = *mut ::c_void;
3431
// Must be usize due to libstd/sys_common/thread_local.rs,
3532
// should technically be *mut ::c_void
3633
pub type pthread_key_t = usize;
37-
pub type pthread_mutex_t = *mut ::c_void;
38-
pub type pthread_mutexattr_t = *mut ::c_void;
39-
pub type pthread_rwlock_t = *mut ::c_void;
40-
pub type pthread_rwlockattr_t = *mut ::c_void;
4134
pub type rlim_t = ::c_ulonglong;
4235
pub type sa_family_t = u16;
4336
pub type sem_t = *mut ::c_void;
44-
pub type sigset_t = ::c_ulong;
37+
pub type sigset_t = ::c_ulonglong;
4538
pub type socklen_t = u32;
4639
pub type speed_t = u32;
4740
pub type suseconds_t = ::c_int;
@@ -265,7 +258,74 @@ s! {
265258
pub uid: uid_t,
266259
pub gid: gid_t,
267260
}
261+
262+
#[cfg_attr(target_pointer_width = "32", repr(C, align(4)))]
263+
#[cfg_attr(target_pointer_width = "64", repr(C, align(8)))]
264+
pub struct pthread_attr_t {
265+
bytes: [u8; _PTHREAD_ATTR_SIZE],
266+
}
267+
#[repr(C)]
268+
#[repr(align(4))]
269+
pub struct pthread_barrier_t {
270+
bytes: [u8; _PTHREAD_BARRIER_SIZE],
271+
}
272+
#[repr(C)]
273+
#[repr(align(4))]
274+
pub struct pthread_barrierattr_t {
275+
bytes: [u8; _PTHREAD_BARRIERATTR_SIZE],
276+
}
277+
#[repr(C)]
278+
#[repr(align(4))]
279+
pub struct pthread_mutex_t {
280+
bytes: [u8; _PTHREAD_MUTEX_SIZE],
281+
}
282+
#[repr(C)]
283+
#[repr(align(4))]
284+
pub struct pthread_rwlock_t {
285+
bytes: [u8; _PTHREAD_RWLOCK_SIZE],
286+
}
287+
#[repr(C)]
288+
#[repr(align(4))]
289+
pub struct pthread_mutexattr_t {
290+
bytes: [u8; _PTHREAD_MUTEXATTR_SIZE],
291+
}
292+
#[repr(C)]
293+
#[repr(align(1))]
294+
pub struct pthread_rwlockattr_t {
295+
bytes: [u8; _PTHREAD_RWLOCKATTR_SIZE],
296+
}
297+
#[repr(C)]
298+
#[repr(align(4))]
299+
pub struct pthread_cond_t {
300+
bytes: [u8; _PTHREAD_COND_SIZE],
301+
}
302+
#[repr(C)]
303+
#[repr(align(4))]
304+
pub struct pthread_condattr_t {
305+
bytes: [u8; _PTHREAD_CONDATTR_SIZE],
306+
}
307+
#[repr(C)]
308+
#[repr(align(4))]
309+
pub struct pthread_once_t {
310+
bytes: [u8; _PTHREAD_ONCE_SIZE],
311+
}
312+
#[repr(C)]
313+
#[repr(align(4))]
314+
pub struct pthread_spinlock_t {
315+
bytes: [u8; _PTHREAD_SPINLOCK_SIZE],
316+
}
268317
}
318+
const _PTHREAD_ATTR_SIZE: usize = 32;
319+
const _PTHREAD_RWLOCKATTR_SIZE: usize = 1;
320+
const _PTHREAD_RWLOCK_SIZE: usize = 4;
321+
const _PTHREAD_BARRIER_SIZE: usize = 24;
322+
const _PTHREAD_BARRIERATTR_SIZE: usize = 4;
323+
const _PTHREAD_CONDATTR_SIZE: usize = 8;
324+
const _PTHREAD_COND_SIZE: usize = 8;
325+
const _PTHREAD_MUTEX_SIZE: usize = 12;
326+
const _PTHREAD_MUTEXATTR_SIZE: usize = 20;
327+
const _PTHREAD_ONCE_SIZE: usize = 4;
328+
const _PTHREAD_SPINLOCK_SIZE: usize = 4;
269329

270330
pub const UTSLENGTH: usize = 65;
271331

@@ -549,9 +609,15 @@ pub const POLLWRBAND: ::c_short = 0x200;
549609
// pthread.h
550610
pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
551611
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
552-
pub const PTHREAD_MUTEX_INITIALIZER: ::pthread_mutex_t = -1isize as *mut _;
553-
pub const PTHREAD_COND_INITIALIZER: ::pthread_cond_t = -1isize as *mut _;
554-
pub const PTHREAD_RWLOCK_INITIALIZER: ::pthread_rwlock_t = -1isize as *mut _;
612+
pub const PTHREAD_MUTEX_INITIALIZER: ::pthread_mutex_t = ::pthread_mutex_t {
613+
bytes: [0; _PTHREAD_MUTEX_SIZE],
614+
};
615+
pub const PTHREAD_COND_INITIALIZER: ::pthread_cond_t = ::pthread_cond_t {
616+
bytes: [0; _PTHREAD_COND_SIZE],
617+
};
618+
pub const PTHREAD_RWLOCK_INITIALIZER: ::pthread_rwlock_t = ::pthread_rwlock_t {
619+
bytes: [0; _PTHREAD_RWLOCK_SIZE],
620+
};
555621
pub const PTHREAD_STACK_MIN: ::size_t = 4096;
556622

557623
// signal.h

0 commit comments

Comments
 (0)