📄 sql_pool.h
字号:
#include <pthread.h>#include <semaphore.h>#include <mysql/mysql.h>#define MAX_WAIT_NUM 1024#define BUSY 0#define IDLE 1#define FLUSH 2struct queue_mem { struct wait_struct *in; struct wait_struct *out; sem_t sem_in; sem_t sem_out;};/* * 数据库连接池的参数 */struct sql_par { char *host; // mysql主机地址 int num; // 连接数目};/* * 数据库连接结构 */struct sql_struct { MYSQL sql; int status; // 连接状态 sem_t sem; // 加锁本结构};/* * 等待队列结构 */struct wait_struct { struct sql_struct *ptr; // 唤醒时将指向获得的mysql连接。 sem_t sem; // 加锁 + 睡眠唤醒机制};int init_sql_pool(void *ptr);MYSQL *get_sql_connection();int ret_sql_connection(MYSQL *sql);int free_sql_pool();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -