Skip to content

Commit 824c638

Browse files
author
Oren (electricessence)
committed
Refresh.
1 parent a4ebb00 commit 824c638

File tree

7 files changed

+48
-64
lines changed

7 files changed

+48
-64
lines changed

AsyncProcess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public virtual T Progress
139139

140140

141141

142-
protected override void OnDispose(bool calledExplicitly)
142+
protected override void OnDispose()
143143
{
144144
SyncLock.Dispose();
145145
Scheduler = null;

AsyncQuery.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ public TResult GetLatestOrRunning(out DateTime completed)
252252

253253

254254

255-
protected override void OnDispose(bool calledExplicitly)
255+
protected override void OnDispose()
256256
{
257-
base.OnDispose(calledExplicitly);
257+
base.OnDispose();
258258
_latest = default;
259259
Closure = null;
260260
}

Container.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,8 @@ public interface IContainValue<out T>
4040
/// <typeparam name="T">The type to be contained.</typeparam>
4141
[SuppressMessage("ReSharper", "UnusedMemberInSuper.Global")]
4242
// ReSharper disable once InheritdocConsiderUsage
43-
public interface IContainer<T> : IContainValue<T>, IDisposable // To ensure manual cleanup is implmented.
43+
public interface IContainer<T> : IContainValue<T>, IDisposable, IDisposalState // To ensure manual cleanup is implmented.
4444
{
45-
/// <summary>
46-
/// Returns true if already disposed.
47-
/// </summary>
48-
bool IsDisposed { get; }
49-
5045
/// <summary>
5146
/// Initalizes or updates the contained source.
5247
/// </summary>
@@ -110,12 +105,12 @@ public T GetValue()
110105
/// <inheritdoc />
111106
public bool SetValue(T value)
112107
{
113-
AssertIsAlive();
108+
this.AssertIsAlive();
114109
var init = false;
115110

116111
var original = SyncLock.WriteValue(() =>
117112
{
118-
AssertIsAlive();
113+
this.AssertIsAlive();
119114

120115
var o = _value;
121116
_value = value;
@@ -194,7 +189,7 @@ public T GetOrUpdate(Func<T> valueFactory)
194189
{
195190
SyncLock.ReadWriteConditional((locked) =>
196191
{
197-
AssertIsAlive();
192+
this.AssertIsAlive();
198193
result = _value;
199194
return !HasValue;
200195
}, () =>
@@ -206,7 +201,7 @@ public T GetOrUpdate(Func<T> valueFactory)
206201

207202
protected void SetHasValue(bool value)
208203
{
209-
AssertIsAlive();
204+
this.AssertIsAlive();
210205

211206
HasValue = value;
212207
}
@@ -223,7 +218,7 @@ protected virtual void OnReset()
223218
}
224219

225220

226-
protected override void OnDispose(bool calledExplicitly)
221+
protected override void OnDispose()
227222
{
228223

229224
}
@@ -276,9 +271,9 @@ protected override T Eval()
276271
return SyncLock.ReadValue(_valueFactory ?? base.Eval);
277272
}
278273

279-
protected override void OnDispose(bool calledExplicitly)
274+
protected override void OnDispose()
280275
{
281-
base.OnDispose(calledExplicitly);
276+
base.OnDispose();
282277
_valueFactory = null;
283278
}
284279
}

ModificationSynchronizedBase.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public IModificationSynchronizer Sync
1818
get
1919
{
2020
var s = _sync;
21-
AssertIsAlive();
21+
this.AssertIsAlive();
2222
return s;
2323
}
2424
}
@@ -70,7 +70,7 @@ void SetSyncSynced(IModificationSynchronizer value)
7070
{
7171
var owned = false;
7272
// Allow for wrap-up.
73-
if (!sync.IsDisposed) sync.Modifying(() =>
73+
if (!sync.WasDisposed) sync.Modifying(() =>
7474
{
7575
owned = _syncOwned;
7676
SetSync(value);
@@ -85,20 +85,9 @@ void SetSyncSynced(IModificationSynchronizer value)
8585
}
8686
}
8787

88-
protected override void OnDispose(bool calledExplicitly)
88+
protected override void OnDispose()
8989
{
90-
if (calledExplicitly)
91-
SetSyncSynced(null);
92-
else
93-
{
94-
// var owned = _syncOwned;
95-
// var sync = _sync as IDisposable;
96-
SetSync(null);
97-
// if(sync!=null)
98-
// {
99-
// sync.Dispose();
100-
// }
101-
}
90+
SetSyncSynced(null);
10291
}
10392

10493
protected void OnModified(object source, EventArgs e)

ModificationSynchronizer.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ protected override void OnBeforeDispose()
9696
Modified = null; // Clean events before swap.
9797
}
9898

99-
protected override void OnDispose(bool calledExplicitly)
99+
protected override void OnDispose()
100100
{
101101
Modified = null; // Just in case.
102102
}
103103

104104

105105
public virtual void Reading(Action action)
106106
{
107-
AssertIsAlive();
107+
this.AssertIsAlive();
108108
action();
109109
}
110110

111111
public virtual T Reading<T>(Func<T> action)
112112
{
113-
AssertIsAlive();
113+
this.AssertIsAlive();
114114
return action();
115115
}
116116

@@ -136,7 +136,7 @@ public bool Modifying(Action action, bool assumeChange = false)
136136

137137
public virtual bool Modifying(Func<bool> condition, Func<bool> action)
138138
{
139-
AssertIsAlive();
139+
this.AssertIsAlive();
140140
if (condition != null && !condition())
141141
return false;
142142

@@ -152,7 +152,7 @@ public virtual bool Modifying(Func<bool> condition, Func<bool> action)
152152

153153
public virtual bool Modifying<T>(ref T target, T newValue)
154154
{
155-
AssertIsAlive();
155+
this.AssertIsAlive();
156156
if (target.Equals(newValue)) return false;
157157

158158
IncrementVersion();
@@ -177,13 +177,13 @@ public SimpleLockingModificationSynchronizer(object sync = null)
177177

178178
public override void Reading(Action action)
179179
{
180-
AssertIsAlive();
180+
this.AssertIsAlive();
181181
lock (_sync) action();
182182
}
183183

184184
public override T Reading<T>(Func<T> action)
185185
{
186-
AssertIsAlive();
186+
this.AssertIsAlive();
187187
lock (_sync) return action();
188188
}
189189

@@ -192,7 +192,7 @@ public override bool Modifying(Func<bool> condition, Func<bool> action)
192192
var modified = false;
193193
ThreadSafety.LockConditional(
194194
_sync,
195-
() => AssertIsAlive() && (condition == null || condition()),
195+
() => this.AssertIsAlive() && (condition == null || condition()),
196196
() => { modified = base.Modifying(null, action); }
197197
);
198198
return modified;
@@ -201,7 +201,7 @@ public override bool Modifying(Func<bool> condition, Func<bool> action)
201201

202202
public override bool Modifying<T>(ref T target, T newValue)
203203
{
204-
AssertIsAlive();
204+
this.AssertIsAlive();
205205
if (target.Equals(newValue)) return false;
206206

207207
lock (_sync) return base.Modifying(ref target, newValue);
@@ -226,11 +226,11 @@ IDisposable Cleanup()
226226
return Interlocked.Exchange(ref _sync, null);
227227
}
228228

229-
protected override void OnDispose(bool calledExplicitly)
229+
protected override void OnDispose()
230230
{
231-
base.OnDispose(calledExplicitly);
231+
base.OnDispose();
232232
IDisposable s = null;
233-
if (!calledExplicitly || !_sync.Write(() => s = Cleanup(), 10 /* Give any cleanup a chance. */ ))
233+
if (!_sync.Write(() => s = Cleanup(), 10 /* Give any cleanup a chance. */ ))
234234
{
235235
s = Cleanup();
236236
}
@@ -243,19 +243,19 @@ protected override void OnDispose(bool calledExplicitly)
243243

244244
public override void Reading(Action action)
245245
{
246-
AssertIsAlive();
246+
this.AssertIsAlive();
247247
_sync.Read(action);
248248
}
249249

250250
public override T Reading<T>(Func<T> action)
251251
{
252-
AssertIsAlive();
252+
this.AssertIsAlive();
253253
return _sync.ReadValue(action);
254254
}
255255

256256
public override bool Modifying(Func<bool> condition, Func<bool> action)
257257
{
258-
AssertIsAlive();
258+
this.AssertIsAlive();
259259

260260
// Try and early invalidate.
261261
if (condition != null && !_sync.ReadValue(condition))
@@ -264,7 +264,7 @@ public override bool Modifying(Func<bool> condition, Func<bool> action)
264264
var modified = false;
265265
_sync.ReadUpgradeable(() =>
266266
{
267-
AssertIsAlive();
267+
this.AssertIsAlive();
268268
if (condition == null || condition())
269269
{
270270
modified = _sync.WriteValue(() => base.Modifying(null, action));
@@ -276,15 +276,15 @@ public override bool Modifying(Func<bool> condition, Func<bool> action)
276276

277277
public override bool Modifying<T>(ref T target, T newValue)
278278
{
279-
AssertIsAlive();
279+
this.AssertIsAlive();
280280
if (target.Equals(newValue)) return false;
281281

282282
bool changed;
283283
try
284284
{
285285
// Note, there's no need for _modifyingDepth recursion tracking here.
286286
_sync.EnterUpgradeableReadLock();
287-
AssertIsAlive();
287+
this.AssertIsAlive();
288288

289289
//var ver = _version; // Capture the version so that if changes occur indirectly...
290290
changed = !target.Equals(newValue);

Open.Threading.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
55
<Authors>electricessence</Authors>
66
<Company />
77
<Product />
88
<Description>Useful set of extensions and classes for simplifying and optimizing thread safe operations and synchronization.
99

1010
Part of the "Open" set of libraries.</Description>
11-
<PackageLicenseUrl>https://github.com/electricessence/Open.Threading/blob/master/LISCENSE.md</PackageLicenseUrl>
11+
<PackageLicenseUrl></PackageLicenseUrl>
1212
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
13-
<Version>1.4.2</Version>
14-
<AssemblyVersion>1.4.2.0</AssemblyVersion>
15-
<FileVersion>1.4.2.0</FileVersion>
13+
<Version>1.5.1</Version>
14+
<AssemblyVersion>1.5.1.0</AssemblyVersion>
15+
<FileVersion>1.5.1.0</FileVersion>
1616
<Copyright>https://github.com/electricessence/Open.Threading/blob/master/LISCENSE.md</Copyright>
1717
<PackageProjectUrl>https://github.com/electricessence/Open.Threading/</PackageProjectUrl>
1818
<RepositoryUrl>https://github.com/electricessence/Open.Threading/</RepositoryUrl>
1919
<RepositoryType>git</RepositoryType>
2020
<PackageTags>dotnet, dotnet-core, dotnetcore, cs, collections, extensions, threadsafe, thread-safe, readwrite, read-write, readerwriterlock, readerwriterlockslim</PackageTags>
2121
<PackageReleaseNotes></PackageReleaseNotes>
22+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2223
</PropertyGroup>
2324

2425
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@@ -41,8 +42,7 @@ Part of the "Open" set of libraries.</Description>
4142
</ItemGroup>
4243

4344
<ItemGroup>
44-
<PackageReference Include="Open.Diagnostics" Version="1.3.0" />
45-
<PackageReference Include="Open.Threading.ReadWrite" Version="1.1.2" />
45+
<PackageReference Include="Open.Threading.ReadWrite" Version="1.3.0" />
4646
</ItemGroup>
4747

4848
</Project>

SemaphoreSlimExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Open.Diagnostics;
2-
using System;
1+
using System;
2+
using System.Diagnostics;
33
using System.Diagnostics.Contracts;
44
using System.Threading;
55
using System.Threading.Tasks;
@@ -35,7 +35,7 @@ public static void Execute(this Semaphore target, Action closure)
3535
}
3636
catch (SemaphoreFullException sfex)
3737
{
38-
sfex.WriteToDebug();
38+
Debug.WriteLine(sfex.ToString());
3939
}
4040
}
4141
}
@@ -66,7 +66,7 @@ public static void Execute(this SemaphoreSlim target, Action closure)
6666
}
6767
catch (SemaphoreFullException sfex)
6868
{
69-
sfex.WriteToDebug();
69+
Debug.WriteLine(sfex.ToString());
7070
}
7171
}
7272
}
@@ -99,7 +99,7 @@ public static T Execute<T>(this Semaphore target, Func<T> closure)
9999
}
100100
catch (SemaphoreFullException sfex)
101101
{
102-
sfex.WriteToDebug();
102+
Debug.WriteLine(sfex.ToString());
103103
}
104104
}
105105
}
@@ -132,7 +132,7 @@ public static T Execute<T>(this SemaphoreSlim target, Func<T> closure)
132132
}
133133
catch (SemaphoreFullException sfex)
134134
{
135-
sfex.WriteToDebug();
135+
Debug.WriteLine(sfex.ToString());
136136
}
137137
}
138138
}
@@ -165,7 +165,7 @@ public static async Task<T> ExecuteAsync<T>(this SemaphoreSlim target, Func<T> c
165165
}
166166
catch (SemaphoreFullException sfex)
167167
{
168-
sfex.WriteToDebug();
168+
Debug.WriteLine(sfex.ToString());
169169
}
170170
}
171171
}
@@ -198,7 +198,7 @@ public static async Task<T> ExecuteAsync<T>(this SemaphoreSlim target, Task<T> t
198198
}
199199
catch (SemaphoreFullException sfex)
200200
{
201-
sfex.WriteToDebug();
201+
Debug.WriteLine(sfex.ToString());
202202
}
203203
}
204204
}

0 commit comments

Comments
 (0)