Skip to content

Commit

Permalink
Perf | Strongly type lock token to avoid boxing (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 authored Feb 5, 2020
1 parent ce76eb0 commit 17eb766
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ virtual protected void PrepareForCloseConnection()
// By default, there is no preparation required
}

virtual protected object ObtainAdditionalLocksForClose()
virtual protected bool ObtainAdditionalLocksForClose()
{
return null; // no additional locks in default implementation
return false; // no additional locks in default implementation
}

virtual protected void ReleaseAdditionalLocksForClose(object lockToken)
virtual protected void ReleaseAdditionalLocksForClose(bool lockToken)
{
// no additional locks in default implementation
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ internal virtual void CloseConnection(DbConnection owningObject, DbConnectionFac
// Lock to prevent race condition with cancellation
lock (this)
{
object lockToken = ObtainAdditionalLocksForClose();
bool lockToken = ObtainAdditionalLocksForClose();
try
{
PrepareForCloseConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ private void AttemptOneLogin(
// PREPARED COMMAND METHODS
////////////////////////////////////////////////////////////////////////////////////////

protected override object ObtainAdditionalLocksForClose()
protected override bool ObtainAdditionalLocksForClose()
{
bool obtainParserLock = !ThreadHasParserLockForClose;
Debug.Assert(obtainParserLock || _parserLock.ThreadMayHaveLock(), "Thread claims to have lock, but lock is not taken");
Expand All @@ -1770,10 +1770,9 @@ protected override object ObtainAdditionalLocksForClose()
return obtainParserLock;
}

protected override void ReleaseAdditionalLocksForClose(object lockToken)
protected override void ReleaseAdditionalLocksForClose(bool lockToken)
{
Debug.Assert(lockToken is bool, "Lock token should be boolean");
if ((bool)lockToken)
if (lockToken)
{
ThreadHasParserLockForClose = false;
_parserLock.Release();
Expand Down

0 comments on commit 17eb766

Please sign in to comment.