基于信号量的配置文件热加载实现
对于高并发的服务端来说,
当服务正在运行进,却需要进行配置文件修改,以响应各种业务需求,
这时就需要对服务端进行配置文件的热加载功能。
下面是一种基于信号量的配置文件热加载实现。
1 使用单例模式构建配置文件类
class CConf {
public:
CConf() { };
~CConf() { };
int load_cfg(const string& conf_file);
int reload_cfg();
public:
string _path;
private:
string _worker_timeout;
}
int CConf::load_conf(const string& conf_file) {
_path = conf_file;
_worker_timeout = 从配置文件中读取的数据;
return 0;
}
int CConf::reload_cfg() {
load_conf(_path);
return 0;
}
2 在主线程中进行配置热加载检查
// main.cpp
static bool CONF_RELOAD_FLAG = false;
static void sigusr2_handler(int sig_val)