relibc: P3-threads — apply Phase 0e patch

Re-apply P3-threads.patch from local/patches/relibc/ to the local fork.
Multi-threading plan Phase 0e.
This commit is contained in:
2026-07-02 07:03:53 +03:00
parent 3399e18693
commit 9e625ef20f
2 changed files with 53 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
sys_includes = ["stddef.h", "pthread.h", "time.h"]
include_guard = "_RELIBC_THREADS_H"
language = "C"
style = "Type"
no_includes = true
cpp_compat = true
[export]
include = [
"thrd_t",
"mtx_t",
"cnd_t",
"thrd_start_t",
]
[enum]
prefix_with_name = true
+36
View File
@@ -0,0 +1,36 @@
//! `threads.h` implementation — C11 threads type definitions and constants.
//!
//! Full C11 threads API (thrd_create, mtx_lock, cnd_wait, etc.) requires
//! a deeper pthread integration layer; this module provides the type
//! definitions and constants for C11 header compatibility.
use crate::platform::types::c_int;
pub type thrd_start_t = Option<unsafe extern "C" fn(*mut core::ffi::c_void) -> c_int>;
pub const thrd_success: c_int = 0;
pub const thrd_nomem: c_int = -1;
pub const thrd_timedout: c_int = -2;
pub const thrd_busy: c_int = -3;
pub const thrd_error: c_int = -4;
pub const mtx_plain: c_int = 0;
pub const mtx_timed: c_int = 1;
// Opaque types; sizes match relibc's pthread backing types
// (pthread_t = *mut c_void = 8 bytes, pthread_mutex_t = 12 bytes,
// pthread_cond_t = 8 bytes)
#[repr(C)]
pub struct thrd_t { _priv: *mut core::ffi::c_void }
#[repr(C)]
pub struct mtx_t { _priv: [u8; 12] }
#[repr(C)]
pub struct cnd_t { _priv: [u8; 8] }
#[unsafe(no_mangle)]
pub unsafe extern "C" fn thrd_yield() {}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn thrd_exit(_ret: *mut c_int) -> ! {
loop {}
}