-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy paththread.h
49 lines (38 loc) · 814 Bytes
/
thread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef __YDX_THREAD_H__
#define __YDX_THREAD_H__
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <string>
#include <pthread.h>
#include "types.h"
#include "ydx_atomic.h"
namespace ydx
{
class Thread : boost::noncopyable
{
public:
typedef boost::function<void ()> ThreadFunc;
explicit Thread(const ThreadFunc&, const std::string& name = "ydxlib_thread");
~Thread();
void start();
int join();
pid_t tid() const { return *tid_; }
bool started() const
{
return started_;
}
private:
void setDefaultName();
private:
bool started_;
bool joined_;
pthread_t pthreadId_;
boost::shared_ptr<pid_t> tid_;
ThreadFunc func_;
std::string name_;
static AtomicInt32 numCreated_;
};
}
#endif