/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// XXX Consider moving this class template to MFBT.
// A wrapper class template on top of the RefPtr. The RefPtr provides us the // automatic reference counting of objects with AddRef() and Release() methods. // `Registered` provides automatic registration counting of objects with // Register() and Unregister() methods. Registration counting works similarly // as reference counting, but objects are not deleted when the number of // registrations drops to zero (that's managed by reference counting). Instead, // an object can trigger an asynchronous close operation which still needs to // hold and use the referenced object. Example: // // using BoolPromise = MozPromise<bool, nsresult, false>; // // class MyObject { // public: // NS_INLINE_DECL_REFCOUNTING(MyObject) // // void Register() { // mRegCnt++; // } // // void Unregister() { // mRegCnt--; // if (mRegCnt == 0) { // BeginClose(); // } // } // // private: // RefPtr<BoolPromise> BeginClose() { // return InvokeAsync(mIOTaskQueue, __func__, // []() { // return BoolPromise::CreateAndResolve(true, __func__); // }) // ->Then(GetCurrentSerialEventTarget(), __func__, // [self = RefPtr<MyObject>(this)]( // const BoolPromise::ResolveOrRejectValue&) { // return self->mIOTaskQueue->BeginShutdown(); // }) // ->Then(GetCurrentSerialEventTarget(), __func__, // [self = RefPtr<MyObject>(this)]( // const ShutdownPromise::ResolveOrRejectValue&) { // return BoolPromise::CreateAndResolve(true, __func__); // }); // } // // RefPtr<TaskQueue> mIOTaskQueue; // uint32_t mRegCnt = 0; // };
template <class T> class Registered { private:
RefPtr<T> mObject;
public:
~Registered() { if (mObject) {
mObject->Unregister();
}
}
// Spec says valid names don't include (os-dependent) path separators, // and is not equal to a dot . or two dots .. // We want to use the same validator from both child and parent. bool IsValidName(const fs::Name& aName);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.