diff --git a/server/TracyView.cpp b/server/TracyView.cpp new file mode 100755 index 00000000..ec0add6c --- /dev/null +++ b/server/TracyView.cpp @@ -0,0 +1,40 @@ +#include + +#include "../common/TracySystem.hpp" +#include "TracyView.hpp" + +namespace tracy +{ + +static View* s_instance = nullptr; + +View::View( const char* addr ) + : m_addr( addr ) + , m_shutdown( false ) +{ + assert( s_instance == nullptr ); + s_instance = this; + + m_thread = std::thread( [this] { Worker(); } ); + SetThreadName( m_thread, "Tracy View" ); +} + +View::~View() +{ + assert( s_instance != nullptr ); + s_instance = nullptr; + + m_shutdown.store( true, std::memory_order_relaxed ); + m_thread.join(); +} + +void View::Worker() +{ + for(;;) + { + if( m_shutdown.load( std::memory_order_relaxed ) ) return; + std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); + } +} + +} diff --git a/server/TracyView.hpp b/server/TracyView.hpp new file mode 100755 index 00000000..72d1585b --- /dev/null +++ b/server/TracyView.hpp @@ -0,0 +1,29 @@ +#ifndef __TRACYVIEW_HPP__ +#define __TRACYVIEW_HPP__ + +#include +#include +#include + +namespace tracy +{ + +class View +{ +public: + View() : View( "127.0.0.1" ) {} + View( const char* addr ); + ~View(); + +private: + void Worker(); + + std::string m_addr; + + std::thread m_thread; + std::atomic m_shutdown; +}; + +} + +#endif