Thread.cpp
author sl
Mon, 17 Mar 2014 12:38:39 +0100
changeset 3 d5f6b2119a13
permissions -rw-r--r--
Fixing init result issue.
     1 //------------------------------------------------------------------------------
     2 #include "Thread.h"
     3 //------------------------------------------------------------------------------
     4 Thread::Thread() : m_hThread(NULL), m_dwThreadId(0)
     5 {
     6 }
     7 //------------------------------------------------------------------------------
     8 Thread::~Thread()
     9 {
    10   if (m_hThread != NULL)
    11   {
    12     TerminateThread(m_hThread, -1);
    13     m_hThread = NULL;
    14   }
    15 }
    16 //------------------------------------------------------------------------------
    17 void Thread::Start()
    18 {
    19   if (m_hThread != NULL)
    20     return;
    21   m_hThread = CreateThread(
    22     NULL,
    23     0,
    24     Thread::ThreadProc,
    25     this,
    26     0,
    27     &m_dwThreadId);
    28 }
    29 //------------------------------------------------------------------------------
    30 void Thread::Join() const
    31 {
    32   WaitForSingleObject(m_hThread, INFINITE);
    33 }
    34 //------------------------------------------------------------------------------
    35 DWORD WINAPI Thread::ThreadProc(LPVOID lpParam)
    36 {
    37   Thread* pThread = (Thread*)lpParam;
    38   pThread->Run();
    39   return 0;
    40 }
    41 //------------------------------------------------------------------------------