Skip to main content

libc/new/glibc/sysdeps/x86/nptl/bits/
struct_mutex.rs

1//! Header: `sysdeps/x86/nptl/bits/struct_mutex.h`
2
3use crate::prelude::*;
4
5pub const fn __PTHREAD_MUTEX_INITIALIZER(__kind: c_int) -> crate::pthread_mutex_t {
6    // We don't need the whole complicated `__pthread_mutex_s` definition, just use the
7    // offset of the `__kind` field.
8    let kind_offset = if truecfg!(target_pointer_width = "64") {
9        4 * size_of::<c_int>()
10    } else {
11        3 * size_of::<c_int>()
12    };
13
14    let size = [0; crate::__SIZEOF_PTHREAD_MUTEX_T];
15    let kind_bytes = __kind.to_ne_bytes();
16    let repl = u8_slice_cast_char_slice(&kind_bytes);
17    let size = replace_array_items(size, repl, kind_offset);
18    crate::pthread_mutex_t { size }
19}