Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022
00023 #include "ThreadImplWin32.h"
00024
00025 #include <icl_core/os_win32_thread.h>
00026
00027 #include "Thread.h"
00028
00029 namespace icl_core {
00030 namespace thread {
00031
00032 ThreadImplWin32::ThreadImplWin32(Thread *thread, const icl_core::String& description,
00033 icl_core::ThreadPriority priority)
00034 : m_thread_handle(0),
00035 m_thread_id(0),
00036 m_thread(thread),
00037 m_priority(priority),
00038 m_description(description)
00039 {
00040 }
00041
00042 ThreadImplWin32::~ThreadImplWin32()
00043 {
00044 if (m_thread_handle != 0)
00045 {
00046 ::CloseHandle(m_thread_handle);
00047 }
00048 }
00049
00050 void ThreadImplWin32::cancel()
00051 {
00052 ::TerminateThread(m_thread_handle, 0);
00053 }
00054
00055 void ThreadImplWin32::join()
00056 {
00057 DWORD result = ::WaitForSingleObject(m_thread_handle, INFINITE);
00058 if (result == WAIT_OBJECT_0)
00059 {
00060 m_thread_id = 0;
00061 }
00062 else
00063 {
00064
00065 }
00066 }
00067
00068 icl_core::ThreadPriority ThreadImplWin32::priority() const
00069 {
00070 return m_priority;
00071 }
00072
00073 bool ThreadImplWin32::setPriority(icl_core::ThreadPriority priority)
00074 {
00075
00076 m_priority = priority;
00077 return true;
00078 }
00079
00080 bool ThreadImplWin32::start()
00081 {
00082 m_thread_id = 0;
00083 m_thread_handle = ::CreateThread(NULL, 0, ThreadImplWin32::runThread, this, 0, NULL);
00084
00085 return m_thread_handle != 0;
00086 }
00087
00088 icl_core::ThreadId ThreadImplWin32::threadId() const
00089 {
00090 return icl_core::ThreadId(m_thread_id);
00091 }
00092
00093 DWORD WINAPI ThreadImplWin32::runThread(void *arg)
00094 {
00095 ThreadImplWin32 *self = static_cast<ThreadImplWin32*>(arg);
00096
00097 self->m_thread_id = ::GetCurrentThreadId();
00098 self->m_thread->runThread();
00099
00100 return 0;
00101 }
00102
00103 }
00104 }