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

Refactor sync::batch_semaphore::Semaphore::poll_acquire #7046

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

Conversation

cip999
Copy link

@cip999 cip999 commented Dec 18, 2024

Motivation

I found the implementation of the low-level semaphore a bit hard to read compared to other code (possibly because it has been untouched for some years). It could potentially benefit from small rewrites, better documentation, and the like.

Solution

Well, I thought it would be faster to attempt a PR for an initial change, rather than opening an issue. But I have no expectations that it will be merged. :)

I reworked the poll_acquire method, these are the major changes:

  • Restructured the control flow so that there is less logic inside the loop (specifically, only kept what really matters for the CAS subtraction).
  • Renamed a bunch of variables.
  • More commentary, and tried to clarify some details that weren't obvious to me.

This probably needs a thorough review to make sure that I haven't messed up anything (or more likely, figure out what I have). If this kind of refactoring is accepted in core modules, I'm also happy to follow up with similar ones.

@github-actions github-actions bot added the R-loom-sync Run loom sync tests on this PR label Dec 18, 2024
@hawkw hawkw self-requested a review December 18, 2024 23:27
This commit tries to make the logic in `poll_acquire` flow more naturally,
while also using more descriptive names and improving commentary (including
the addition of a missing "SAFETY:" annotation).

There should be no functional changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R-loom-sync Run loom sync tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant