37 lines
749 B
C
37 lines
749 B
C
|
|
#ifndef THREAD_H
|
|||
|
|
#define THREAD_H
|
|||
|
|
|
|||
|
|
|
|||
|
|
#include <functional>
|
|||
|
|
#include <string>
|
|||
|
|
|
|||
|
|
//typedef std::tr1::function<void()> ThreadFunc;
|
|||
|
|
typedef void (*ThreadFunc) (void*);
|
|||
|
|
class Thread
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
explicit Thread(void* pthis,const ThreadFunc&, const std::string& name = std::string());
|
|||
|
|
~Thread();
|
|||
|
|
|
|||
|
|
void start();
|
|||
|
|
void join();
|
|||
|
|
|
|||
|
|
bool started() const { return started_; }
|
|||
|
|
const std::string name() const { return name_; }
|
|||
|
|
static int numCreated() { return numCreated_; }
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
static unsigned int __stdcall startThread(void* thread);
|
|||
|
|
void runInThread();
|
|||
|
|
|
|||
|
|
void* pThis_;
|
|||
|
|
bool started_;
|
|||
|
|
uintptr_t threadId_;
|
|||
|
|
ThreadFunc func_;
|
|||
|
|
std::string name_;
|
|||
|
|
static volatile long numCreated_;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
#endif // THREAD_H
|