зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1322863 - part 3 - manage Sampler::PlatformData with UniquePtr; r=mstange
Smart pointers are better than raw pointers, and this makes clients of PlatformData slightly simpler because they don't have to manage destruction themselves: the new UniquePtr-derived type handles all of that for us.
This commit is contained in:
Родитель
5767fcd327
Коммит
0dab5bba8e
|
@ -34,8 +34,6 @@ ThreadInfo::ThreadInfo(const char* aName, int aThreadId,
|
|||
|
||||
ThreadInfo::~ThreadInfo() {
|
||||
MOZ_COUNT_DTOR(ThreadInfo);
|
||||
|
||||
Sampler::FreePlatformData(mPlatformData);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -29,7 +29,7 @@ class ThreadInfo {
|
|||
}
|
||||
ThreadProfile* Profile() const { return mProfile.get(); }
|
||||
|
||||
PlatformData* GetPlatformData() const { return mPlatformData; }
|
||||
PlatformData* GetPlatformData() const { return mPlatformData.get(); }
|
||||
void* StackTop() const { return mStackTop; }
|
||||
|
||||
virtual void SetPendingDelete();
|
||||
|
@ -50,7 +50,7 @@ class ThreadInfo {
|
|||
int mThreadId;
|
||||
const bool mIsMainThread;
|
||||
PseudoStack* mPseudoStack;
|
||||
PlatformData* mPlatformData;
|
||||
Sampler::UniquePlatformData mPlatformData;
|
||||
mozilla::UniquePtr<ThreadProfile> mProfile;
|
||||
void* mStackTop;
|
||||
#ifndef SPS_STANDALONE
|
||||
|
|
|
@ -287,14 +287,14 @@ class PlatformData {
|
|||
}
|
||||
};
|
||||
|
||||
/* static */ PlatformData*
|
||||
Sampler::AllocPlatformData(int aThreadId)
|
||||
/* static */ auto
|
||||
Sampler::AllocPlatformData(int aThreadId) -> UniquePlatformData
|
||||
{
|
||||
return new PlatformData;
|
||||
return UniquePlatformData(new PlatformData);
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
Sampler::FreePlatformData(PlatformData* aData)
|
||||
void
|
||||
Sampler::PlatformDataDestructor::operator()(PlatformData* aData)
|
||||
{
|
||||
delete aData;
|
||||
}
|
||||
|
|
|
@ -163,14 +163,14 @@ class PlatformData {
|
|||
pthread_t profiled_pthread_;
|
||||
};
|
||||
|
||||
/* static */ PlatformData*
|
||||
Sampler::AllocPlatformData(int aThreadId)
|
||||
/* static */ auto
|
||||
Sampler::AllocPlatformData(int aThreadId) -> UniquePlatformData
|
||||
{
|
||||
return new PlatformData;
|
||||
return UniquePlatformData(new PlatformData);
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
Sampler::FreePlatformData(PlatformData* aData)
|
||||
void
|
||||
Sampler::PlatformDataDestructor::operator()(PlatformData* aData)
|
||||
{
|
||||
delete aData;
|
||||
}
|
||||
|
|
|
@ -69,14 +69,14 @@ class PlatformData {
|
|||
HANDLE profiled_thread_;
|
||||
};
|
||||
|
||||
/* static */ PlatformData*
|
||||
Sampler::AllocPlatformData(int aThreadId)
|
||||
/* static */ auto
|
||||
Sampler::AllocPlatformData(int aThreadId) -> UniquePlatformData
|
||||
{
|
||||
return new PlatformData(aThreadId);
|
||||
return UniquePlatformData(new PlatformData(aThreadId));
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
Sampler::FreePlatformData(PlatformData* aData)
|
||||
void
|
||||
Sampler::PlatformDataDestructor::operator()(PlatformData* aData)
|
||||
{
|
||||
delete aData;
|
||||
}
|
||||
|
|
|
@ -365,9 +365,15 @@ class Sampler {
|
|||
int EntrySize() { return entrySize_; }
|
||||
|
||||
// We can't new/delete the type safely without defining it
|
||||
// (-Wdelete-incomplete). Use these Alloc/Free functions instead.
|
||||
static PlatformData* AllocPlatformData(int aThreadId);
|
||||
static void FreePlatformData(PlatformData*);
|
||||
// (-Wdelete-incomplete). Use these to hide the details from
|
||||
// clients.
|
||||
struct PlatformDataDestructor {
|
||||
void operator()(PlatformData*);
|
||||
};
|
||||
|
||||
typedef mozilla::UniquePtr<PlatformData, PlatformDataDestructor>
|
||||
UniquePlatformData;
|
||||
static UniquePlatformData AllocPlatformData(int aThreadId);
|
||||
|
||||
// If we move the backtracing code into the platform files we won't
|
||||
// need to have these hacks
|
||||
|
|
Загрузка…
Ссылка в новой задаче