OpenBarnyard
 
Loading...
Searching...
No Matches
TThread Class Referenceabstract

#include <TThread_Win.h>

Inheritance diagram for TThread:
T2GenericDList::Node TFileStream Toshi::T2NamedPipeServerThread

Public Types

enum  PRIORITY_ : PRIORITY {
  THREAD_MODE_BACKGROUND_BEGIN = 0x00010000 , THREAD_MODE_BACKGROUND_END = 0x00020000 , THREAD_PRIORITY_ABOVE_NORMAL = 1 , THREAD_PRIORITY_BELOW_NORMAL = -1 ,
  THREAD_PRIORITY_HIGHEST = 2 , THREAD_PRIORITY_IDLE = -15 , THREAD_PRIORITY_LOWEST = -2 , THREAD_PRIORITY_NORMAL = 0 ,
  THREAD_PRIORITY_TIME_CRITICAL = 15
}
 
typedef TINT PRIORITY
 

Public Member Functions

virtual void Main ()=0
 
virtual ~TThread ()
 
TBOOL Create (size_t a_iStackSize, PRIORITY a_ePriority, TUINT8 a_eFlags)
 
TBOOL Destroy ()
 
- Public Member Functions inherited from T2GenericDList::Node
constexpr Node ()
 
 ~Node ()
 
TBOOL IsLinked () const
 
void InsertBefore (Node *pInsertBefore)
 
void InsertAfter (Node *pInsertAfter)
 
void Remove ()
 
NodeNext () const
 
NodePrev () const
 

Static Public Member Functions

static TBOOL GetPriority (void *a_hThreadHnd, PRIORITY &a_ePriority)
 
static TBOOL SetPriority (void *a_hThreadHnd, PRIORITY a_ePriority)
 
static void Exit (TThread *a_pThread)
 

Public Attributes

void * m_hThreadHnd
 
unsigned long m_iThreadID
 

Additional Inherited Members

- Protected Attributes inherited from T2GenericDList::Node
friend T2GenericDList
 

Detailed Description

Definition at line 19 of file TThread_Win.h.

Member Typedef Documentation

◆ PRIORITY

Definition at line 22 of file TThread_Win.h.

Member Enumeration Documentation

◆ PRIORITY_

Enumerator
THREAD_MODE_BACKGROUND_BEGIN 
THREAD_MODE_BACKGROUND_END 
THREAD_PRIORITY_ABOVE_NORMAL 
THREAD_PRIORITY_BELOW_NORMAL 
THREAD_PRIORITY_HIGHEST 
THREAD_PRIORITY_IDLE 
THREAD_PRIORITY_LOWEST 
THREAD_PRIORITY_NORMAL 
THREAD_PRIORITY_TIME_CRITICAL 

Definition at line 23 of file TThread_Win.h.

24 {
26 THREAD_MODE_BACKGROUND_END = 0x00020000,
34 };
@ THREAD_PRIORITY_ABOVE_NORMAL
Definition TThread_Win.h:27
@ THREAD_MODE_BACKGROUND_END
Definition TThread_Win.h:26
@ THREAD_MODE_BACKGROUND_BEGIN
Definition TThread_Win.h:25
@ THREAD_PRIORITY_BELOW_NORMAL
Definition TThread_Win.h:28
@ THREAD_PRIORITY_HIGHEST
Definition TThread_Win.h:29
@ THREAD_PRIORITY_NORMAL
Definition TThread_Win.h:32
@ THREAD_PRIORITY_TIME_CRITICAL
Definition TThread_Win.h:33
@ THREAD_PRIORITY_LOWEST
Definition TThread_Win.h:31
@ THREAD_PRIORITY_IDLE
Definition TThread_Win.h:30

Constructor & Destructor Documentation

◆ ~TThread()

virtual TThread::~TThread ( )
inlinevirtual

Definition at line 38 of file TThread_Win.h.

38{};

Member Function Documentation

◆ Create()

TBOOL TThread::Create ( size_t a_iStackSize,
PRIORITY a_ePriority,
TUINT8 a_eFlags )

Definition at line 26 of file TThread_Win.cpp.

27{
28 m_iThreadID = -1;
29 m_hThreadHnd = CreateThread( NULL, a_iStackSize, ThreadEntry, this, CREATE_SUSPENDED, &m_iThreadID );
30
31 TASSERT( m_hThreadHnd != NULL, "Couldn't create thread" );
32 TBOOL bResult = SetThreadPriority( m_hThreadHnd, a_ePriority );
33 TASSERT( bResult != TFALSE, "Couldn't set thread priority" );
34
36
37 if ( ( a_eFlags & 1 ) == 0 )
38 {
39 DWORD iResult = ResumeThread( m_hThreadHnd );
40 TASSERT( iResult != -1, "Couldn't resume thread" );
41 }
42
43 return TTRUE;
44}
#define TASSERT(X,...)
Definition Defines.h:138
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
unsigned long m_iThreadID
Definition TThread_Win.h:50
void * m_hThreadHnd
Definition TThread_Win.h:49
void InsertThread(TThread *a_pThread)
static TFORCEINLINE TThreadManager * GetSingletonSafe()
Definition TSingleton.h:37

◆ Destroy()

TBOOL TThread::Destroy ( )

Definition at line 46 of file TThread_Win.cpp.

47{
48 TASSERT( m_iThreadID != GetCurrentThreadId() );
49
50 BOOL bResult = TerminateThread( m_hThreadHnd, 0 );
51 TASSERT( bResult != FALSE );
52
53 bResult = CloseHandle( m_hThreadHnd );
54 TASSERT( bResult != FALSE );
55
57 m_hThreadHnd = NULL;
58 m_iThreadID = -1;
59
60 return TTRUE;
61}
void RemoveThread(TThread *a_pThread)

◆ Exit()

void TThread::Exit ( TThread * a_pThread)
static

Definition at line 81 of file TThread_Win.cpp.

82{
83 TASSERT( a_pThread->m_iThreadID == GetCurrentThreadId(), "Thread cannot be closed outside" );
84
85 BOOL bResult = CloseHandle( a_pThread->m_hThreadHnd );
86 TASSERT( bResult != FALSE, "Couldn't close thread" );
87
89 a_pThread->m_hThreadHnd = NULL;
90 a_pThread->m_iThreadID = -1;
91
92 _endthreadex( 0 );
93}

◆ GetPriority()

TBOOL TThread::GetPriority ( void * a_hThreadHnd,
PRIORITY & a_ePriority )
static

Definition at line 63 of file TThread_Win.cpp.

64{
65 TASSERT( a_hThreadHnd != NULL, "Thread doesn't exist" );
66 TINT iPriority = GetThreadPriority( a_hThreadHnd );
67 TASSERT( iPriority != THREAD_PRIORITY_ERROR_RETURN, "Couldn't get thread priority" );
68 a_ePriority = iPriority;
69 return TTRUE;
70}
int TINT
Definition Typedefs.h:7

◆ Main()

virtual void TThread::Main ( )
pure virtual

◆ SetPriority()

TBOOL TThread::SetPriority ( void * a_hThreadHnd,
PRIORITY a_ePriority )
static

Definition at line 72 of file TThread_Win.cpp.

73{
74 TASSERT( a_hThreadHnd != NULL, "Thread doesn't exist" );
75 BOOL bResult = SetThreadPriority( a_hThreadHnd, a_ePriority );
76 TASSERT( bResult != FALSE, "Couldn't set priority" );
77 return TTRUE;
78}

Member Data Documentation

◆ m_hThreadHnd

void* TThread::m_hThreadHnd

Definition at line 49 of file TThread_Win.h.

◆ m_iThreadID

unsigned long TThread::m_iThreadID

Definition at line 50 of file TThread_Win.h.


The documentation for this class was generated from the following files: