Skip to content

Commit

Permalink
Merge pull request #1146 from microsoft/dev/lifengl/noEtwInLock
Browse files Browse the repository at this point in the history
Prevent sending ETW within a lock
  • Loading branch information
lifengl authored Feb 7, 2023
2 parents 0fe0cce + 1d32bd1 commit a31490c
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/Microsoft.VisualStudio.Threading/AsyncReaderWriterLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,8 @@ private void CheckSynchronizationContextAppropriateForLock(Awaiter? awaiter)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
private bool TryIssueLock(Awaiter awaiter, bool previouslyQueued, bool skipPendingWriteLockCheck = false)
{
bool issued = false;

lock (this.syncObject)
{
if (this.completeInvoked && !previouslyQueued)
Expand All @@ -1079,7 +1081,6 @@ private bool TryIssueLock(Awaiter awaiter, bool previouslyQueued, bool skipPendi
}
}

bool issued = false;
if (this.reenterConcurrencyPrepRunning is null)
{
if (this.issuedWriteLocks.Count == 0 && this.issuedUpgradeableReadLocks.Count == 0 && this.issuedReadLocks.Count == 0)
Expand Down Expand Up @@ -1166,20 +1167,23 @@ private bool TryIssueLock(Awaiter awaiter, bool previouslyQueued, bool skipPendi
if (issued)
{
this.GetActiveLockSet(awaiter.Kind).Add(awaiter);
this.etw.Issued(awaiter);
}
}

if (!issued)
{
this.etw.WaitStart(awaiter);

// If the lock is immediately available, we don't need to coordinate with other threads.
// But if it is NOT available, we'd have to wait potentially for other threads to do more work.
Debugger.NotifyOfCrossThreadDependency();
}
if (issued)
{
this.etw.Issued(awaiter);
}
else
{
this.etw.WaitStart(awaiter);

return issued;
// If the lock is immediately available, we don't need to coordinate with other threads.
// But if it is NOT available, we'd have to wait potentially for other threads to do more work.
Debugger.NotifyOfCrossThreadDependency();
}

return issued;
}

/// <summary>
Expand Down

0 comments on commit a31490c

Please sign in to comment.