tools/profiler/SyncProfile.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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