mfbt/ReentrancyGuard.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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/. */
     7 /* Small helper class for asserting uses of a class are non-reentrant. */
     9 #ifndef mozilla_ReentrancyGuard_h
    10 #define mozilla_ReentrancyGuard_h
    12 #include "mozilla/Assertions.h"
    13 #include "mozilla/Attributes.h"
    14 #include "mozilla/GuardObjects.h"
    16 namespace mozilla {
    18 /* Useful for implementing containers that assert non-reentrancy */
    19 class ReentrancyGuard
    20 {
    21     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
    22 #ifdef DEBUG
    23     bool& entered;
    24 #endif
    26   public:
    27     template<class T>
    28 #ifdef DEBUG
    29     ReentrancyGuard(T& obj
    30                     MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
    31       : entered(obj.entered)
    32 #else
    33     ReentrancyGuard(T&
    34                     MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
    35 #endif
    36     {
    37       MOZ_GUARD_OBJECT_NOTIFIER_INIT;
    38 #ifdef DEBUG
    39       MOZ_ASSERT(!entered);
    40       entered = true;
    41 #endif
    42     }
    43     ~ReentrancyGuard()
    44     {
    45 #ifdef DEBUG
    46       entered = false;
    47 #endif
    48     }
    50   private:
    51     ReentrancyGuard(const ReentrancyGuard&) MOZ_DELETE;
    52     void operator=(const ReentrancyGuard&) MOZ_DELETE;
    53 };
    55 } // namespace mozilla
    57 #endif /* mozilla_ReentrancyGuard_h */

mercurial