daily update on 20240325 by nitload youmu

This commit is contained in:
YoumuLiu
2024-03-25 09:26:53 +08:00
parent 9a10ec201c
commit 02be081eee
142 changed files with 11277 additions and 572 deletions
@@ -43,6 +43,9 @@ namespace StgSharpDebug.Logic
private SemaphoreSlim _addSubscriberSemaphore = new SemaphoreSlim(1, 1);
protected SemaphoreSlim CheckSubscriberSemaphore
=> _addSubscriberSemaphore;
public void AddSubscriber(TimeSpanProvider subscriber)
{
_addSubscriberSemaphore.Wait();
@@ -79,11 +82,6 @@ namespace StgSharpDebug.Logic
public abstract void StartProvidingTime();
protected SemaphoreSlim CheckSubscriberSemaphore
{
get => _addSubscriberSemaphore;
}
protected abstract void AddSubscriberUnsynced(TimeSpanProvider subscriber);
protected abstract void RemoveSubscriberUnsynced(TimeSpanProvider subscriber);
+25 -18
View File
@@ -38,19 +38,22 @@ namespace StgSharp
{
public delegate void TimeSpanRefeshCallback();
/// <summary>
/// A microsecond-accuracy timer. It will refresh every a certain time span.
/// </summary>
public class TimeSpanProvider
{
private Action<SemaphoreFullException> _frameUpdateMissCallback = null;
private readonly int _maxSpanCount;
private TimeSpanRefeshCallback _refeshCallback;
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(0, 1);
private long _spanBegin;
private readonly long _spanLength;
private bool _subscribed;
private Counter<int> timeSpanCount = new Counter<int>(-1, 1, 1);
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(0,1);
/// <summary>
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
@@ -60,6 +63,7 @@ namespace StgSharp
public TimeSpanProvider(long spanLength, TimeSourceProviderBase provider)
{
_spanLength = spanLength;
_maxSpanCount = int.MaxValue;
provider.AddSubscriber(this);
_subscribed = true;
}
@@ -72,7 +76,9 @@ namespace StgSharp
/// <parma name="provider"></parma>
public TimeSpanProvider(double spanLength, TimeSourceProviderBase provider)
{
_spanLength = ((int)spanLength) * 1000L * 1000L; _spanBegin = -_spanLength;
_spanLength = (long)(spanLength * 1000L * 1000L);
_spanBegin = -_spanLength;
_maxSpanCount = int.MaxValue;
provider.AddSubscriber(this);
_subscribed = true;
}
@@ -86,18 +92,28 @@ namespace StgSharp
{
if (maxSpan <= 0)
{
maxSpan = int.MaxValue;
maxSpan = int.MaxValue;
}
_spanLength = spanLength; _spanBegin = -_spanLength;
provider.AddSubscriber(this);
_subscribed = true;
}
public int CurrentSpan
{
get => timeSpanCount.Value;
}
/// <summary>
/// Time source provider provided in <see cref="StgSharp"/> internal framework.
/// </summary>
public static TimeSourceProviderBase DefaultProvider => StgSharpTime.OnlyInstance;
public Action<SemaphoreFullException> FrameUpdateMissCallback
{
get => _frameUpdateMissCallback;
set => _frameUpdateMissCallback = value;
}
/// <summary>
/// The method this <see cref="TimeSpanProvider"/> will call every time a new time span started.
/// </summary>
@@ -107,7 +123,6 @@ namespace StgSharp
set => _refeshCallback = value;
}
public void SubcsribeToTimeSource(TimeSourceProviderBase serviceHandler)
{
if (_subscribed)
@@ -118,6 +133,11 @@ namespace StgSharp
serviceHandler.AddSubscriber(this);
}
public void WaitNextSpan()
{
_refreshSemaphore.Wait();
}
internal bool CheckTime(long microseconds)
{
if (microseconds - _spanBegin > _spanLength)
@@ -128,7 +148,7 @@ namespace StgSharp
{
_refreshSemaphore.Release();
}
catch(SemaphoreFullException ex)
catch (SemaphoreFullException ex)
{
if (_frameUpdateMissCallback != null)
{
@@ -143,19 +163,6 @@ namespace StgSharp
return true;
}
private Action<SemaphoreFullException> _frameUpdateMissCallback = null;
public Action<SemaphoreFullException> FrameUpdateMissCallback
{
get { return _frameUpdateMissCallback; }
set { _frameUpdateMissCallback = value;}
}
public void WaitNextSpan()
{
_refreshSemaphore.Wait();
}
public static implicit operator int(TimeSpanProvider provider)
{
return provider.timeSpanCount.Value;