Skip to content

Commit

Permalink
Exempt shaper from concurrency detector, to avoid needing reentrancy
Browse files Browse the repository at this point in the history
SingleQueryingEnumerable only for now
  • Loading branch information
roji committed Feb 11, 2021
1 parent acf38aa commit b6e407f
Showing 1 changed file with 65 additions and 51 deletions.
116 changes: 65 additions & 51 deletions src/EFCore.Relational/Query/Internal/SingleQueryingEnumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public bool MoveNext()
{
try
{
bool hasNext;
using (_relationalQueryContext.ConcurrencyDetector.EnterCriticalSection())
{
if (_dataReader == null)
Expand All @@ -156,41 +157,47 @@ public bool MoveNext()
.Execute(true, InitializeReader, null);
}

var hasNext = _resultCoordinator!.HasNext ?? _dataReader!.Read();
Current = default!;
hasNext = _resultCoordinator!.HasNext ?? _dataReader!.Read();
}

if (hasNext)
Current = default!;

if (hasNext)
{
while (true)
{
while (true)
_resultCoordinator.ResultReady = true;
_resultCoordinator.HasNext = null;
Current = _shaper(
_relationalQueryContext, _dataReader!.DbDataReader, _resultCoordinator.ResultContext,
_resultCoordinator);
if (_resultCoordinator.ResultReady)
{
// We generated a result so null out previously stored values
_resultCoordinator.ResultContext.Values = null;
break;
}

using (_relationalQueryContext.ConcurrencyDetector.EnterCriticalSection())
{
hasNext = _dataReader.Read();
}

if (!hasNext)
{
_resultCoordinator.HasNext = false;
// Enumeration has ended, materialize last element
_resultCoordinator.ResultReady = true;
_resultCoordinator.HasNext = null;
Current = _shaper(
_relationalQueryContext, _dataReader!.DbDataReader, _resultCoordinator.ResultContext,
_relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext,
_resultCoordinator);
if (_resultCoordinator.ResultReady)
{
// We generated a result so null out previously stored values
_resultCoordinator.ResultContext.Values = null;
break;
}

if (!_dataReader.Read())
{
_resultCoordinator.HasNext = false;
// Enumeration has ended, materialize last element
_resultCoordinator.ResultReady = true;
Current = _shaper(
_relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext,
_resultCoordinator);

break;
}

break;
}
}

return hasNext;
}

return hasNext;
}
catch (Exception exception)
{
Expand Down Expand Up @@ -263,6 +270,8 @@ public async ValueTask<bool> MoveNextAsync()
{
try
{
bool hasNext;

using (_relationalQueryContext.ConcurrencyDetector.EnterCriticalSection())
{
if (_dataReader == null)
Expand All @@ -272,42 +281,47 @@ await _relationalQueryContext.ExecutionStrategyFactory.Create()
.ConfigureAwait(false);
}

var hasNext = _resultCoordinator!.HasNext
hasNext = _resultCoordinator!.HasNext
?? await _dataReader!.ReadAsync(_relationalQueryContext.CancellationToken).ConfigureAwait(false);
Current = default!;
}

if (hasNext)
if (hasNext)
{
while (true)
{
while (true)
_resultCoordinator.ResultReady = true;
_resultCoordinator.HasNext = null;
Current = _shaper(
_relationalQueryContext, _dataReader!.DbDataReader, _resultCoordinator.ResultContext,
_resultCoordinator);
if (_resultCoordinator.ResultReady)
{
// We generated a result so null out previously stored values
_resultCoordinator.ResultContext.Values = null;
break;
}

using (_relationalQueryContext.ConcurrencyDetector.EnterCriticalSection())
{
hasNext = await _dataReader.ReadAsync(_relationalQueryContext.CancellationToken).ConfigureAwait(false);
}

if (!hasNext)
{
_resultCoordinator.HasNext = false;
// Enumeration has ended, materialize last element
_resultCoordinator.ResultReady = true;
_resultCoordinator.HasNext = null;
Current = _shaper(
_relationalQueryContext, _dataReader!.DbDataReader, _resultCoordinator.ResultContext,
_relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext,
_resultCoordinator);
if (_resultCoordinator.ResultReady)
{
// We generated a result so null out previously stored values
_resultCoordinator.ResultContext.Values = null;
break;
}

if (!await _dataReader.ReadAsync(_relationalQueryContext.CancellationToken).ConfigureAwait(false))
{
_resultCoordinator.HasNext = false;
// Enumeration has ended, materialize last element
_resultCoordinator.ResultReady = true;
Current = _shaper(
_relationalQueryContext, _dataReader.DbDataReader, _resultCoordinator.ResultContext,
_resultCoordinator);

break;
}

break;
}
}

return hasNext;
}

return hasNext;
}
catch (Exception exception)
{
Expand Down

0 comments on commit b6e407f

Please sign in to comment.