use std::{mem, num::NonZero};
use crate::{Errno, kernel};
pub struct Attrs(libc::pthread_attr_t);
impl Attrs {
pub fn with_stack(stack: NonZero<usize>) -> Result<Self, Errno> {
let mut raw = mem::MaybeUninit::uninit();
let result = unsafe { libc::pthread_attr_init(raw.as_mut_ptr()) };
unsafe { kernel::raw::Status::new(result).try_pthread() }?;
let mut attr = Self(unsafe { raw.assume_init() });
let result = unsafe { libc::pthread_attr_setstacksize(&mut attr.0, stack.get()) };
unsafe { kernel::raw::Status::new(result).try_pthread() }?;
Ok(attr)
}
pub(super) fn as_ptr(&self) -> *const libc::pthread_attr_t {
&self.0
}
}
impl Drop for Attrs {
fn drop(&mut self) {
unsafe { libc::pthread_attr_destroy(&mut self.0) };
}
}