Bug 1520955. Add ref qualifier to DataMutex for more safety. r=froydnj

We lose some sugar but gain some safety. This seems like the right
trade. If people want sugar they should use Rust.

Differential Revision: https://phabricator.services.mozilla.com/D16918

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jeff Muizelaar 2019-01-18 16:48:22 +00:00
parent 2940e587c4
commit 91c37e95f0
2 changed files with 8 additions and 4 deletions

View File

@ -180,7 +180,8 @@ void RenderThread::AddRenderer(wr::WindowId aWindowId,
mRenderers[aWindowId] = std::move(aRenderer);
mWindowInfos.Lock()->emplace(AsUint64(aWindowId), new WindowInfo());
auto windows = mWindowInfos.Lock();
windows->emplace(AsUint64(aWindowId), new WindowInfo());
}
void RenderThread::RemoveRenderer(wr::WindowId aWindowId) {

View File

@ -39,9 +39,11 @@ class DataMutex {
private:
class MOZ_STACK_CLASS AutoLock {
public:
T* operator->() const { return &ref(); }
T* operator->() const& { return &ref(); }
T* operator->() const&& = delete;
T& operator*() const { return ref(); }
T& operator*() const& { return ref(); }
T& operator*() const&& = delete;
// Like RefPtr, make this act like its underlying raw pointer type
// whenever it is used in a context where a raw pointer is expected.
@ -50,10 +52,11 @@ class DataMutex {
// Like RefPtr, don't allow implicit conversion of temporary to raw pointer.
operator T*() const&& = delete;
T& ref() const {
T& ref() const& {
MOZ_ASSERT(mOwner);
return mOwner->mValue;
}
T& ref() const&& = delete;
AutoLock(AutoLock&& aOther) : mOwner(aOther.mOwner) {
aOther.mOwner = nullptr;