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

perf: Strongly type lock token to avoid boxing #377

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
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
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