mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-27 00:31:02 +08:00
Some changes to Singleton implementation
This commit is contained in:
parent
1f80b87816
commit
561f79e8e6
@ -3,28 +3,25 @@
|
|||||||
|
|
||||||
using namespace profiler;
|
using namespace profiler;
|
||||||
|
|
||||||
ProfileManager* ProfileManager::m_profileManager = nullptr;
|
|
||||||
|
|
||||||
extern "C"{
|
extern "C"{
|
||||||
|
|
||||||
void PROFILER_API registerMark(Mark* _mark)
|
void PROFILER_API registerMark(Mark* _mark)
|
||||||
{
|
{
|
||||||
ProfileManager::instance()->registerMark(_mark);
|
ProfileManager::instance().registerMark(_mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PROFILER_API endBlock()
|
void PROFILER_API endBlock()
|
||||||
{
|
{
|
||||||
ProfileManager::instance()->endBlock();
|
ProfileManager::instance().endBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PROFILER_API setEnabled(bool isEnable)
|
|
||||||
{
|
|
||||||
ProfileManager::instance()->setEnabled(isEnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void PROFILER_API setEnabled(bool isEnable)
|
||||||
|
{
|
||||||
|
ProfileManager::instance().setEnabled(isEnable);
|
||||||
|
}
|
||||||
void PROFILER_API beginBlock(Block* _block)
|
void PROFILER_API beginBlock(Block* _block)
|
||||||
{
|
{
|
||||||
ProfileManager::instance()->beginBlock(_block);
|
ProfileManager::instance().beginBlock(_block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,15 +31,12 @@ ProfileManager::ProfileManager()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileManager* ProfileManager::instance()
|
ProfileManager& ProfileManager::instance()
|
||||||
{
|
{
|
||||||
if (!m_profileManager)
|
///C++11 makes possible to create Singleton without any warry about thread-safeness
|
||||||
{
|
///http://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/
|
||||||
//TODO: thread safety for profiler::instance
|
static ProfileManager m_profileManager;
|
||||||
//if(!m_profiler)//see paper by Scott Mayers and Alecsandrescu: http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
|
return m_profileManager;
|
||||||
m_profileManager = new ProfileManager();
|
|
||||||
}
|
|
||||||
return m_profileManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileManager::registerMark(profiler::Mark* _mark)
|
void ProfileManager::registerMark(profiler::Mark* _mark)
|
||||||
|
@ -26,11 +26,11 @@ class ProfileManager
|
|||||||
ProfileManager();
|
ProfileManager();
|
||||||
ProfileManager(const ProfileManager& p) = delete;
|
ProfileManager(const ProfileManager& p) = delete;
|
||||||
ProfileManager& operator=(const ProfileManager&) = delete;
|
ProfileManager& operator=(const ProfileManager&) = delete;
|
||||||
static ProfileManager* m_profileManager;
|
static ProfileManager m_profileManager;
|
||||||
|
|
||||||
bool m_isEnabled = false;
|
bool m_isEnabled = false;
|
||||||
public:
|
public:
|
||||||
static ProfileManager* instance();
|
static ProfileManager& instance();
|
||||||
|
|
||||||
void registerMark(profiler::Mark* _mark);
|
void registerMark(profiler::Mark* _mark);
|
||||||
void beginBlock(profiler::Block* _block);
|
void beginBlock(profiler::Block* _block);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user