2016-05-25 00:45:44 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-04-01 04:44:13 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#if !defined(StateMirroring_h_)
|
|
|
|
#define StateMirroring_h_
|
|
|
|
|
|
|
|
#include "mozilla/Maybe.h"
|
2015-07-16 21:52:43 +03:00
|
|
|
#include "mozilla/MozPromise.h"
|
|
|
|
#include "mozilla/StateWatching.h"
|
|
|
|
#include "mozilla/TaskDispatcher.h"
|
2015-04-01 04:44:13 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2015-04-01 04:44:13 +03:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The state-mirroring machinery allows pieces of interesting state to be
|
|
|
|
* observed on multiple thread without locking. The basic strategy is to track
|
|
|
|
* changes in a canonical value and post updates to other threads that hold
|
|
|
|
* mirrors for that value.
|
|
|
|
*
|
|
|
|
* One problem with the naive implementation of such a system is that some pieces
|
|
|
|
* of state need to be updated atomically, and certain other operations need to
|
|
|
|
* wait for these atomic updates to complete before executing. The state-mirroring
|
|
|
|
* machinery solves this problem by requiring that its owner thread uses tail
|
|
|
|
* dispatch, and posting state update events (which should always be run first by
|
|
|
|
* TaskDispatcher implementations) to that tail dispatcher. This ensures that
|
|
|
|
* state changes are always atomic from the perspective of observing threads.
|
|
|
|
*
|
2015-04-29 01:16:15 +03:00
|
|
|
* Given that state-mirroring is an automatic background process, we try to avoid
|
|
|
|
* burdening the caller with worrying too much about teardown. To that end, we
|
|
|
|
* don't assert dispatch success for any of the notifications, and assume that
|
|
|
|
* any canonical or mirror owned by a thread for whom dispatch fails will soon
|
|
|
|
* be disconnected by its holder anyway.
|
|
|
|
*
|
2015-04-01 04:44:13 +03:00
|
|
|
* Given that semantics may change and comments tend to go out of date, we
|
|
|
|
* deliberately don't provide usage examples here. Grep around to find them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
// Mirror<T> and Canonical<T> inherit WatchTarget, so we piggy-back on the
|
|
|
|
// logging that WatchTarget already does. Given that, it makes sense to share
|
|
|
|
// the same log module.
|
|
|
|
#define MIRROR_LOG(x, ...) \
|
|
|
|
MOZ_ASSERT(gStateWatchingLog); \
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gStateWatchingLog, LogLevel::Debug, (x, ##__VA_ARGS__))
|
2015-04-01 04:44:13 +03:00
|
|
|
|
|
|
|
template<typename T> class AbstractMirror;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AbstractCanonical is a superclass from which all Canonical values must
|
|
|
|
* inherit. It serves as the interface of operations which may be performed (via
|
|
|
|
* asynchronous dispatch) by other threads, in particular by the corresponding
|
|
|
|
* Mirror value.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class AbstractCanonical
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AbstractCanonical)
|
|
|
|
AbstractCanonical(AbstractThread* aThread) : mOwnerThread(aThread) {}
|
|
|
|
virtual void AddMirror(AbstractMirror<T>* aMirror) = 0;
|
|
|
|
virtual void RemoveMirror(AbstractMirror<T>* aMirror) = 0;
|
|
|
|
|
|
|
|
AbstractThread* OwnerThread() const { return mOwnerThread; }
|
|
|
|
protected:
|
|
|
|
virtual ~AbstractCanonical() {}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AbstractThread> mOwnerThread;
|
2015-04-01 04:44:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AbstractMirror is a superclass from which all Mirror values must
|
|
|
|
* inherit. It serves as the interface of operations which may be performed (via
|
|
|
|
* asynchronous dispatch) by other threads, in particular by the corresponding
|
|
|
|
* Canonical value.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class AbstractMirror
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AbstractMirror)
|
|
|
|
AbstractMirror(AbstractThread* aThread) : mOwnerThread(aThread) {}
|
|
|
|
virtual void UpdateValue(const T& aNewValue) = 0;
|
|
|
|
virtual void NotifyDisconnected() = 0;
|
|
|
|
|
|
|
|
AbstractThread* OwnerThread() const { return mOwnerThread; }
|
|
|
|
protected:
|
|
|
|
virtual ~AbstractMirror() {}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AbstractThread> mOwnerThread;
|
2015-04-01 04:44:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Canonical<T> is a wrapper class that allows a given value to be mirrored by other
|
|
|
|
* threads. It maintains a list of active mirrors, and queues updates for them
|
|
|
|
* when the internal value changes. When changing the value, the caller needs to
|
|
|
|
* pass a TaskDispatcher object, which fires the updates at the appropriate time.
|
|
|
|
* Canonical<T> is also a WatchTarget, and may be set up to trigger other routines
|
|
|
|
* (on the same thread) when the canonical value changes.
|
|
|
|
*
|
2015-04-30 04:42:46 +03:00
|
|
|
* Canonical<T> is intended to be used as a member variable, so it doesn't actually
|
|
|
|
* inherit AbstractCanonical<T> (a refcounted type). Rather, it contains an inner
|
|
|
|
* class called |Impl| that implements most of the interesting logic.
|
2015-04-01 04:44:13 +03:00
|
|
|
*/
|
|
|
|
template<typename T>
|
2015-04-30 04:42:46 +03:00
|
|
|
class Canonical
|
2015-04-01 04:44:13 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-04-30 10:21:43 +03:00
|
|
|
Canonical(AbstractThread* aThread, const T& aInitialValue, const char* aName)
|
|
|
|
{
|
|
|
|
mImpl = new Impl(aThread, aInitialValue, aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
~Canonical() {}
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
private:
|
|
|
|
class Impl : public AbstractCanonical<T>, public WatchTarget
|
2015-04-01 04:44:13 +03:00
|
|
|
{
|
2015-04-30 04:42:46 +03:00
|
|
|
public:
|
|
|
|
using AbstractCanonical<T>::OwnerThread;
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
Impl(AbstractThread* aThread, const T& aInitialValue, const char* aName)
|
|
|
|
: AbstractCanonical<T>(aThread), WatchTarget(aName), mValue(aInitialValue)
|
|
|
|
{
|
|
|
|
MIRROR_LOG("%s [%p] initialized", mName, this);
|
2015-05-14 04:47:42 +03:00
|
|
|
MOZ_ASSERT(aThread->SupportsTailDispatch(), "Can't get coherency without tail dispatch");
|
2015-04-01 04:44:13 +03:00
|
|
|
}
|
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
void AddMirror(AbstractMirror<T>* aMirror) override
|
|
|
|
{
|
|
|
|
MIRROR_LOG("%s [%p] adding mirror %p", mName, this, aMirror);
|
|
|
|
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
|
|
|
|
MOZ_ASSERT(!mMirrors.Contains(aMirror));
|
|
|
|
mMirrors.AppendElement(aMirror);
|
2015-12-01 11:52:43 +03:00
|
|
|
aMirror->OwnerThread()->DispatchStateChange(MakeNotifier(aMirror));
|
2015-04-01 04:44:13 +03:00
|
|
|
}
|
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
void RemoveMirror(AbstractMirror<T>* aMirror) override
|
|
|
|
{
|
|
|
|
MIRROR_LOG("%s [%p] removing mirror %p", mName, this, aMirror);
|
|
|
|
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
|
|
|
|
MOZ_ASSERT(mMirrors.Contains(aMirror));
|
|
|
|
mMirrors.RemoveElement(aMirror);
|
2015-04-01 04:44:13 +03:00
|
|
|
}
|
2015-04-29 02:56:07 +03:00
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
void DisconnectAll()
|
|
|
|
{
|
|
|
|
MIRROR_LOG("%s [%p] Disconnecting all mirrors", mName, this);
|
|
|
|
for (size_t i = 0; i < mMirrors.Length(); ++i) {
|
2017-06-12 22:34:10 +03:00
|
|
|
mMirrors[i]->OwnerThread()->Dispatch(
|
|
|
|
NewRunnableMethod("AbstractMirror::NotifyDisconnected",
|
|
|
|
mMirrors[i],
|
|
|
|
&AbstractMirror<T>::NotifyDisconnected),
|
|
|
|
AbstractThread::DontAssertDispatchSuccess);
|
2015-04-30 04:42:46 +03:00
|
|
|
}
|
|
|
|
mMirrors.Clear();
|
|
|
|
}
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
operator const T&()
|
2015-04-01 04:44:13 +03:00
|
|
|
{
|
2015-04-30 04:42:46 +03:00
|
|
|
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
|
|
|
|
return mValue;
|
2015-04-01 04:44:13 +03:00
|
|
|
}
|
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
void Set(const T& aNewValue)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
|
|
|
|
|
|
|
|
if (aNewValue == mValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify same-thread watchers. The state watching machinery will make sure
|
|
|
|
// that notifications run at the right time.
|
|
|
|
NotifyWatchers();
|
|
|
|
|
|
|
|
// Check if we've already got a pending update. If so we won't schedule another
|
|
|
|
// one.
|
|
|
|
bool alreadyNotifying = mInitialValue.isSome();
|
|
|
|
|
|
|
|
// Stash the initial value if needed, then update to the new value.
|
|
|
|
if (mInitialValue.isNothing()) {
|
|
|
|
mInitialValue.emplace(mValue);
|
|
|
|
}
|
|
|
|
mValue = aNewValue;
|
|
|
|
|
|
|
|
// We wait until things have stablized before sending state updates so that
|
|
|
|
// we can avoid sending multiple updates, and possibly avoid sending any
|
|
|
|
// updates at all if the value ends up where it started.
|
|
|
|
if (!alreadyNotifying) {
|
2017-06-12 22:34:10 +03:00
|
|
|
AbstractThread::DispatchDirectTask(NewRunnableMethod(
|
|
|
|
"Canonical::Impl::DoNotify", this, &Impl::DoNotify));
|
2015-04-30 04:42:46 +03:00
|
|
|
}
|
|
|
|
}
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
Impl& operator=(const T& aNewValue) { Set(aNewValue); return *this; }
|
|
|
|
Impl& operator=(const Impl& aOther) { Set(aOther); return *this; }
|
|
|
|
Impl(const Impl& aOther) = delete;
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
protected:
|
|
|
|
~Impl() { MOZ_DIAGNOSTIC_ASSERT(mMirrors.IsEmpty()); }
|
2015-04-01 04:44:13 +03:00
|
|
|
|
|
|
|
private:
|
2015-04-30 04:42:46 +03:00
|
|
|
void DoNotify()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
|
|
|
|
MOZ_ASSERT(mInitialValue.isSome());
|
|
|
|
bool same = mInitialValue.ref() == mValue;
|
|
|
|
mInitialValue.reset();
|
|
|
|
|
|
|
|
if (same) {
|
|
|
|
MIRROR_LOG("%s [%p] unchanged - not sending update", mName, this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mMirrors.Length(); ++i) {
|
2015-06-10 01:14:09 +03:00
|
|
|
mMirrors[i]->OwnerThread()->DispatchStateChange(MakeNotifier(mMirrors[i]));
|
2015-04-30 04:42:46 +03:00
|
|
|
}
|
2015-04-01 04:44:13 +03:00
|
|
|
}
|
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
already_AddRefed<nsIRunnable> MakeNotifier(AbstractMirror<T>* aMirror)
|
|
|
|
{
|
2017-06-12 22:34:10 +03:00
|
|
|
return NewRunnableMethod<T>("AbstractMirror::UpdateValue",
|
|
|
|
aMirror,
|
|
|
|
&AbstractMirror<T>::UpdateValue,
|
|
|
|
mValue);
|
|
|
|
;
|
2015-04-01 04:44:13 +03:00
|
|
|
}
|
|
|
|
|
2015-04-30 04:42:46 +03:00
|
|
|
T mValue;
|
|
|
|
Maybe<T> mInitialValue;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<AbstractMirror<T>>> mMirrors;
|
2015-04-30 04:42:46 +03:00
|
|
|
};
|
|
|
|
public:
|
|
|
|
|
|
|
|
// NB: Because mirror-initiated disconnection can race with canonical-
|
|
|
|
// initiated disconnection, a canonical should never be reinitialized.
|
|
|
|
// Forward control operations to the Impl.
|
|
|
|
void DisconnectAll() { return mImpl->DisconnectAll(); }
|
|
|
|
|
|
|
|
// Access to the Impl.
|
|
|
|
operator Impl&() { return *mImpl; }
|
|
|
|
Impl* operator&() { return mImpl; }
|
|
|
|
|
|
|
|
// Access to the T.
|
|
|
|
const T& Ref() const { return *mImpl; }
|
|
|
|
operator const T&() const { return Ref(); }
|
|
|
|
void Set(const T& aNewValue) { mImpl->Set(aNewValue); }
|
|
|
|
Canonical& operator=(const T& aNewValue) { Set(aNewValue); return *this; }
|
|
|
|
Canonical& operator=(const Canonical& aOther) { Set(aOther); return *this; }
|
|
|
|
Canonical(const Canonical& aOther) = delete;
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Impl> mImpl;
|
2015-04-01 04:44:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mirror<T> is a wrapper class that allows a given value to mirror that of a
|
|
|
|
* Canonical<T> owned by another thread. It registers itself with a Canonical<T>,
|
|
|
|
* and is periodically updated with new values. Mirror<T> is also a WatchTarget,
|
|
|
|
* and may be set up to trigger other routines (on the same thread) when the
|
|
|
|
* mirrored value changes.
|
|
|
|
*
|
2015-04-30 04:56:18 +03:00
|
|
|
* Mirror<T> is intended to be used as a member variable, so it doesn't actually
|
|
|
|
* inherit AbstractMirror<T> (a refcounted type). Rather, it contains an inner
|
|
|
|
* class called |Impl| that implements most of the interesting logic.
|
2015-04-01 04:44:13 +03:00
|
|
|
*/
|
|
|
|
template<typename T>
|
2015-04-30 04:56:18 +03:00
|
|
|
class Mirror
|
2015-04-01 04:44:13 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-05-01 01:46:49 +03:00
|
|
|
Mirror(AbstractThread* aThread, const T& aInitialValue, const char* aName)
|
2015-04-30 10:21:43 +03:00
|
|
|
{
|
2015-05-01 01:46:49 +03:00
|
|
|
mImpl = new Impl(aThread, aInitialValue, aName);
|
2015-04-30 10:21:43 +03:00
|
|
|
}
|
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
~Mirror()
|
2015-04-01 04:44:13 +03:00
|
|
|
{
|
2015-06-16 03:26:25 +03:00
|
|
|
// As a member of complex objects, a Mirror<T> may be destroyed on a
|
|
|
|
// different thread than its owner, or late in shutdown during CC. Given
|
|
|
|
// that, we require manual disconnection so that callers can put things in
|
|
|
|
// the right place.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mImpl->IsConnected());
|
2015-04-01 04:44:13 +03:00
|
|
|
}
|
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
private:
|
|
|
|
class Impl : public AbstractMirror<T>, public WatchTarget
|
2015-04-01 04:44:13 +03:00
|
|
|
{
|
2015-04-30 04:56:18 +03:00
|
|
|
public:
|
|
|
|
using AbstractMirror<T>::OwnerThread;
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-05-01 01:46:49 +03:00
|
|
|
Impl(AbstractThread* aThread, const T& aInitialValue, const char* aName)
|
2015-04-30 04:56:18 +03:00
|
|
|
: AbstractMirror<T>(aThread), WatchTarget(aName), mValue(aInitialValue)
|
|
|
|
{
|
|
|
|
MIRROR_LOG("%s [%p] initialized", mName, this);
|
2015-05-14 04:47:42 +03:00
|
|
|
MOZ_ASSERT(aThread->SupportsTailDispatch(), "Can't get coherency without tail dispatch");
|
2015-04-30 04:56:18 +03:00
|
|
|
}
|
2015-04-25 06:23:04 +03:00
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
operator const T&()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
|
|
|
|
return mValue;
|
|
|
|
}
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
virtual void UpdateValue(const T& aNewValue) override
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
|
|
|
|
if (mValue != aNewValue) {
|
|
|
|
mValue = aNewValue;
|
|
|
|
WatchTarget::NotifyWatchers();
|
|
|
|
}
|
|
|
|
}
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
virtual void NotifyDisconnected() override
|
|
|
|
{
|
|
|
|
MIRROR_LOG("%s [%p] Notifed of disconnection from %p", mName, this, mCanonical.get());
|
|
|
|
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
|
|
|
|
mCanonical = nullptr;
|
2015-04-01 04:44:13 +03:00
|
|
|
}
|
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
bool IsConnected() const { return !!mCanonical; }
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
void Connect(AbstractCanonical<T>* aCanonical)
|
2015-04-01 04:44:13 +03:00
|
|
|
{
|
2015-04-30 04:56:18 +03:00
|
|
|
MIRROR_LOG("%s [%p] Connecting to %p", mName, this, aCanonical);
|
2015-05-01 01:46:49 +03:00
|
|
|
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
|
2015-04-30 04:56:18 +03:00
|
|
|
MOZ_ASSERT(!IsConnected());
|
2015-05-14 04:47:42 +03:00
|
|
|
MOZ_ASSERT(OwnerThread()->RequiresTailDispatch(aCanonical->OwnerThread()), "Can't get coherency without tail dispatch");
|
2015-04-30 04:56:18 +03:00
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> r =
|
|
|
|
NewRunnableMethod<StoreRefPtrPassByPtr<AbstractMirror<T>>>(
|
|
|
|
"AbstractCanonical::AddMirror",
|
|
|
|
aCanonical,
|
|
|
|
&AbstractCanonical<T>::AddMirror,
|
|
|
|
this);
|
2015-04-30 04:56:18 +03:00
|
|
|
aCanonical->OwnerThread()->Dispatch(r.forget(), AbstractThread::DontAssertDispatchSuccess);
|
|
|
|
mCanonical = aCanonical;
|
2015-04-01 04:44:13 +03:00
|
|
|
}
|
2015-04-30 04:56:18 +03:00
|
|
|
public:
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
void DisconnectIfConnected()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn());
|
|
|
|
if (!IsConnected()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
MIRROR_LOG("%s [%p] Disconnecting from %p", mName, this, mCanonical.get());
|
2017-06-12 22:34:10 +03:00
|
|
|
nsCOMPtr<nsIRunnable> r =
|
|
|
|
NewRunnableMethod<StoreRefPtrPassByPtr<AbstractMirror<T>>>(
|
|
|
|
"AbstractCanonical::RemoveMirror",
|
|
|
|
mCanonical,
|
|
|
|
&AbstractCanonical<T>::RemoveMirror,
|
|
|
|
this);
|
2015-04-30 04:56:18 +03:00
|
|
|
mCanonical->OwnerThread()->Dispatch(r.forget(), AbstractThread::DontAssertDispatchSuccess);
|
|
|
|
mCanonical = nullptr;
|
|
|
|
}
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
protected:
|
|
|
|
~Impl() { MOZ_DIAGNOSTIC_ASSERT(!IsConnected()); }
|
2015-04-01 04:44:13 +03:00
|
|
|
|
|
|
|
private:
|
2015-04-30 04:56:18 +03:00
|
|
|
T mValue;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AbstractCanonical<T>> mCanonical;
|
2015-04-01 04:44:13 +03:00
|
|
|
};
|
2015-04-30 04:56:18 +03:00
|
|
|
public:
|
2015-04-01 04:44:13 +03:00
|
|
|
|
2015-04-30 04:56:18 +03:00
|
|
|
// Forward control operations to the Impl<T>.
|
|
|
|
void Connect(AbstractCanonical<T>* aCanonical) { mImpl->Connect(aCanonical); }
|
|
|
|
void DisconnectIfConnected() { mImpl->DisconnectIfConnected(); }
|
|
|
|
|
|
|
|
// Access to the Impl<T>.
|
|
|
|
operator Impl&() { return *mImpl; }
|
|
|
|
Impl* operator&() { return mImpl; }
|
|
|
|
|
|
|
|
// Access to the T.
|
|
|
|
const T& Ref() const { return *mImpl; }
|
|
|
|
operator const T&() const { return Ref(); }
|
2015-04-01 04:44:13 +03:00
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Impl> mImpl;
|
2015-04-01 04:44:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#undef MIRROR_LOG
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|