-
Notifications
You must be signed in to change notification settings - Fork 5
/
Thread.h
51 lines (42 loc) · 1.05 KB
/
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
50
51
/*************************************************************************
> File Name: Thread.h
> Author: zhangfeng
> Mail: [email protected]
> Created Time: Wed 16 Oct 2019 12:19:59 PM CST
> Target:
************************************************************************/
#ifndef _THREAD_H
#define _THREAD_H
#include "noncopyable.h"
#include <functional>
#include <pthread.h>
#include <memory>
#include <iostream>
class ThreadPool;
typedef std::function<void* (void*)> TaskFunc;
typedef void* TaskArgs;
struct ThreadTask {
TaskFunc taskFunc_;
TaskArgs taskArgs_;
};
class Thread {
public:
Thread(pthread_cond_t *cond, pthread_mutex_t *mutex, std::shared_ptr<ThreadPool> threadHolder);
~Thread();
void Start();
void Shut();
bool IsJoin() {return joined_;}
bool IsAlive();
pthread_t GetPid() {
return pid_;
}
private:
bool running_;
bool joined_;
bool shutDown_;
pthread_t pid_;
pthread_mutex_t *mutex_;
pthread_cond_t *cond_;
std::shared_ptr<ThreadPool> threadHolder_;
};
#endif