Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use futex-based synchronization on Apple platforms #122408

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
std: allow weak in item position on Apple platforms
joboet committed Feb 3, 2025
commit c9f7324c7407ccdde32a8caad55b54b81572e8ef
8 changes: 4 additions & 4 deletions library/std/src/sys/pal/unix/fd.rs
Original file line number Diff line number Diff line change
@@ -284,9 +284,9 @@ impl FileDesc {
super::weak::weak!(fn preadv(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);

match preadv.get() {
Some(preadv) => {
Some(read) => {
let ret = cvt(unsafe {
preadv(
read(
self.as_raw_fd(),
bufs.as_mut_ptr() as *mut libc::iovec as *const libc::iovec,
cmp::min(bufs.len(), max_iov()) as libc::c_int,
@@ -477,9 +477,9 @@ impl FileDesc {
super::weak::weak!(fn pwritev(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);

match pwritev.get() {
Some(pwritev) => {
Some(read) => {
let ret = cvt(unsafe {
pwritev(
read(
self.as_raw_fd(),
bufs.as_ptr() as *const libc::iovec,
cmp::min(bufs.len(), max_iov()) as libc::c_int,
11 changes: 6 additions & 5 deletions library/std/src/sys/pal/unix/weak.rs
Original file line number Diff line number Diff line change
@@ -62,15 +62,16 @@ impl<F: Copy> ExternWeak<F> {
}

pub(crate) macro dlsym {
(fn $name:ident($($t:ty),*) -> $ret:ty) => (
dlsym!(fn $name($($t),*) -> $ret, stringify!($name));
($v:vis fn $name:ident($($t:ty),*) -> $ret:ty) => (
dlsym!($v fn $name($($t),*) -> $ret, stringify!($name));
),
(fn $name:ident($($t:ty),*) -> $ret:ty, $sym:expr) => (
static DLSYM: DlsymWeak<unsafe extern "C" fn($($t),*) -> $ret> =
($v:vis fn $name:ident($($t:ty),*) -> $ret:ty, $sym:expr) => (
#[allow(non_upper_case_globals)]
$v static $name: DlsymWeak<unsafe extern "C" fn($($t),*) -> $ret> =
DlsymWeak::new(concat!($sym, '\0'));
let $name = &DLSYM;
)
}

pub(crate) struct DlsymWeak<F> {
name: &'static str,
func: AtomicPtr<libc::c_void>,