split out pthread_attr_t

This commit is contained in:
auronandace
2026-07-04 17:16:08 +01:00
parent fe20b68a95
commit 185b49b73e
7 changed files with 63 additions and 37 deletions
+2 -3
View File
@@ -6,11 +6,10 @@
# - "The <aio.h> header shall define the sigevent structure and sigval union as described in <signal.h>."
# - "Inclusion of the <aio.h> header may make visible symbols defined in the headers <fcntl.h>, <signal.h>, and <time.h>."
#
# TODO don't bring in all of bits/pthread.h
#
# signal.h brings in sigevent and sigval
# signal.h brings in bits/timespec.h for timespec from time.h
# signal.h brings in bits/pthread.h bringing in pthread_attr_t from sys/types.h
# signal.h brings in bits/pthread-t.h bringing in pthread_t from sys/types.h
# signal.h brings in bits/pthreadattr-t.h bringing in pthread_attr_t from sys/types.h
# signal.h brings in size_t from sys/types.h
sys_includes = ["signal.h"]
after_includes = """
+3 -5
View File
@@ -5,10 +5,8 @@
# POSIX headers that require them:
# - aio.h (pthread_attr_t only)
# - pthread.h (all of them)
# - signal (pthread_t and pthread_attr_t only)
# - signal.h (pthread_t and pthread_attr_t only)
# - sys/types.h (where they should be defined)
#
# TODO split out pthread_attr_t
include_guard = "_RELIBC_BITS_PTHREAD_H"
language = "C"
style = "type"
@@ -16,7 +14,8 @@ no_includes = true
cpp_compat = true
# TODO split out PTHREAD_ONCE_INIT for threads.h
after_includes = """
#include <bits/pthread-t.h> // for pthread_t from sys/types.h
#include <bits/pthread-t.h> // for pthread_t from sys/types.h
#include <bits/pthreadattr-t.h> // for pthread_attr_t from sys/types.h
#define PTHREAD_ONCE_INIT ((pthread_once_t){0})
@@ -24,7 +23,6 @@ after_includes = """
[export]
include = [
"pthread_attr_t",
"pthread_rwlockattr_t",
"pthread_rwlock_t",
"pthread_barrier_t",
+15 -21
View File
@@ -1,8 +1,8 @@
#![allow(non_camel_case_types)]
use crate::platform::types::{c_int, c_uchar, c_ulong, size_t};
use crate::platform::types::{c_int, c_uchar, c_ulong};
pub use crate::header::bits_pthread_t::pthread_t;
pub use crate::header::{bits_pthread_t::pthread_t, bits_pthreadattr_t::pthread_attr_t};
// XXX: https://github.com/eqrion/cbindgen/issues/685
//
@@ -10,12 +10,6 @@ pub use crate::header::bits_pthread_t::pthread_t;
// expanding macros! Instead, we rely on checking that the lengths are correct, when these headers
// are parsed in the regular compilation phase.
/// The `pthread_attr_t` type provided in [`sys/types.h`](crate::header::sys_types).
#[repr(C)]
pub union pthread_attr_t {
__relibc_internal_size: [c_uchar; 32],
__relibc_internal_align: size_t,
}
/// The `pthread_rwlockattr_t` type provided in [`sys/types.h`](crate::header::sys_types).
#[repr(C)]
pub union pthread_rwlockattr_t {
@@ -77,10 +71,11 @@ pub union pthread_once_t {
__relibc_internal_align: c_int,
}
macro_rules! assert_equal_size(
#[macro_export]
macro_rules! pthread_assert_equal_size(
($export:ident, $wrapped:ident) => {
const _: () = unsafe {
type Wrapped = crate::header::pthread::$wrapped;
type Wrapped = $crate::header::pthread::$wrapped;
// Fail at compile-time if sizes differ.
@@ -107,17 +102,16 @@ macro_rules! assert_equal_size(
};
}
);
assert_equal_size!(pthread_attr_t, RlctAttr);
assert_equal_size!(pthread_rwlock_t, RlctRwlock);
assert_equal_size!(pthread_rwlockattr_t, RlctRwlockAttr);
assert_equal_size!(pthread_barrier_t, RlctBarrier);
assert_equal_size!(pthread_barrierattr_t, RlctBarrierAttr);
assert_equal_size!(pthread_mutex_t, RlctMutex);
assert_equal_size!(pthread_mutexattr_t, RlctMutexAttr);
assert_equal_size!(pthread_cond_t, RlctCond);
assert_equal_size!(pthread_condattr_t, RlctCondAttr);
assert_equal_size!(pthread_spinlock_t, RlctSpinlock);
assert_equal_size!(pthread_once_t, RlctOnce);
pthread_assert_equal_size!(pthread_rwlock_t, RlctRwlock);
pthread_assert_equal_size!(pthread_rwlockattr_t, RlctRwlockAttr);
pthread_assert_equal_size!(pthread_barrier_t, RlctBarrier);
pthread_assert_equal_size!(pthread_barrierattr_t, RlctBarrierAttr);
pthread_assert_equal_size!(pthread_mutex_t, RlctMutex);
pthread_assert_equal_size!(pthread_mutexattr_t, RlctMutexAttr);
pthread_assert_equal_size!(pthread_cond_t, RlctCond);
pthread_assert_equal_size!(pthread_condattr_t, RlctCondAttr);
pthread_assert_equal_size!(pthread_spinlock_t, RlctSpinlock);
pthread_assert_equal_size!(pthread_once_t, RlctOnce);
/// The `pthread_key_t` type provided in [`sys/types.h`](crate::header::sys_types).
pub type pthread_key_t = c_ulong;
@@ -0,0 +1,17 @@
# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_types.h.html
#
# This type is split out to prevent importing all of sys/types.h into other headers.
#
# POSIX headers that require pthread_attr_t:
# - aio.h
# - pthread.h
# - signal.h
# - sys/types.h (where it should be defined)
include_guard = "_RELIBC_BITS_PTHREADATTR_T_H"
language = "C"
no_includes = true
cpp_compat = true
[export]
include = ["pthread_attr_t"]
[enum]
prefix_with_name = true
+17
View File
@@ -0,0 +1,17 @@
//! `pthread_attr_t` from `sys/types.h` implementation.
//!
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_types.h.html>.
use crate::{
platform::types::{c_uchar, size_t},
pthread_assert_equal_size,
};
/// Used to identify a thread attribute object.
#[repr(C)]
pub union pthread_attr_t {
__relibc_internal_size: [c_uchar; 32],
__relibc_internal_align: size_t,
}
pthread_assert_equal_size!(pthread_attr_t, RlctAttr);
+2
View File
@@ -40,6 +40,8 @@ pub mod bits_pid_t;
pub mod bits_pthread;
#[path = "bits_pthread-t/mod.rs"]
pub mod bits_pthread_t;
#[path = "bits_pthreadattr-t/mod.rs"]
pub mod bits_pthreadattr_t;
#[path = "bits_reclen-t/mod.rs"]
pub mod bits_reclen_t;
#[path = "bits_safamily-t/mod.rs"]
+7 -8
View File
@@ -11,18 +11,17 @@
# POSIX states signal.h may include time.h and time.h may include signal.h.
# To prevent a cycle between both headers we only import the needed types through bits.
#
# TODO split out types from bits/pthread.h
#
# features.h required for deprecated annotations
sys_includes = ["features.h"]
include_guard = "_RELIBC_SIGNAL_H"
after_includes = """
#include <bits/size-t.h> // for size_t from sys/types.h
#include <bits/pid-t.h> // for pid_t from sys/types.h
#include <bits/uid-t.h> // for uid_t from sys/types.h
#include <bits/pthread.h> // for pthread_t and pthread_attr_t from sys/types.h
#include <bits/sigset-t.h> // for sigset_t
#include <bits/timespec.h> // for timespec from time.h
#include <bits/size-t.h> // for size_t from sys/types.h
#include <bits/pid-t.h> // for pid_t from sys/types.h
#include <bits/uid-t.h> // for uid_t from sys/types.h
#include <bits/pthread-t.h> // for pthread_t from sys/types.h
#include <bits/pthreadattr-t.h> // for pthread_attr_t from sys/types.h
#include <bits/sigset-t.h> // for sigset_t
#include <bits/timespec.h> // for timespec from time.h
// Request for default signal handling.
#define SIG_DFL ((void (*)(int))0)