tools/profiler/SyncProfile.cpp

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: 2; 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 #include "SyncProfile.h"
     8 #include "UnwinderThread2.h"
    10 SyncProfile::SyncProfile(const char* aName, int aEntrySize, PseudoStack *aStack,
    11                          Thread::tid_t aThreadId, bool aIsMainThread)
    12   : ThreadProfile(aName, aEntrySize, aStack, aThreadId,
    13                  Sampler::AllocPlatformData(aThreadId), aIsMainThread,
    14                  tlsStackTop.get()),
    15     mOwnerState(REFERENCED),
    16     mUtb(nullptr)
    17 {
    18 }
    20 SyncProfile::~SyncProfile()
    21 {
    22   if (mUtb) {
    23     utb__release_sync_buffer(mUtb);
    24   }
    25   Sampler::FreePlatformData(GetPlatformData());
    26 }
    28 bool
    29 SyncProfile::SetUWTBuffer(LinkedUWTBuffer* aBuff)
    30 {
    31   MOZ_ASSERT(aBuff);
    32   mUtb = aBuff;
    33   return true;
    34 }
    36 bool
    37 SyncProfile::ShouldDestroy()
    38 {
    39   GetMutex()->AssertNotCurrentThreadOwns();
    40   mozilla::MutexAutoLock lock(*GetMutex());
    41   if (mOwnerState == OWNED) {
    42     mOwnerState = OWNER_DESTROYING;
    43     return true;
    44   }
    45   mOwnerState = ORPHANED;
    46   return false;
    47 }
    49 void
    50 SyncProfile::EndUnwind()
    51 {
    52   // Mutex must be held when this is called
    53   GetMutex()->AssertCurrentThreadOwns();
    54   if (mOwnerState != ORPHANED) {
    55     flush();
    56     mOwnerState = OWNED;
    57   }
    58   // Save mOwnerState before we release the mutex
    59   OwnerState ownerState = mOwnerState;
    60   ThreadProfile::EndUnwind();
    61   if (ownerState == ORPHANED) {
    62     delete this;
    63   }
    64 }

mercurial