Sync Compress and RVIO with latest from RVWorld

This commit is contained in:
Matt Nadareski
2023-04-21 15:04:31 -04:00
parent de59a91bef
commit ac718efa78
116 changed files with 5197 additions and 3669 deletions

View File

@@ -1,11 +1,12 @@
using System;
using System.Threading;
using Compress.Support.Utils;
namespace Compress.ThreadReaders
{
public class ThreadCRC : IDisposable
{
private Utils.CRC crc;
private CRC crc;
private readonly AutoResetEvent _waitEvent;
private readonly AutoResetEvent _outEvent;
private readonly Thread _tWorker;
@@ -17,7 +18,7 @@ namespace Compress.ThreadReaders
public ThreadCRC()
{
crc=new Utils.CRC();
crc=new CRC();
_waitEvent = new AutoResetEvent(false);
_outEvent = new AutoResetEvent(false);
_finished = false;
@@ -56,6 +57,13 @@ namespace Compress.ThreadReaders
_size = size;
_waitEvent.Set();
}
public void TriggerOnce(byte[] buffer, int size)
{
crc.Reset();
_buffer = buffer;
_size = size;
_waitEvent.Set();
}
public void Wait()
{

View File

@@ -4,7 +4,7 @@ using System.Threading;
namespace Compress.ThreadReaders
{
public class ThreadLoadBuffer : IDisposable
public class ThreadReadBuffer : IDisposable
{
private readonly AutoResetEvent _waitEvent;
private readonly AutoResetEvent _outEvent;
@@ -18,7 +18,7 @@ namespace Compress.ThreadReaders
public int SizeRead;
public ThreadLoadBuffer(Stream ds)
public ThreadReadBuffer(Stream ds)
{
_waitEvent = new AutoResetEvent(false);
_outEvent = new AutoResetEvent(false);

View File

@@ -0,0 +1,79 @@
using System;
using System.IO;
using System.Threading;
namespace Compress.ThreadReaders
{
public class ThreadWriteBuffer : IDisposable
{
private readonly AutoResetEvent _waitEvent;
private readonly AutoResetEvent _outEvent;
private readonly Thread _tWorker;
private byte[] _buffer;
private int _size;
private readonly Stream _ds;
private bool _finished;
public bool errorState;
public int SizeRead;
public ThreadWriteBuffer(Stream ds)
{
_waitEvent = new AutoResetEvent(false);
_outEvent = new AutoResetEvent(false);
_finished = false;
_ds = ds;
errorState = false;
_tWorker = new Thread(MainLoop);
_tWorker.Start();
}
public void Dispose()
{
_waitEvent.Close();
_outEvent.Close();
}
private void MainLoop()
{
while (true)
{
_waitEvent.WaitOne();
if (_finished)
{
break;
}
try
{
_ds.Write(_buffer, 0, _size);
}
catch (Exception)
{
errorState = true;
}
_outEvent.Set();
}
}
public void Trigger(byte[] buffer, int size)
{
_buffer = buffer;
_size = size;
_waitEvent.Set();
}
public void Wait()
{
_outEvent.WaitOne();
}
public void Finish()
{
_finished = true;
_waitEvent.Set();
_tWorker.Join();
}
}
}