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

Make futex and condition variable waiting interfaces more similar. #46

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

VoxSciurorum
Copy link
Contributor

Also, move some code out of header files. The implementations already require function calls and system calls. Inlining them adds little value.

This adds support for the FreeBSD equivalent of futex.

Apple's operating system has a similar feature, not yet enabled because the interface is not meant to be used directly by applications. If we switch to using C++20 for the runtime we can use std::atomic::wait.

Also, move some code out of header files.  The implementations
already require function calls and system calls.  Inlining them
adds little value.

#if USE_FUTEX
// Wait for *obj to be unequal to val.
extern void cond_wait(futex_t *obj, futex_val_t val);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add a condvar.h?

@kyle-singer
Copy link
Collaborator

kyle-singer commented Jan 24, 2025

atomic-interop.tar.gz
My understanding is that C11 and C++ atomics are bit compatible for at least clang, gcc, and msvc (I think one of the standards recommends, but does not require it?). I tested with the attached code on x86_64 with clang and gcc, and it seems to suggest we could make just condvar.c -> condvar.cpp to use std::atomic::wait with this interface.

(This was meant to just be a quick and simple test, so doesn't directly test std::atomic::wait, just checks that storing in c and loading in c++ works).

@VoxSciurorum
Copy link
Contributor Author

atomic-interop.tar.gz My understanding is that C11 and C++ atomics are bit compatible for at least clang, gcc, and msvc (I think one of the standards recommends, but does not require it?). I tested with the attached code on x86_64 with clang and gcc, and it seems to suggest we could make just condvar.c -> condvar.cpp to use std::atomic::wait with this interface.

(This was meant to just be a quick and simple test, so doesn't directly test std::atomic::wait, just checks that storing in c and loading in c++ works).

I would rather be type safe than rely on that behavior. TB and I have talked about changing the runtime from C to simple C++. If we do that we can switch everything to std::atomic, assuming the implementations are fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants