author Sean Feng <>
Mon, 18 Jan 2021 19:23:10 +0000
changeset 563636 a0cde344a94949b9739af7fa550698a1be2f44f6
parent 515950 954d5a7490a36c05b8f07e0caaa782c7eb0a2ed5
permissions -rw-r--r--
Bug 1682045 - Allow nsPresContext to store and release the last registered OneShotPostRefreshObserver r=smaug OneShotPostRefreshObserver works as the caller registers it, and let it deletes itself via the DidRefresh method. The issue is that DidRefresh is not guaranteed to run, and it'll leak PresShell if it doesn't run. This patch allows nsPresContext to store and release the last registered OneShotPostRefreshObserver, and converted the existing usage of OneShotPostRefreshObserver to use that. So instead of asking OneShotPostRefreshObserver to delete itself, we now ask nsPresContext to release it. Differential Revision:

/* -*- 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 */

#include "mozilla/Assertions.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/PlatformMutex.h"

#include <windows.h>

#include "MutexPlatformData_windows.h"

mozilla::detail::MutexImpl::MutexImpl() {

mozilla::detail::MutexImpl::~MutexImpl() {}

void mozilla::detail::MutexImpl::lock() {

bool mozilla::detail::MutexImpl::tryLock() { return mutexTryLock(); }

bool mozilla::detail::MutexImpl::mutexTryLock() {
  return !!TryAcquireSRWLockExclusive(&platformData()->lock);

void mozilla::detail::MutexImpl::unlock() {

mozilla::detail::MutexImpl::platformData() {
  static_assert(sizeof(platformData_) >= sizeof(PlatformData),
                "platformData_ is too small");
  return reinterpret_cast<PlatformData*>(platformData_);