GenericThread.cppGo to the documentation of this file.00001 /* 00002 * Copyright (c) 2000-2003 Barak Weichselbaum <barak@komodia.com> 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00015 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00016 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00017 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00018 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00019 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00020 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00021 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00022 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00023 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00024 * SUCH DAMAGE. 00025 * 00026 * Contact info: 00027 * ------------- 00028 * 00029 * Site: http://www.komodia.com 00030 * Main contact: barak@komodia.com 00031 * For custom projects, 00032 * consulting, or other 00033 * paid services: sales@komodia.com 00034 */ 00035 00036 #include "stdafx.h" 00037 #include "GenericThread.h" 00038 00039 #include "ErrorHandlerMacros.h" 00040 #include "OSManager.h" 00041 00042 #ifdef _MEMORY_DEBUG 00043 #define new DEBUG_NEW 00044 #define malloc DEBUG_MALLOC 00045 static char THIS_FILE[] = __FILE__; 00046 #endif 00047 00048 KOMODIA_NAMESPACE_START 00049 00050 #define CGenericThread_Class "CGenericThread" 00051 00052 CGenericThread::CGenericThread(LPGenericThreadProc pThreadProc) : CErrorHandler(), 00053 m_pThreadProc(pThreadProc), 00054 m_dwThreadID(0), 00055 m_pData(NULL), 00056 m_aThreadStatus(tsError), 00057 m_pCSection(NULL), 00058 m_bAutoDelete(FALSE), 00059 m_bBruteTermination(TRUE) 00060 { 00061 //Set our name 00062 SetName(CGenericThread_Class); 00063 00064 //Create the critical section 00065 m_pCSection=COSManager::CreateCriticalSection(); 00066 } 00067 00068 CGenericThread::~CGenericThread() 00069 { 00070 try 00071 { 00072 delete m_pCSection; 00073 } 00074 ERROR_HANDLER("~CGenericThread") 00075 } 00076 00077 DWORD CGenericThread::GetThreadID()const 00078 { 00079 return m_dwThreadID; 00080 } 00081 00082 LPVOID CGenericThread::GetData()const 00083 { 00084 return m_pData; 00085 } 00086 00087 BOOL CGenericThread::Start(LPVOID pData) 00088 { 00089 //Save the data 00090 m_pData=pData; 00091 00092 //Done 00093 return TRUE; 00094 } 00095 00096 void CGenericThread::SetThreadStatus(ThreadStatus aStatus) 00097 { 00098 try 00099 { 00100 //Enter the CS 00101 CCriticalAutoRelease aRelease(m_pCSection); 00102 00103 //Set it 00104 m_aThreadStatus=aStatus; 00105 } 00106 ERROR_HANDLER("SetThreadStatus") 00107 } 00108 00109 CGenericThread::ThreadStatus CGenericThread::GetThreadStatus() const 00110 { 00111 return m_aThreadStatus; 00112 } 00113 00114 CGenericThread::LPGenericThreadProc CGenericThread::GetThreadProc()const 00115 { 00116 return m_pThreadProc; 00117 } 00118 00119 void CGenericThread::SetAutoDelete(BOOL bAuto) 00120 { 00121 m_bAutoDelete=bAuto; 00122 } 00123 00124 BOOL CGenericThread::GetAutoDelete()const 00125 { 00126 return m_bAutoDelete; 00127 } 00128 00129 void CGenericThread::SetBruteTermination(BOOL bBrute) 00130 { 00131 m_bBruteTermination=bBrute; 00132 } 00133 00134 BOOL CGenericThread::GetBruteTermination()const 00135 { 00136 return m_bBruteTermination; 00137 } 00138 00139 KOMODIA_NAMESPACE_END |