tracy/client/TracyLock.hpp

49 lines
846 B
C++
Raw Normal View History

2017-10-04 13:41:02 +00:00
#ifndef __TRACYLOCK_HPP__
#define __TRACYLOCK_HPP__
#include "TracyProfiler.hpp"
namespace tracy
{
template<class T>
class Lockable
{
public:
Lockable( const SourceLocation* srcloc )
{
2017-10-04 14:16:40 +00:00
Magic magic;
auto& token = s_token;
auto item = s_queue.enqueue_begin( token, magic );
item->hdr.type = QueueType::LockAnnounce;
item->lockAnnounce.id = (uint64_t)&m_lockable;
item->lockAnnounce.srcloc = (uint64_t)srcloc;
s_queue.enqueue_finish( token, magic );
2017-10-04 13:41:02 +00:00
}
Lockable( const Lockable& ) = delete;
Lockable& operator=( const Lockable& ) = delete;
void lock()
{
m_lockable.lock();
}
void unlock()
{
m_lockable.unlock();
}
bool try_lock()
{
return m_lockable.try_lock();
}
private:
T m_lockable;
};
};
#endif