Skip to content

Commit

Permalink
Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Nov 30, 2018
1 parent 35fa439 commit 562f79a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
58 changes: 29 additions & 29 deletions src/Unosquare.Swan.Lite/Abstractions/ExclusiveTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
using System.Threading;

/// <summary>
/// A threading <see cref="BackingTimer"/> implementation that executes at most one cycle at a time
/// A threading <see cref="_backingTimer"/> implementation that executes at most one cycle at a time
/// in a <see cref="ThreadPool"/> thread. Callback execution is NOT guaranteed to be carried out
/// on the same <see cref="ThreadPool"/> thread every time the timer fires.
/// </summary>
public sealed class ExclusiveTimer
{
private readonly object SyncLock = new object();
private readonly ManualResetEventSlim CycleDoneEvent = new ManualResetEventSlim(true);
private readonly Timer BackingTimer;
private readonly TimerCallback UserCallback;
private readonly AtomicBoolean m_IsDisposing = new AtomicBoolean();
private readonly AtomicBoolean m_IsDisposed = new AtomicBoolean();
private readonly object _syncLock = new object();
private readonly ManualResetEventSlim _cycleDoneEvent = new ManualResetEventSlim(true);
private readonly Timer _backingTimer;
private readonly TimerCallback _userCallback;
private readonly AtomicBoolean _isDisposing = new AtomicBoolean();
private readonly AtomicBoolean _isDisposed = new AtomicBoolean();

/// <summary>
/// Initializes a new instance of the <see cref="ExclusiveTimer"/> class.
Expand All @@ -26,8 +26,8 @@ public sealed class ExclusiveTimer
/// <param name="period">The period.</param>
public ExclusiveTimer(TimerCallback timerCallback, object state, int dueTime, int period)
{
UserCallback = timerCallback;
BackingTimer = new Timer(InternalCallback, state ?? this, dueTime, period);
_userCallback = timerCallback;
_backingTimer = new Timer(InternalCallback, state ?? this, dueTime, period);
}

/// <summary>
Expand All @@ -38,7 +38,7 @@ public ExclusiveTimer(TimerCallback timerCallback, object state, int dueTime, in
/// <param name="dueTime">The due time.</param>
/// <param name="period">The period.</param>
public ExclusiveTimer(TimerCallback timerCallback, object state, TimeSpan dueTime, TimeSpan period)
: this(timerCallback, state, Convert.ToInt32(dueTime.TotalMilliseconds), Convert.ToInt32(dueTime.TotalMilliseconds))
: this(timerCallback, state, Convert.ToInt32(dueTime.TotalMilliseconds), Convert.ToInt32(period.TotalMilliseconds))
{
// placeholder
}
Expand All @@ -60,7 +60,7 @@ public ExclusiveTimer(TimerCallback timerCallback)
/// <param name="dueTime">The due time.</param>
/// <param name="period">The period.</param>
public ExclusiveTimer(Action timerCallback, int dueTime, int period)
: this(new TimerCallback((object s) => { timerCallback?.Invoke(); }), null, dueTime, period)
: this(s => { timerCallback?.Invoke(); }, null, dueTime, period)
{
// placeholder
}
Expand All @@ -72,7 +72,7 @@ public ExclusiveTimer(Action timerCallback, int dueTime, int period)
/// <param name="dueTime">The due time.</param>
/// <param name="period">The period.</param>
public ExclusiveTimer(Action timerCallback, TimeSpan dueTime, TimeSpan period)
: this(new TimerCallback((object s) => { timerCallback?.Invoke(); }), null, dueTime, period)
: this(s => { timerCallback?.Invoke(); }, null, dueTime, period)
{
// placeholder
}
Expand All @@ -93,29 +93,29 @@ public ExclusiveTimer(Action timerCallback)
/// <value>
/// <c>true</c> if this instance is disposing; otherwise, <c>false</c>.
/// </value>
public bool IsDisposing => m_IsDisposing.Value;
public bool IsDisposing => _isDisposing.Value;

/// <summary>
/// Gets a value indicating whether this instance is disposed.
/// </summary>
/// <value>
/// <c>true</c> if this instance is disposed; otherwise, <c>false</c>.
/// </value>
public bool IsDisposed => m_IsDisposed.Value;
public bool IsDisposed => _isDisposed.Value;

/// <summary>
/// Changes the start time and the interval between method invocations for the internal timer.
/// </summary>
/// <param name="dueTime">The due time.</param>
/// <param name="period">The period.</param>
public void Change(int dueTime, int period) => BackingTimer.Change(dueTime, period);
public void Change(int dueTime, int period) => _backingTimer.Change(dueTime, period);

/// <summary>
/// Changes the start time and the interval between method invocations for the internal timer.
/// </summary>
/// <param name="dueTime">The due time.</param>
/// <param name="period">The period.</param>
public void Change(TimeSpan dueTime, TimeSpan period) => BackingTimer.Change(dueTime, period);
public void Change(TimeSpan dueTime, TimeSpan period) => _backingTimer.Change(dueTime, period);

/// <summary>
/// Changes the interval between method invocations for the internal timer.
Expand All @@ -139,24 +139,24 @@ public ExclusiveTimer(Action timerCallback)
/// </summary>
public void Dispose()
{
lock (SyncLock)
lock (_syncLock)
{
if (m_IsDisposed == true || m_IsDisposed == true)
if (_isDisposed == true || _isDisposed == true)
return;

m_IsDisposing.Value = true;
_isDisposing.Value = true;
}

try
{
BackingTimer.Dispose();
CycleDoneEvent.Wait();
CycleDoneEvent.Dispose();
_backingTimer.Dispose();
_cycleDoneEvent.Wait();
_cycleDoneEvent.Dispose();
}
finally
{
m_IsDisposed.Value = true;
m_IsDisposing.Value = false;
_isDisposed.Value = true;
_isDisposing.Value = false;
}
}

Expand All @@ -166,24 +166,24 @@ public void Dispose()
/// <param name="state">The state.</param>
private void InternalCallback(object state)
{
lock (SyncLock)
lock (_syncLock)
{
if (IsDisposed || IsDisposing)
return;
}

if (CycleDoneEvent.IsSet == false)
if (_cycleDoneEvent.IsSet == false)
return;

CycleDoneEvent.Reset();
_cycleDoneEvent.Reset();

try
{
UserCallback(state);
_userCallback(state);
}
finally
{
CycleDoneEvent.Set();
_cycleDoneEvent.Set();
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Unosquare.Swan.Lite/Attributes/Validators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ public class EmailAttribute : MatchAttribute
@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$";

/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:Unosquare.Swan.Attributes.EmailAttribute" /> class.
/// Initializes a new instance of the <see cref="EmailAttribute"/> class.
/// </summary>
/// <param name="errorMessage">The error message.</param>
public EmailAttribute(string errorMessage = null)
Expand Down
4 changes: 2 additions & 2 deletions test/Unosquare.Swan.Test/Unosquare.Swan.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.3.1">
<PackageReference Include="coverlet.msbuild" Version="2.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<packagereference Include="NUnit3TestAdapter" Version="3.11.0"></packagereference>
<packagereference Include="NUnit3TestAdapter" Version="3.11.2"></packagereference>
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta008">
<PrivateAssets>All</PrivateAssets>
Expand Down

0 comments on commit 562f79a

Please sign in to comment.