icl_core_thread/ThreadImplWin32.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #include "ThreadImplWin32.h"
24 
26 
27 #include "Thread.h"
28 
29 namespace icl_core {
30 namespace thread {
31 
33  icl_core::ThreadPriority priority)
34  : m_thread_handle(0),
35  m_thread_id(0),
36  m_thread(thread),
37  m_priority(priority),
38  m_description(description)
39 {
40 }
41 
43 {
44  if (m_thread_handle != 0)
45  {
46  ::CloseHandle(m_thread_handle);
47  }
48 }
49 
51 {
52  ::TerminateThread(m_thread_handle, 0);
53 }
54 
56 {
57  DWORD result = ::WaitForSingleObject(m_thread_handle, INFINITE);
58  if (result == WAIT_OBJECT_0)
59  {
60  m_thread_id = 0;
61  }
62  else
63  {
64  // TODO: Error handling!
65  }
66 }
67 
69 {
70  return m_priority;
71 }
72 
74 {
75  // TODO: Thread priority handling.
77  return true;
78 }
79 
81 {
82  m_thread_id = 0;
83  m_thread_handle = ::CreateThread(NULL, 0, ThreadImplWin32::runThread, this, 0, NULL);
84 
85  return m_thread_handle != 0;
86 }
87 
89 {
91 }
92 
93 DWORD WINAPI ThreadImplWin32::runThread(void *arg)
94 {
95  ThreadImplWin32 *self = static_cast<ThreadImplWin32*>(arg);
96 
97  self->m_thread_id = ::GetCurrentThreadId();
98  self->m_thread->runThread();
99 
100  return 0;
101 }
102 
103 }
104 }
ICL_CORE_OS_IMPL_NS::ThreadId ThreadId
Definition: os_thread.h:49
virtual icl_core::ThreadId threadId() const
ThreadImplWin32(Thread *thread, const icl_core::String &description, icl_core::ThreadPriority priority)
virtual bool setPriority(icl_core::ThreadPriority priority)
Contains icl_core::thread::ThreadImpl for Win32 systems.
std::string String
Definition: BaseTypes.h:43
virtual icl_core::ThreadPriority priority() const
Contains icl_core::thread::Thread.
Win32 implementation of the global thread functions.
int32_t ThreadPriority
Definition: os_thread.h:50


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58