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

add bindings for critical section API #4477

Merged
merged 4 commits into from
Aug 24, 2024

Conversation

ngoldbaum
Copy link
Contributor

refs #4265, specifically #4265 (comment), ultimately we want to use this in GILProtected and GILOnceCell.

#4439 is an alternate approach that also uses this API for dict iteration (following the suggestion in the docs for PyDict_Next). I'm holding off on using this API in that spot because of the discussion in that PR.

That PR doesn't use opaque_struct on the GIL-enabled build, but I think that's actually the correct thing to do, since it's an opaque struct in the regular ABI:

https://github.com/python/cpython/blob/556e8556849cb9df0666629b0f564b5dd203344c/Include/cpython/critical_section.h#L70-L71

I'm not exposing the begin/end critical section macros because they include braces and are not expressible in rust.

@bschoenmaeckers
Copy link
Contributor

bschoenmaeckers commented Aug 23, 2024

I'm not exposing the begin/end critical section macros because they include braces and are not expressible in rust.

I kind of like the idea of an inline function that will initialise the CriticalSection object for you before calling PyCriticalSection_Begin.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

Regarding the macros, usually we don't expose these in pyo3-ffi as we can't match the C semantics. But we can add a safe wrapper in pyo3::sync!

@davidhewitt davidhewitt added this pull request to the merge queue Aug 24, 2024
Merged via the queue into PyO3:main with commit 03e85c2 Aug 24, 2024
42 of 43 checks passed
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.

3 participants