-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCThreadPool.h
More file actions
56 lines (46 loc) · 1 KB
/
CThreadPool.h
File metadata and controls
56 lines (46 loc) · 1 KB
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
52
53
54
55
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: CThreadPool.h
* Author: hxw
*
* Created on September 18, 2017, 4:59 PM
*/
#ifndef CTHREADPOOL_H
#define CTHREADPOOL_H
#include <vector>
#include <mutex>
#include <condition_variable>
class CThread_t;
class Runable_t;
typedef void (*callback_t)(void *);
struct Task_t {
callback_t function;
callback_t destroy_func;
void *argument;
};
class CThreadPool_t {
public:
CThreadPool_t();
int start(int thread_count, int queue_size);
int destroy();
int add(callback_t func, void *arg);
int add(callback_t call_func, callback_t destroy_func, void *arg);
Task_t get();
private:
std::mutex lock_;
std::condition_variable notify_;
CThread_t *threads_;
Task_t *task_;
int thread_count_;
int queue_size_;
int task_count_;
int head_;
int tail_;
bool started_;
bool shudown_;
};
#endif /* CTHREADPOOL_H */