tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RefCounted.cpp (1446B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "mozilla/RefCounted.h"
      8 
      9 namespace mozilla::detail {
     10 
     11 #ifdef MOZ_REFCOUNTED_LEAK_CHECKING
     12 MFBT_DATA LogAddRefFunc gLogAddRefFunc = nullptr;
     13 MFBT_DATA LogReleaseFunc gLogReleaseFunc = nullptr;
     14 MFBT_DATA size_t gNumStaticCtors = 0;
     15 MFBT_DATA const char* gLastStaticCtorTypeName = nullptr;
     16 
     17 MFBT_API void RefCountLogger::SetLeakCheckingFunctions(
     18    LogAddRefFunc aLogAddRefFunc, LogReleaseFunc aLogReleaseFunc) {
     19  if (gNumStaticCtors > 0) {
     20    // RefCountLogger was used before this point. Print a warning, similar to
     21    // ASSERT_ACTIVITY_IS_LEGAL. We do this here because SpiderMonkey standalone
     22    // and shell builds don't call this function and we don't want to report any
     23    // warnings in that case.
     24    fprintf(stderr,
     25            "RefCounted objects addrefed/released (static ctor?) total: %zu, "
     26            "last type: %s\n",
     27            gNumStaticCtors, gLastStaticCtorTypeName);
     28    gNumStaticCtors = 0;
     29    gLastStaticCtorTypeName = nullptr;
     30  }
     31  gLogAddRefFunc = aLogAddRefFunc;
     32  gLogReleaseFunc = aLogReleaseFunc;
     33 }
     34 #endif  // MOZ_REFCOUNTED_LEAK_CHECKING
     35 
     36 }  // namespace mozilla::detail