back to matrix, but trouble in combining L4 predict with matrixparallelqueue
This commit is contained in:
@@ -47,12 +47,12 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
}
|
||||
|
||||
public class MatrixParallelWrap : IDisposable
|
||||
public sealed class MatrixParallelWrap : IDisposable
|
||||
{
|
||||
|
||||
private MatrixParallelThread[] _threads;
|
||||
private bool _disposed = false;
|
||||
private int _count;
|
||||
private bool _disposed;
|
||||
private readonly CountdownEvent _countdownEvent;
|
||||
|
||||
internal MatrixParallelWrap(
|
||||
MatrixParallelThread[] threadArray
|
||||
@@ -60,7 +60,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
{
|
||||
_threads = threadArray;
|
||||
IsMultithread = threadArray.Length > 1;
|
||||
_count = threadArray.Length;
|
||||
_countdownEvent = new CountdownEvent(threadArray.Length);
|
||||
}
|
||||
|
||||
public ReadOnlySpan<MatrixParallelThread> Threads
|
||||
@@ -81,11 +81,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) {
|
||||
return;
|
||||
}
|
||||
MatrixParallel.ReturnParallelResources(ref _threads);
|
||||
_disposed = true;
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -104,19 +101,30 @@ namespace StgSharp.Mathematics.Numeric
|
||||
|
||||
public void WaitAllWraps()
|
||||
{
|
||||
if (_disposed) {
|
||||
throw new ObjectDisposedException(nameof(MatrixParallelWrap));
|
||||
}
|
||||
SpinWait.SpinUntil(() => Volatile.Read(ref _count) == 0);
|
||||
ObjectDisposedException.ThrowIf(_disposed, nameof(MatrixParallelWrap));
|
||||
_countdownEvent.Wait();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void ReportThreadAccomplished()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, nameof(MatrixParallelWrap));
|
||||
_ = _countdownEvent.Signal();
|
||||
}
|
||||
|
||||
private void Dispose(
|
||||
bool disposing
|
||||
)
|
||||
{
|
||||
if (_disposed) {
|
||||
throw new ObjectDisposedException(nameof(MatrixParallelWrap));
|
||||
return;
|
||||
}
|
||||
Interlocked.Decrement(ref _count);
|
||||
if (disposing)
|
||||
{
|
||||
MatrixParallel.ReturnParallelResources(ref _threads);
|
||||
_countdownEvent.Dispose();
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user