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

Skip sending ETW trace event for nested lock which is always granted automatically #1301

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Microsoft.VisualStudio.Threading/AsyncReaderWriterLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ private void CheckSynchronizationContextAppropriateForLock(Awaiter? awaiter)
private bool TryIssueLock(Awaiter awaiter, bool previouslyQueued, bool skipPendingWriteLockCheck = false)
{
bool issued = false;
bool isOrdinaryNestedLock = false; // ordinary nested lock is a nested lock always granted immediately. We don't need write ETW event to reduce noise in traces.

lock (this.syncObject)
{
Expand Down Expand Up @@ -1108,17 +1109,20 @@ private bool TryIssueLock(Awaiter awaiter, bool previouslyQueued, bool skipPendi
}

issued = true;
isOrdinaryNestedLock = true;
}
else if (hasRead || hasUpgradeableRead)
{
issued = true;
isOrdinaryNestedLock = true;
}

break;
case LockKind.UpgradeableRead:
if (hasUpgradeableRead || hasWrite)
{
issued = true;
isOrdinaryNestedLock = true;
}
else if (hasRead)
{
Expand All @@ -1137,6 +1141,7 @@ private bool TryIssueLock(Awaiter awaiter, bool previouslyQueued, bool skipPendi
if (hasWrite)
{
issued = true;
isOrdinaryNestedLock = true;
}
else if (hasRead && !hasUpgradeableRead)
{
Expand Down Expand Up @@ -1170,7 +1175,10 @@ private bool TryIssueLock(Awaiter awaiter, bool previouslyQueued, bool skipPendi

if (issued)
{
this.etw.Issued(awaiter);
if (!isOrdinaryNestedLock)
{
this.etw.Issued(awaiter);
}
}
else
{
Expand Down