osthread.h
来自「本源码为移动公司话费查询中间件TUXEDO使用的实例」· C头文件 代码 · 共 116 行
H
116 行
/*******************************************
* File: OSThread.h
*
* DATE: 2001.07.25
* Contains: A thread abstraction
*
*
*/
// OSThread.h
#ifndef __OSTHREAD__LINYOUHAI
#define __OSTHREAD__LINYOUHAI
#ifndef _WIN32
#include <pthread.h>
#endif
#include <assert.h>
#include "SHPP.h"
class OSThread
{
public:
//
// Call before calling any other OSThread function
static void Initialize();
OSThread();
virtual ~OSThread();
//
// Derived classes must implement their own entry function
virtual void Entry();
virtual SInt64 Run() = 0;
Bool16 IsRun(){ return fRunning;}
void Start(Bool16 bJoin = false);
void Join();
void Detach();
void SendStopRequest() { fStopRequested = true; }
void StopAndWaitForThread();
//When making a blocking system call, you can frame it
//with these static function calls to support stop exceptions
// void MakingBlockingCall() { this->CheckForStopRequest(); }
// void BlockingCallReturning() { this->CheckForStopRequest(); }
// void* GetThreadData() { return fThreadData; }
// void SetThreadData(void* inThreadData) { fThreadData = inThreadData; }
// As a convienence to higher levels, each thread has its own date buffer
// static void* GetMainThreadData() { return sMainThreadData; }
// static void SetMainThreadData(void* inData) { sMainThreadData = inData; }
static int GetErrno();
static int TOpen(char *pfn);
static int TWrite(char *pWrite,int nLen);
static int TClose();
// static UInt32 GetCurrentThreadID() { return fThreadID; }
// static OSThread* GetCurrent();
protected:
Bool16 fRunning:1;
private:
void ThrowStopRequest();
void CheckForStopRequest();
static UInt32 sThreadStorageIndex;
Bool16 fStopRequested:1;
Bool16 fCancelThrown:1;
Bool16 fDetached:1;
Bool16 fJoined:1;
#ifndef _WIN32
pthread_t fThreadID;
pthread_attr_t attr;
#else
HANDLE fThreadID;
#endif //_WIN32
void* fThreadData;
static void* sMainThreadData;
static void CallEntry(OSThread* thread);
#ifdef _WIN32
static unsigned long WINAPI
#else
static void*
#endif
_Entry(void* inThread);
static FILE * fb;
#ifndef _WIN32
static pthread_mutex_t counter_mutex;
#else
static HANDLE counter_mutex;
#endif //_WIN32
};
#endif //#define __OSTHREAD__LINYOUHAI
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?