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

Don't capture synchronization context in DiskWriterQueue #2447

Merged
Merged
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
26 changes: 12 additions & 14 deletions LiteDB/Engine/Disk/DiskWriterQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public void EnqueuePage(PageBuffer page)
// throw last exception that stop running queue
if (_exception != null) throw _exception;

_queueIsEmpty.Reset();
_queue.Enqueue(page);
_queueHasItems.Set();

lock (_queueSync)
{
_queueIsEmpty.Reset();
_queue.Enqueue(page);
_queueHasItems.Set();

if (_task == null)
{
_task = Task.Factory.StartNew(ExecuteQueue, TaskCreationOptions.LongRunning);
Expand All @@ -76,7 +76,7 @@ public void Wait()
/// <summary>
/// Execute all items in queue sync
/// </summary>
private async Task ExecuteQueue()
private void ExecuteQueue()
{
try
{
Expand All @@ -88,19 +88,17 @@ private async Task ExecuteQueue()
}
else
{
lock (_queueSync)
{
if (_queue.Count > 0) continue;

_queueIsEmpty.Set();
_queueHasItems.Reset();
if (_queue.Count > 0) continue;

_queueIsEmpty.Set();
_queueHasItems.Reset();

if (_shouldClose) return;
}
if (_shouldClose) return;

_stream.FlushToDisk();

await _queueHasItems.WaitAsync();
_queueHasItems.WaitAsync().GetAwaiter().GetResult();
JKamsker marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -137,7 +135,7 @@ public void Dispose()
_shouldClose = true;
_queueHasItems.Set(); // unblock the running loop in case there are no items

_task?.Wait();
_task?.GetAwaiter().GetResult();
_task = null;
}
}
Expand Down