-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsession_thread_pool.h
More file actions
62 lines (49 loc) · 1.11 KB
/
session_thread_pool.h
File metadata and controls
62 lines (49 loc) · 1.11 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
56
57
58
59
60
61
62
#ifndef _SESSION_THREAD_POOL_H_
#define _SESSION_THREAD_POOL_H_
#include "common_include.h"
#include "session_thread.h"
#include "session.h"
namespace ftp_server
{
class session_thread_pool
{
private:
int max_num;
public:
session_thread *p_threads;
pthread_cond_t *st_cond;
pthread_mutex_t *st_mutex;
_event_notify *fsm_notify;
public:
session_thread_pool(int thread_num)
{
max_num = thread_num; // 线程池的线程数
p_threads = new session_thread[ max_num ];
st_cond = new pthread_cond_t[ max_num ];
st_mutex = new pthread_mutex_t[ max_num ];
fsm_notify = new _event_notify[ max_num ];
for(int i = 0; i < max_num; i++ )
{
pthread_cond_init(&st_cond[i], NULL);
pthread_mutex_init(&st_mutex[i], NULL);
}
};
~session_thread_pool()
{
stop_running();
for(int i = 0; i < max_num; i++ )
{
pthread_mutex_destroy(&st_mutex[i]);
pthread_cond_destroy(&st_cond[i]);
}
delete[] st_cond;
delete[] st_mutex;
delete[] p_threads;
delete[] fsm_notify;
};
public:
bool start_running();
bool stop_running( bool b_force = false );
};
};
#endif