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

small perf changes #889

Merged
merged 2 commits into from
Feb 2, 2021
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 @@ -720,8 +720,14 @@ public override string ServerVersion
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/ServerProcessId/*' />
public int ServerProcessId
{
get => State.Equals(ConnectionState.Open) | State.Equals(ConnectionState.Executing) | State.Equals(ConnectionState.Fetching) ?
GetOpenTdsConnection().ServerProcessId : 0;
get
{
if ((State & (ConnectionState.Open | ConnectionState.Executing | ConnectionState.Fetching)) > 0)
{
return GetOpenTdsConnection().ServerProcessId;
}
return 0;
}
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/State/*' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,8 @@ public static MethodInfo GetPromotedToken
/// </summary>
internal class ConcurrentQueueSemaphore
{
private static readonly Action<Task, object> s_continuePop = ContinuePop;

private readonly SemaphoreSlim _semaphore;
private readonly ConcurrentQueue<TaskCompletionSource<bool>> _queue =
new ConcurrentQueue<TaskCompletionSource<bool>>();
Expand All @@ -2152,18 +2154,27 @@ public Task WaitAsync(CancellationToken cancellationToken)
{
var tcs = new TaskCompletionSource<bool>();
_queue.Enqueue(tcs);
_semaphore.WaitAsync().ContinueWith(t =>
{
if (_queue.TryDequeue(out TaskCompletionSource<bool> popped))
popped.SetResult(true);
}, cancellationToken);
_semaphore.WaitAsync().ContinueWith(
continuationAction: s_continuePop,
state: _queue,
cancellationToken: cancellationToken
);
return tcs.Task;
}

public void Release()
{
_semaphore.Release();
}

private static void ContinuePop(Task task, object state)
{
ConcurrentQueue<TaskCompletionSource<bool>> queue = (ConcurrentQueue<TaskCompletionSource<bool>>)state;
if (queue.TryDequeue(out TaskCompletionSource<bool> popped))
{
popped.SetResult(true);
}
}
}

}//namespace