long candy ready to test
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
using Inspectron.Fastbuffer.Interfaces;
|
||||
using System.Collections.Concurrent;
|
||||
using OpenCvSharp;
|
||||
using Serilog;
|
||||
|
||||
namespace Inspectron.Fastbuffer.Filesystems;
|
||||
|
||||
public class AsyncFilesystem : IFilesystem
|
||||
{
|
||||
private readonly DirectFilesystem _directFilesystem = new();
|
||||
private readonly ConcurrentDictionary<string, byte[]> _buffer = new();
|
||||
private readonly BlockingCollection<(string path, byte[] data)> _writeQueue = new();
|
||||
private readonly List<string> _buffer = new();
|
||||
private readonly BlockingCollection<(string path, Mat data)> _writeQueue = new();
|
||||
private readonly Thread _backgroundThread;
|
||||
private readonly object _lock = new();
|
||||
|
||||
@@ -18,27 +20,17 @@ public class AsyncFilesystem : IFilesystem
|
||||
_backgroundThread.Start();
|
||||
}
|
||||
|
||||
public void Write(string path, byte[] data)
|
||||
public void Write(string path, Mat data)
|
||||
{
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_buffer[path] = data;
|
||||
_buffer.Add(path);
|
||||
_writeQueue.Add((path, data));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] Read(string path)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_buffer.TryGetValue(path, out var data))
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return _directFilesystem.Read(path);
|
||||
}
|
||||
|
||||
public void Delete(string path)
|
||||
{
|
||||
@@ -46,8 +38,9 @@ public class AsyncFilesystem : IFilesystem
|
||||
lock (_lock)
|
||||
{
|
||||
// pats is in buffer, so it's not written to disk yet
|
||||
if (_buffer.TryRemove(path, out _))
|
||||
if (_buffer.Contains(path))
|
||||
{
|
||||
_buffer.Remove(path);
|
||||
return;
|
||||
}
|
||||
_directFilesystem.Delete(path);
|
||||
@@ -61,8 +54,9 @@ public class AsyncFilesystem : IFilesystem
|
||||
{
|
||||
_directFilesystem.Write(path, data);
|
||||
lock (_lock)
|
||||
_buffer.TryRemove(path, out _);
|
||||
|
||||
_buffer.Remove(path);
|
||||
if (_writeQueue.Count > 5)
|
||||
Log.Warning($"AsyncFilesystem write queue size: {_writeQueue.Count}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user