VR-Vantage 3.1 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TracyThread.hpp
Go to the documentation of this file.
1 #ifndef __TRACYTHREAD_HPP__
2 #define __TRACYTHREAD_HPP__
3 
4 #if defined _WIN32 || defined __CYGWIN__
5 # include <windows.h>
6 #else
7 # include <pthread.h>
8 #endif
9 
10 #ifdef TRACY_MANUAL_LIFETIME
11 # include "tracy_rpmalloc.hpp"
12 #endif
13 
14 namespace tracy
15 {
16 
18 {
19 public:
21  {
22 #ifdef TRACY_MANUAL_LIFETIME
24 #endif
25  }
26 };
27 
28 #if defined _WIN32 || defined __CYGWIN__
29 
30 class Thread
31 {
32 public:
33  Thread( void(*func)( void* ptr ), void* ptr )
34  : m_func( func )
35  , m_ptr( ptr )
36  , m_hnd( CreateThread( nullptr, 0, Launch, this, 0, nullptr ) )
37  {}
38 
39  ~Thread()
40  {
41  WaitForSingleObject( m_hnd, INFINITE );
42  CloseHandle( m_hnd );
43  }
44 
45  HANDLE Handle() const { return m_hnd; }
46 
47 private:
48  static DWORD WINAPI Launch( void* ptr ) { ((Thread*)ptr)->m_func( ((Thread*)ptr)->m_ptr ); return 0; }
49 
50  void(*m_func)( void* ptr );
51  void* m_ptr;
52  HANDLE m_hnd;
53 };
54 
55 #else
56 
57 class Thread
58 {
59 public:
60  Thread( void(*func)( void* ptr ), void* ptr )
61  : m_func( func )
62  , m_ptr( ptr )
63  {
64  pthread_create( &m_thread, nullptr, Launch, this );
65  }
66 
68  {
69  pthread_join( m_thread, nullptr );
70  }
71 
72  pthread_t Handle() const { return m_thread; }
73 
74 private:
75  static void* Launch( void* ptr ) { ((Thread*)ptr)->m_func( ((Thread*)ptr)->m_ptr ); return nullptr; }
76  void(*m_func)( void* ptr );
77  void* m_ptr;
78  pthread_t m_thread;
79 };
80 
81 #endif
82 
83 }
84 
85 #endif


Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)