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.
96 lines
2.3 KiB
96 lines
2.3 KiB
#ifndef __BASICTHREAD_H_INCL__
|
|
#define __BASICTHREAD_H_INCL__
|
|
|
|
#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
|
|
|
|
|
|
#include "basicLogCollection.h"
|
|
|
|
typedef enum thredStatus{
|
|
TH_PRE_INIT = 0,
|
|
TH_ARMED = 1,
|
|
TH_WORKING = 2,
|
|
TH_SLIPS = 3,
|
|
TH_ENDED = 4,
|
|
TH_EXIT = 5
|
|
} thredStatus;
|
|
|
|
#define DEFAULT_THREAD_SLEEP_TIME 10 // msec
|
|
|
|
/**
|
|
* TODO: Add class description
|
|
*
|
|
* @author Gagua
|
|
*/
|
|
class basicThread {
|
|
private:
|
|
|
|
#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 );
|
|
basicLogCollection *m_pLog;
|
|
public:
|
|
// Constructor
|
|
basicThread();
|
|
|
|
// Destructor
|
|
~basicThread();
|
|
|
|
virtual bool init( void );
|
|
thredStatus getStatus( void ){ return m_bThreadStatus; };
|
|
void setStatus( thredStatus A ){ m_bThreadStatus = A; };
|
|
void waitThreadEnd( bool forced = false );
|
|
// 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);
|
|
};
|
|
// TODO: Uncomment the copy constructor when you need it.
|
|
//inline basicThread::basicThread(const basicThread& src)
|
|
//{
|
|
// // TODO: copy
|
|
//}
|
|
|
|
// TODO: Uncomment the assignment operator when you need it.
|
|
//inline basicThread& basicThread::operator=(const basicThread& rhs)
|
|
//{
|
|
// if (this == &rhs) {
|
|
// return *this;
|
|
// }
|
|
//
|
|
// // TODO: assignment
|
|
//
|
|
// return *this;
|
|
//}
|
|
|
|
#endif // __BASICTHREAD_H_INCL__
|