View server skeleton.

This commit is contained in:
Bartosz Taudul 2017-09-13 01:33:50 +02:00
parent 45646c4f45
commit 953e9c6206
2 changed files with 69 additions and 0 deletions

40
server/TracyView.cpp Executable file
View File

@ -0,0 +1,40 @@
#include <assert.h>
#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 ) );
}
}
}

29
server/TracyView.hpp Executable file
View File

@ -0,0 +1,29 @@
#ifndef __TRACYVIEW_HPP__
#define __TRACYVIEW_HPP__
#include <atomic>
#include <string>
#include <thread>
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<bool> m_shutdown;
};
}
#endif