240717班级,工业化控制系统,煤矿相关行业,昆仑系统
lzx
2024-11-09 204ed8bff86568e57acae30cd905a4ba70f5f0f0
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
#pragma once
 
#include "MysqlConn.h"
 
class ConnectionPool
{
public:
    static ConnectionPool* getInstance();
 
    shared_ptr<MysqlConn> getMysqlConn();    // ´ÓÊý¾Ý¿âÁ¬½Ó³Ø»ñÈ¡Á¬½Ó
 
    ConnectionPool(const ConnectionPool& other) = delete;
    ConnectionPool& operator=(const ConnectionPool& other) = delete;
 
    ~ConnectionPool();
 
    void description();
 
protected:
    ConnectionPool();   // ¹¹Ô캯Êý
private:
    // ²»ÔÙÐèÒª½âÎöÅäÖÃÎļþµÄº¯Êý
    // bool parseJsonFile();   // ½âÎöÅäÖÃ
 
    void produce();
    void recycle();
    void addConnection();  // Ôö¼ÓÁ¬½ÓÊý
 
    // Ð´ËÀµÄÊý¾Ý¿âÁ¬½Ó²ÎÊý
    string m_ip = "127.0.0.1";
    string m_userName = "root";
    string m_passwd = "123456";
    string m_db = "mayi_kunlun";
    unsigned short m_port = 3306;
 
    int m_max_conn;
    int m_min_conn;
 
    int m_timeout;      // Á¬½Ó³¬Ê±Ê±¼ä
    int max_del_time;   // ×î´óɾ³ýʱ¼ä( Á¬½Ó¿ÕÏÐʱ¼ä³¬¹ýÕâ¸ö,¾Í¸øµ±Ç°Á¬½Ó¹Ø±Õ )
    queue<MysqlConn*> m_connkQueue;   // Á¬½Ó¶ÓÁÐ
    mutex m_mutex;  // »¥³âËø
    condition_variable m_cond;   // Ìõ¼þ±äÁ¿
};