mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-03 23:30:46 +00:00
Bug 1808294 - Introduce explicit method for releasing directory locks; r=dom-storage-reviewers,jari
The method name can't be Release because that's already used for ref-counting. The next best alternative seems to be Drop. The explicit Drop method is needed to make it later possible to release directory locks asynchronously and also to make it more obvious when directory locks are released which is not that clear now when directory locks are released when the last strong reference is removed. Differential Revision: https://phabricator.services.mozilla.com/D197292
This commit is contained in:
parent
8dfaa4635f
commit
ae78313d1d
@ -36,12 +36,16 @@ class NS_NO_VTABLE DirectoryLock {
|
||||
|
||||
virtual nsTArray<RefPtr<DirectoryLock>> LocksMustWaitFor() const = 0;
|
||||
|
||||
virtual bool Dropped() const = 0;
|
||||
|
||||
virtual RefPtr<BoolPromise> Acquire() = 0;
|
||||
|
||||
virtual void AcquireImmediately() = 0;
|
||||
|
||||
virtual void AssertIsAcquiredExclusively() = 0;
|
||||
|
||||
virtual void Drop() = 0;
|
||||
|
||||
virtual void OnInvalidate(std::function<void()>&& aCallback) = 0;
|
||||
|
||||
virtual void Log() const = 0;
|
||||
|
@ -54,10 +54,9 @@ DirectoryLockImpl::DirectoryLockImpl(
|
||||
|
||||
DirectoryLockImpl::~DirectoryLockImpl() {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT_IF(!mRegistered, mBlocking.IsEmpty());
|
||||
|
||||
if (mRegistered) {
|
||||
Unregister();
|
||||
if (!mDropped) {
|
||||
Drop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,6 +124,8 @@ void DirectoryLockImpl::NotifyOpenListener() {
|
||||
mPending.Flip();
|
||||
|
||||
if (mInvalidated) {
|
||||
mDropped.Flip();
|
||||
|
||||
Unregister();
|
||||
}
|
||||
}
|
||||
@ -287,6 +288,17 @@ void DirectoryLockImpl::AssertIsAcquiredExclusively() {
|
||||
}
|
||||
#endif
|
||||
|
||||
void DirectoryLockImpl::Drop() {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT_IF(!mRegistered, mBlocking.IsEmpty());
|
||||
|
||||
mDropped.Flip();
|
||||
|
||||
if (mRegistered) {
|
||||
Unregister();
|
||||
}
|
||||
}
|
||||
|
||||
void DirectoryLockImpl::OnInvalidate(std::function<void()>&& aCallback) {
|
||||
mInvalidateCallback = std::move(aCallback);
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
|
||||
FlippedOnce<true> mPending;
|
||||
FlippedOnce<false> mInvalidated;
|
||||
FlippedOnce<false> mAcquired;
|
||||
FlippedOnce<false> mDropped;
|
||||
|
||||
public:
|
||||
DirectoryLockImpl(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
@ -185,6 +186,8 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
|
||||
|
||||
nsTArray<RefPtr<DirectoryLock>> LocksMustWaitFor() const override;
|
||||
|
||||
bool Dropped() const override { return mDropped; }
|
||||
|
||||
RefPtr<BoolPromise> Acquire() override;
|
||||
|
||||
void AcquireImmediately() override;
|
||||
@ -197,6 +200,8 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
|
||||
}
|
||||
#endif
|
||||
|
||||
void Drop() override;
|
||||
|
||||
void OnInvalidate(std::function<void()>&& aCallback) override;
|
||||
|
||||
void Log() const override;
|
||||
|
@ -287,7 +287,8 @@ class QuotaManager final : public BackgroundThreadObject {
|
||||
// reference in order to keep the lock alive.
|
||||
// Unlocking is simply done by dropping all references to the lock object.
|
||||
// In other words, protection which the lock represents dies with the lock
|
||||
// object itself.
|
||||
// object itself (Note that it's now possible to release directory locks
|
||||
// sooner by calling newly added Drop method).
|
||||
RefPtr<ClientDirectoryLockPromise> OpenClientDirectory(
|
||||
const ClientMetadata& aClientMetadata,
|
||||
Maybe<RefPtr<ClientDirectoryLock>&> aPendingDirectoryLockOut = Nothing());
|
||||
|
Loading…
x
Reference in New Issue
Block a user