tools/profiler/SyncProfile.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:bda68f9b84e3
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/. */
6
7 #include "SyncProfile.h"
8 #include "UnwinderThread2.h"
9
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 }
19
20 SyncProfile::~SyncProfile()
21 {
22 if (mUtb) {
23 utb__release_sync_buffer(mUtb);
24 }
25 Sampler::FreePlatformData(GetPlatformData());
26 }
27
28 bool
29 SyncProfile::SetUWTBuffer(LinkedUWTBuffer* aBuff)
30 {
31 MOZ_ASSERT(aBuff);
32 mUtb = aBuff;
33 return true;
34 }
35
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 }
48
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 }
65

mercurial