Bug 1073336 part 5 - Add AnimationPlayerCollection::PlayerUpdated; r=dbaron
[gecko.git] / tools / profiler / SyncProfile.cpp
blob2d24d63bca470bd9ba0b147fff32741364e1b1df
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(ThreadInfo* aInfo, int aEntrySize)
11 : ThreadProfile(aInfo, aEntrySize)
12 , mOwnerState(REFERENCED)
13 , mUtb(nullptr)
15 MOZ_COUNT_CTOR(SyncProfile);
18 SyncProfile::~SyncProfile()
20 MOZ_COUNT_DTOR(SyncProfile);
21 if (mUtb) {
22 utb__release_sync_buffer(mUtb);
24 Sampler::FreePlatformData(GetPlatformData());
27 bool
28 SyncProfile::SetUWTBuffer(LinkedUWTBuffer* aBuff)
30 MOZ_ASSERT(aBuff);
31 mUtb = aBuff;
32 return true;
35 bool
36 SyncProfile::ShouldDestroy()
38 GetMutex()->AssertNotCurrentThreadOwns();
39 mozilla::MutexAutoLock lock(*GetMutex());
40 if (mOwnerState == OWNED) {
41 mOwnerState = OWNER_DESTROYING;
42 return true;
44 mOwnerState = ORPHANED;
45 return false;
48 void
49 SyncProfile::EndUnwind()
51 // Mutex must be held when this is called
52 GetMutex()->AssertCurrentThreadOwns();
53 if (mUtb) {
54 utb__end_sync_buffer_unwind(mUtb);
56 if (mOwnerState != ORPHANED) {
57 flush();
58 mOwnerState = OWNED;
60 // Save mOwnerState before we release the mutex
61 OwnerState ownerState = mOwnerState;
62 ThreadProfile::EndUnwind();
63 if (ownerState == ORPHANED) {
64 delete this;