#include <yangipc/YangIpc.h>
#include <yangutil/sys/YangCTimer.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <pthread.h>
//声明一个Timer
YangCTimer* m_5stimer=NULL;
int g_waitState=0;
//声明一个互斥锁
pthread_mutex_t g_lock ;
//声明一个条件锁
pthread_cond_t g_cond ;
//创建ctrl+c的回调函数,设置b_exit为1,signal通知条件锁在wait处继续执行,此处继续执行会退出程序运行。
static int32_t b_exit = 0;
static void ctrl_c_handler(int s){
printf("\ncaught signal %d, exit.\n",s);
b_exit = 1;
pthread_mutex_lock(&g_lock);
pthread_cond_signal(&g_cond);
pthread_mutex_unlock(&g_lock);
}
static int32_t b_reload = 0;
static void reload_handler(int s){
printf("\ncaught signal %d, reload.\n",s);
b_reload = 1;
}
//timer会定时调用这个函数,函数每次会调用checkAlive方法检查ipc的session是否活跃。
void g_yang_main_doTask(int32_t taskId, void *user) {
if (user == NULL) return;
YangIpc *ipc = (YangIpc*) user;
if (taskId == 5) {
metartc5_jz源码阅读-main.c
于 2023-12-29 22:01:24 首次发布
本文介绍了一个使用C++编写的程序,通过YangIpc库和YangCTimer来创建一个定时任务,该任务会在5秒后执行一次,同时处理Ctrl+C信号并支持热重启。程序中还包含了信号处理函数和多线程同步机制。

最低0.47元/天 解锁文章
5666

被折叠的 条评论
为什么被折叠?



