You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

114 lines
2.0 KiB

#ifndef __BASICTHREAD_H_INCL__
#define __BASICTHREAD_H_INCL__
#define BTH_NO_LOGGING
#ifndef __linux__
#ifndef WIN_PTHREAD
// #define WIN_PTHREAD
#endif
#endif
#ifdef WIN_PTHREAD
#pragma comment(lib, "pthreadVC2.lib")
#endif
#if defined(__linux__) || defined(WIN_PTHREAD)
#include <pthread.h>
#ifdef WIN_PTHREAD
#include <Windows.h>
#endif
#else
// #include <WinSock2.h>
// #include <Windows.h>
#endif
// #pragma message("Debug: Test point riched 2!")
#include "basicLogCollection.h"
typedef enum thredStatus
{
TH_PRE_INIT = 0,
TH_ARMED = 1,
TH_WORKING = 2,
// TH_SLIPS,
TH_ENDED,
TH_EXIT
} thredStatus;
#define DEFAULT_THREAD_SLEEP_TIME 10 // msec
/**
* TODO: Add class description
*
* @author Gagua
*/
class basicThread
{
private:
#ifndef BTH_NO_LOGGING
basicLogCollection * m_pLog;
#endif
#if defined(__linux__) || defined(WIN_PTHREAD)
pthread_t m_sThreadHandler;
static void * m_fThreadEntryPoint(void *);
#else
HANDLE m_hThreadHandle;
DWORD m_dwThreadID;
static DWORD WINAPI m_fThreadEntryPoint(LPVOID lpParameter);
#endif
protected:
thredStatus m_bThreadStatus;
virtual void m_fThreadProc(void);
public:
// Constructor
basicThread();
// Destructor
~basicThread();
virtual bool init(void);
virtual bool uninit(void);
thredStatus getStatus(void)
{
return m_bThreadStatus;
}
void setStatus(thredStatus A)
{
m_bThreadStatus = A;
}
void waitThreadEnd(bool forced = false);
void abort(void);
// Copy constructor
// TODO: Uncomment the copy constructor when you need it.
// basicThread(const basicThread& src);
// Assignment operator
// TODO: Uncomment the assignment operator when you need it.
// basicThread& operator=(const basicThread& src);
};
// Constructor implementation
inline basicThread::basicThread()
{
#ifndef BTH_NO_LOGGING
m_pLog = basicLogCollection::getInstance();
#endif
m_bThreadStatus = TH_PRE_INIT;
}
// Destructor implementation
inline basicThread::~basicThread()
{
waitThreadEnd(true);
}
#endif // __BASICTHREAD_H_INCL__