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

Optimize atomic_thread_fence #740

Merged

Conversation

AlexGuteniev
Copy link
Contributor

Fix #739 (without saving stack variable)

@AlexGuteniev AlexGuteniev requested a review from a team as a code owner April 23, 2020 14:28
@StephanTLavavej StephanTLavavej added the performance Must go faster label Apr 24, 2020
Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

Choose a reason for hiding this comment

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

I suggest minor comment edits and sorting the suppressed warnings; other than that, this looks good to me. Assuming that interlocked operations on separate guard variables provide a sufficient fence, there should be no ODR concerns with mixing-and-matching; older TUs will share a single separate guard variable.

stl/inc/atomic Outdated Show resolved Hide resolved
@AlexGuteniev
Copy link
Contributor Author

After @pcordes comment, I'm now thinking that _InterlockedXor(reinterpret_cast<volatile long*>(_AddressOfReturnAddress()), 0); may be a slightly better alternative, and in this case no suppression needed.

But I'll need to add intrinsic include (_AddressOfReturnAddress() is not <intrin0.h>), and you have already approved the current approach, so let's go with that.

@StephanTLavavej StephanTLavavej self-assigned this Apr 29, 2020
@StephanTLavavej StephanTLavavej merged commit a5a9e49 into microsoft:master Apr 30, 2020
@StephanTLavavej
Copy link
Member

Thanks for this performance improvement - I'm really glad you noticed it! 😸

@AlexGuteniev
Copy link
Contributor Author

AlexGuteniev commented Apr 30, 2020

Thanks to @pcordes for great explanations on this subject!

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

Successfully merging this pull request may close these issues.

<atomic>: Optimize atomic_thread_fence
3 participants