michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "SyncProfile.h" michael@0: #include "UnwinderThread2.h" michael@0: michael@0: SyncProfile::SyncProfile(const char* aName, int aEntrySize, PseudoStack *aStack, michael@0: Thread::tid_t aThreadId, bool aIsMainThread) michael@0: : ThreadProfile(aName, aEntrySize, aStack, aThreadId, michael@0: Sampler::AllocPlatformData(aThreadId), aIsMainThread, michael@0: tlsStackTop.get()), michael@0: mOwnerState(REFERENCED), michael@0: mUtb(nullptr) michael@0: { michael@0: } michael@0: michael@0: SyncProfile::~SyncProfile() michael@0: { michael@0: if (mUtb) { michael@0: utb__release_sync_buffer(mUtb); michael@0: } michael@0: Sampler::FreePlatformData(GetPlatformData()); michael@0: } michael@0: michael@0: bool michael@0: SyncProfile::SetUWTBuffer(LinkedUWTBuffer* aBuff) michael@0: { michael@0: MOZ_ASSERT(aBuff); michael@0: mUtb = aBuff; michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: SyncProfile::ShouldDestroy() michael@0: { michael@0: GetMutex()->AssertNotCurrentThreadOwns(); michael@0: mozilla::MutexAutoLock lock(*GetMutex()); michael@0: if (mOwnerState == OWNED) { michael@0: mOwnerState = OWNER_DESTROYING; michael@0: return true; michael@0: } michael@0: mOwnerState = ORPHANED; michael@0: return false; michael@0: } michael@0: michael@0: void michael@0: SyncProfile::EndUnwind() michael@0: { michael@0: // Mutex must be held when this is called michael@0: GetMutex()->AssertCurrentThreadOwns(); michael@0: if (mOwnerState != ORPHANED) { michael@0: flush(); michael@0: mOwnerState = OWNED; michael@0: } michael@0: // Save mOwnerState before we release the mutex michael@0: OwnerState ownerState = mOwnerState; michael@0: ThreadProfile::EndUnwind(); michael@0: if (ownerState == ORPHANED) { michael@0: delete this; michael@0: } michael@0: } michael@0: