1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/profiler/SyncProfile.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "SyncProfile.h" 1.11 +#include "UnwinderThread2.h" 1.12 + 1.13 +SyncProfile::SyncProfile(const char* aName, int aEntrySize, PseudoStack *aStack, 1.14 + Thread::tid_t aThreadId, bool aIsMainThread) 1.15 + : ThreadProfile(aName, aEntrySize, aStack, aThreadId, 1.16 + Sampler::AllocPlatformData(aThreadId), aIsMainThread, 1.17 + tlsStackTop.get()), 1.18 + mOwnerState(REFERENCED), 1.19 + mUtb(nullptr) 1.20 +{ 1.21 +} 1.22 + 1.23 +SyncProfile::~SyncProfile() 1.24 +{ 1.25 + if (mUtb) { 1.26 + utb__release_sync_buffer(mUtb); 1.27 + } 1.28 + Sampler::FreePlatformData(GetPlatformData()); 1.29 +} 1.30 + 1.31 +bool 1.32 +SyncProfile::SetUWTBuffer(LinkedUWTBuffer* aBuff) 1.33 +{ 1.34 + MOZ_ASSERT(aBuff); 1.35 + mUtb = aBuff; 1.36 + return true; 1.37 +} 1.38 + 1.39 +bool 1.40 +SyncProfile::ShouldDestroy() 1.41 +{ 1.42 + GetMutex()->AssertNotCurrentThreadOwns(); 1.43 + mozilla::MutexAutoLock lock(*GetMutex()); 1.44 + if (mOwnerState == OWNED) { 1.45 + mOwnerState = OWNER_DESTROYING; 1.46 + return true; 1.47 + } 1.48 + mOwnerState = ORPHANED; 1.49 + return false; 1.50 +} 1.51 + 1.52 +void 1.53 +SyncProfile::EndUnwind() 1.54 +{ 1.55 + // Mutex must be held when this is called 1.56 + GetMutex()->AssertCurrentThreadOwns(); 1.57 + if (mOwnerState != ORPHANED) { 1.58 + flush(); 1.59 + mOwnerState = OWNED; 1.60 + } 1.61 + // Save mOwnerState before we release the mutex 1.62 + OwnerState ownerState = mOwnerState; 1.63 + ThreadProfile::EndUnwind(); 1.64 + if (ownerState == ORPHANED) { 1.65 + delete this; 1.66 + } 1.67 +} 1.68 +