mirror of
https://github.com/osukey/osukey.git
synced 2025-05-08 15:17:24 +09:00
Rework logic to avoid custom disposal early return handling
This commit is contained in:
parent
366f074f86
commit
10e8b7082e
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
|
||||||
@ -43,42 +42,45 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
leasedInProgress = inProgress.BeginLease(true);
|
leasedInProgress = inProgress.BeginLease(true);
|
||||||
leasedInProgress.Value = true;
|
leasedInProgress.Value = true;
|
||||||
|
|
||||||
// for extra safety, marshal the end of operation back to the update thread if necessary.
|
return new OngoingOperation(this, leasedInProgress);
|
||||||
return new OngoingOperation(() => Scheduler.Add(endOperation, false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endOperation()
|
private void endOperationWithKnownLease(LeasedBindable<bool> lease)
|
||||||
{
|
{
|
||||||
leasedInProgress?.Return();
|
if (lease != leasedInProgress)
|
||||||
leasedInProgress = null;
|
return;
|
||||||
|
|
||||||
|
// for extra safety, marshal the end of operation back to the update thread if necessary.
|
||||||
|
Scheduler.Add(() =>
|
||||||
|
{
|
||||||
|
leasedInProgress?.Return();
|
||||||
|
leasedInProgress = null;
|
||||||
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
// base call does an UnbindAllBindables().
|
// base call does an UnbindAllBindables().
|
||||||
// clean up the leased reference here so that it doesn't get returned twice.
|
// clean up the leased reference here so that it doesn't get returned twice.
|
||||||
leasedInProgress = null;
|
leasedInProgress = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class OngoingOperation : InvokeOnDisposal
|
private class OngoingOperation : IDisposable
|
||||||
{
|
{
|
||||||
private bool isDisposed;
|
private readonly OngoingOperationTracker tracker;
|
||||||
|
private readonly LeasedBindable<bool> lease;
|
||||||
|
|
||||||
public OngoingOperation(Action action)
|
public OngoingOperation(OngoingOperationTracker tracker, LeasedBindable<bool> lease)
|
||||||
: base(action)
|
|
||||||
{
|
{
|
||||||
|
this.tracker = tracker;
|
||||||
|
this.lease = lease;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
// base class does not check disposal state for performance reasons which aren't relevant here.
|
tracker.endOperationWithKnownLease(lease);
|
||||||
// track locally, to avoid interfering with other operations in case of a potential double-disposal.
|
|
||||||
if (isDisposed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
base.Dispose();
|
|
||||||
isDisposed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user