Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Make SpinLock.TryEnter(ref bool) fail faster#2628

Merged
jkotas merged 2 commits into
dotnet:masterfrom
jkotas:coreclr-9224
Feb 1, 2017
Merged

Make SpinLock.TryEnter(ref bool) fail faster#2628
jkotas merged 2 commits into
dotnet:masterfrom
jkotas:coreclr-9224

Conversation

@jkotas
Copy link
Copy Markdown
Member

@jkotas jkotas commented Feb 1, 2017

One uses SpinLock.TryEnter(ref bool) when they want to do a quick test to either acquire the lock or know it's held by someone else. We can make the latter path much faster so that it fails faster.

Port dotnet/coreclr#9224

@jkotas
Copy link
Copy Markdown
Member Author

jkotas commented Feb 1, 2017

curl https://github.com/dotnet/coreclr/commit/21c89ff541d210d4bef04e074c1be962d3104fbc.patch | git am -p 3 --directory=src/System.Private.CoreLib/ --reject

cc @stephentoub

One uses SpinLock.TryEnter(ref bool) when they want to do a quick test to either acquire the lock or know it's held by someone else.  We can make the latter path much faster so that it fails faster.
else
{
// Lock wasn't held; try to acquire it.
Interlocked.CompareExchange(ref m_owner, observedOwner | LOCK_ANONYMOUS_OWNED, observedOwner, ref lockTaken);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for porting this, Jan. Looks like this overload doesn't exist in corert.

@jkotas jkotas merged commit 1a2a3f0 into dotnet:master Feb 1, 2017
@jkotas jkotas deleted the coreclr-9224 branch February 4, 2017 06:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants