📄 connectionpool.h
字号:
#ifndef __CONNECTION_POOL_H__
#define __CONNECTION_POOL_H__
#include <mysql.h>
#include <time.h>
#include "utils.h"
typedef struct _CONNECTION
{
int nID;
time_t nCreationTime;
time_t nLastQueryTime;
time_t nLastIdleTime;
int nQueryCount;
bool bBusy;
MYSQL *pConn;
} CONNECTION;
class ConnectionPool
{
public:
ConnectionPool(const char *sHost, const char *sUser, const char *sPassword, const char *sDatabase, unsigned int nPort, const char *sUnixSocket, unsigned int nClientFlag, int nCapacity, int nIdleTimeout, int nMaxQuery);
~ConnectionPool();
CONNECTION *GetConnection();
void FreeConnection(CONNECTION *pConn);
int GetIdleCount()
{
return nIdlePoolSize;
}
int GetBusyCount()
{
return nBusyPoolSize;
}
int GetIdleTimeout()
{
return nIdleTimeout;
}
void CheckIdle();
bool bStop;
private:
CONNECTION *CreateConnection();
void CloseConnection(CONNECTION *pConn);
void CloseAllConnections();
pthread_mutex_t mutex;
pthread_t WatcherThread;
// MySQL connection properties
char *sHost, *sUsername, *sPassword, *sDatabase, *sUnixSocket;
unsigned int nPort, nClientFlag;
// Connection pool properties
int nCapacity, nIdleTimeout, nMaxQuery;
FIFO *pIdlePool; // Linked list (FIFO)
int nIdlePoolSize;
HashTable *pBusyPool; // Array (hash map)
int nBusyPoolSize;
int nID;
};
#endif // #ifndef __CONNECTION_POOL_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -