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;
|
||||
|
||||
ProfileManager* ProfileManager::m_profileManager = nullptr;
|
||||
|
||||
extern "C"{
|
||||
|
||||
void PROFILER_API registerMark(Mark* _mark)
|
||||
{
|
||||
ProfileManager::instance()->registerMark(_mark);
|
||||
}
|
||||
void PROFILER_API registerMark(Mark* _mark)
|
||||
{
|
||||
ProfileManager::instance().registerMark(_mark);
|
||||
}
|
||||
|
||||
void PROFILER_API endBlock()
|
||||
{
|
||||
ProfileManager::instance()->endBlock();
|
||||
}
|
||||
|
||||
void PROFILER_API setEnabled(bool isEnable)
|
||||
{
|
||||
ProfileManager::instance()->setEnabled(isEnable);
|
||||
}
|
||||
void PROFILER_API endBlock()
|
||||
{
|
||||
ProfileManager::instance().endBlock();
|
||||
}
|
||||
|
||||
void PROFILER_API setEnabled(bool isEnable)
|
||||
{
|
||||
ProfileManager::instance().setEnabled(isEnable);
|
||||
}
|
||||
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)
|
||||
{
|
||||
//TODO: thread safety for profiler::instance
|
||||
//if(!m_profiler)//see paper by Scott Mayers and Alecsandrescu: http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
|
||||
m_profileManager = new ProfileManager();
|
||||
}
|
||||
return 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/
|
||||
static ProfileManager m_profileManager;
|
||||
return m_profileManager;
|
||||
}
|
||||
|
||||
void ProfileManager::registerMark(profiler::Mark* _mark)
|
||||
|
@ -26,11 +26,11 @@ class ProfileManager
|
||||
ProfileManager();
|
||||
ProfileManager(const ProfileManager& p) = delete;
|
||||
ProfileManager& operator=(const ProfileManager&) = delete;
|
||||
static ProfileManager* m_profileManager;
|
||||
static ProfileManager m_profileManager;
|
||||
|
||||
bool m_isEnabled = false;
|
||||
public:
|
||||
static ProfileManager* instance();
|
||||
static ProfileManager& instance();
|
||||
|
||||
void registerMark(profiler::Mark* _mark);
|
||||
void beginBlock(profiler::Block* _block);
|
||||
|
Loading…
x
Reference in New Issue
Block a user