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:
Nathan Froyd 2017-01-06 09:21:01 -05:00
Родитель 5767fcd327
Коммит 0dab5bba8e
6 изменённых файлов: 26 добавлений и 22 удалений

Просмотреть файл

@ -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