Skip to content

Commit

Permalink
Get rid of OperationData
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzhulart committed Jan 23, 2017
1 parent 7fe45c4 commit 0854104
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions Mono.Debugging/Mono.Debugging.Evaluation/AsyncOperationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,7 @@ namespace Mono.Debugging.Evaluation
{
public class AsyncOperationManager : IDisposable
{
class OperationData
{
public IAsyncOperationBase Operation { get; private set; }
public OperationData (IAsyncOperationBase operation)
{
Operation = operation;
}
}

readonly HashSet<OperationData> currentOperations = new HashSet<OperationData> ();
readonly HashSet<IAsyncOperationBase> currentOperations = new HashSet<IAsyncOperationBase> ();
bool disposed = false;
const int ShortCancelTimeout = 100;

Expand All @@ -70,13 +61,12 @@ public OperationResult<TValue> Invoke<TValue> (AsyncOperationBase<TValue> mc, in

Task<OperationResult<TValue>> task;
var description = mc.Description;
var operationData = new OperationData (mc);
lock (currentOperations) {
if (disposed)
throw new ObjectDisposedException ("Already disposed");
DebuggerLoggingService.LogMessage (string.Format("Starting invoke for {0}", description));
task = mc.InvokeAsync ();
currentOperations.Add (operationData);
currentOperations.Add (mc);
}

bool cancelledAfterTimeout = false;
Expand Down Expand Up @@ -111,7 +101,7 @@ public OperationResult<TValue> Invoke<TValue> (AsyncOperationBase<TValue> mc, in
}
finally {
lock (currentOperations) {
currentOperations.Remove (operationData);
currentOperations.Remove (mc);
}
}
}
Expand Down Expand Up @@ -151,7 +141,7 @@ void WaitAfterCancel (IAsyncOperationBase op)
public void AbortAll ()
{
DebuggerLoggingService.LogMessage ("Aborting all the current invocations");
List<OperationData> copy;
List<IAsyncOperationBase> copy;
lock (currentOperations) {
if (disposed) throw new ObjectDisposedException ("Already disposed");
copy = currentOperations.ToList ();
Expand All @@ -161,14 +151,14 @@ public void AbortAll ()
CancelOperations (copy, true);
}

void CancelOperations (List<OperationData> operations, bool wait)
void CancelOperations (List<IAsyncOperationBase> operations, bool wait)
{
foreach (var operationData in operations) {
var taskDescription = operationData.Operation.Description;
foreach (var operation in operations) {
var taskDescription = operation.Description;
try {
operationData.Operation.Abort ();
operation.Abort ();
if (wait) {
WaitAfterCancel (operationData.Operation);
WaitAfterCancel (operation);
}
}
catch (Exception e) {
Expand All @@ -185,7 +175,7 @@ void CancelOperations (List<OperationData> operations, bool wait)

public void Dispose ()
{
List<OperationData> copy;
List<IAsyncOperationBase> copy;
lock (currentOperations) {
if (disposed) throw new ObjectDisposedException ("Already disposed");
disposed = true;
Expand Down

0 comments on commit 0854104

Please sign in to comment.