00001 /* 00002 * Copyright (c) 2012 SCHUNK GmbH & Co. KG 00003 * Copyright (c) 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA) 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef UTIL_THREAD_H 00019 #define UTIL_THREAD_H 00020 00021 // ---- local includes ------------------------------------------------------ ; 00022 00023 #include "../Util/Message.h" 00024 00025 // ---- global includes ----------------------------------------------------- ; 00026 00027 // ---- constants ----------------------------------------------------------- ; 00028 00029 // ---- typedefs ------------------------------------------------------------ ; 00030 00031 // ---- class definition ---------------------------------------------------- ; 00032 00033 class CThread : public CMessage 00034 { 00035 00036 private: 00037 00038 // ---- private data ---------------------------------------------------- ; 00039 00040 // ---- private auxiliary functions -------------------------------------- ; 00041 00042 protected: 00043 00044 // ---- protected data -------------------------------------------------- ; 00045 00046 unsigned int m_uiStackSize; 00047 char* m_pcStack; 00048 #if defined (_WIN32) 00049 HANDLE m_hThreadHandle; 00050 #endif 00051 #if defined(__LINUX__) 00052 pthread_t m_hThreadHandle; 00053 #endif 00054 #if defined (__QNX__) 00055 void* m_hThreadHandle; 00056 #endif 00057 bool m_bThreadRunFlag; 00058 bool m_bThreadStopFlag; 00059 00060 // ---- protected auxiliary functions ------------------------------------- ; 00061 00062 public: 00063 00064 // ---- public data ------------------------------------------------------- ; 00065 00066 void* m_pvThreadObject; 00067 void (*m_pfuThreadFunction)(CThread*); 00068 00069 // ---- constructors / destructor ----------------------------------------- ; 00070 00071 // default constructor 00072 CThread(); 00073 // copy constructor 00074 CThread(const CThread& clThread); 00075 // destructor 00076 ~CThread(void); 00077 00078 // ---- operators --------------------------------------------------------- ; 00079 00080 // assignment operator 00081 CThread& operator=(const CThread& clThread); 00082 00083 // ---- query functions --------------------------------------------------- ; 00084 00085 // ---- modify functions -------------------------------------------------- ; 00086 00087 void setThreadStackSize(unsigned int uiSize); 00088 00089 // ---- I/O functions ----------------------------------------------------- ; 00090 00091 // ---- exec functions ---------------------------------------------------- ; 00092 00093 int createThread(void (*fuThreadFunction)(CThread*), void* pThreadObject); 00094 00096 void exitThread(); 00097 00099 void terminateThread(); 00100 00102 bool checkThreadRun(); 00103 00105 bool checkThreadStop(); 00106 }; 00107 00108 #endif