This repository has been archived by the owner on Feb 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca6c90c
commit cfacef5
Showing
17 changed files
with
279 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using StackInjector.Wrappers; | ||
|
||
namespace StackInjector.Core | ||
{ | ||
internal abstract partial class AsyncStackWrapperCore<T> : AsyncStackWrapperCore, IAsyncStackWrapperCore<T> | ||
{ | ||
|
||
// used to cancel everything | ||
protected internal readonly CancellationTokenSource cancelPendingTasksSource = new CancellationTokenSource(); | ||
|
||
// exposes the token | ||
public CancellationToken PendingTasksCancellationToken | ||
=> this.cancelPendingTasksSource.Token; | ||
|
||
// used to lock access to tasks | ||
protected internal readonly object listAccessLock = new object(); | ||
|
||
// asyncronously waited for new events if TaskList is empty | ||
protected internal readonly SemaphoreSlim emptyListAwaiter = new SemaphoreSlim(0); | ||
|
||
// pending tasks | ||
protected internal LinkedList<Task<T>> tasks = new LinkedList<Task<T>>(); | ||
|
||
|
||
internal AsyncStackWrapperCore ( WrapperCore core, Type toRegister ) : base(core, toRegister) | ||
{ | ||
// register an event that in case the list is empty, release the empty event listener. | ||
this.cancelPendingTasksSource.Token.Register(this.ReleaseListAwaiter); | ||
} | ||
|
||
|
||
|
||
#region IDisposable Support | ||
|
||
private bool disposedValue = false; | ||
|
||
public override void Dispose () | ||
{ | ||
if( !this.disposedValue ) | ||
{ | ||
|
||
// managed resources | ||
this.cancelPendingTasksSource.Cancel(); | ||
this.ReleaseListAwaiter(); // in case it's waiting on the empty list | ||
|
||
this.cancelPendingTasksSource.Dispose(); | ||
this.emptyListAwaiter.Dispose(); | ||
|
||
|
||
// big objects | ||
this.tasks.Clear(); | ||
this.tasks = null; | ||
|
||
// clean instantiated objects | ||
this.Core.RemoveInstancesDiff(); | ||
|
||
|
||
this.disposedValue = true; | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.