ThreadImplWin32.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 #include "ThreadImplWin32.h"
00024 
00025 #include "Thread.h"
00026 
00027 namespace icl_core {
00028 namespace logging {
00029 
00030 ThreadImplWin32::ThreadImplWin32(Thread *thread, icl_core::ThreadPriority priority)
00031   : m_thread_handle(0),
00032     m_thread(thread)
00033 {
00034 }
00035 
00036 ThreadImplWin32::~ThreadImplWin32()
00037 {
00038   if (m_thread_handle != 0)
00039   {
00040     ::CloseHandle(m_thread_handle);
00041   }
00042 }
00043 
00044 void ThreadImplWin32::join()
00045 {
00046   DWORD result = ::WaitForSingleObject(m_thread_handle, INFINITE);
00047   if (result == WAIT_OBJECT_0)
00048   {
00049     m_thread_id = 0;
00050   }
00051   else
00052   {
00053     // TODO: Error handling!
00054   }
00055 }
00056 
00057 bool ThreadImplWin32::start()
00058 {
00059   m_thread_id = 0;
00060   m_thread_handle = ::CreateThread(NULL, 0, ThreadImplWin32::runThread, this, 0, NULL);
00061 
00062   return m_thread_handle != 0;
00063 }
00064 
00065 DWORD WINAPI ThreadImplWin32::runThread(void *arg)
00066 {
00067   ThreadImplWin32 *self = static_cast<ThreadImplWin32*>(arg);
00068 
00069   self->m_thread_id = ::GetCurrentThreadId();
00070   self->m_thread->runThread();
00071 
00072   return 0;
00073 }
00074 
00075 }
00076 }


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:24