未验证 提交 268baa3d 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #1999 from taosdata/patch/exiting

td-337: add error log when have to call pthread_cancel
...@@ -148,6 +148,10 @@ static void taosDeleteTimer(void *tharg) { ...@@ -148,6 +148,10 @@ static void taosDeleteTimer(void *tharg) {
timer_delete(*pTimer); timer_delete(*pTimer);
} }
static pthread_t timerThread;
static timer_t timerId;
static volatile bool stopTimer = false;
void *taosProcessAlarmSignal(void *tharg) { void *taosProcessAlarmSignal(void *tharg) {
// Block the signal // Block the signal
sigset_t sigset; sigset_t sigset;
...@@ -156,7 +160,6 @@ void *taosProcessAlarmSignal(void *tharg) { ...@@ -156,7 +160,6 @@ void *taosProcessAlarmSignal(void *tharg) {
sigprocmask(SIG_BLOCK, &sigset, NULL); sigprocmask(SIG_BLOCK, &sigset, NULL);
void (*callback)(int) = tharg; void (*callback)(int) = tharg;
static timer_t timerId;
struct sigevent sevent = {{0}}; struct sigevent sevent = {{0}};
#ifdef _ALPINE #ifdef _ALPINE
...@@ -187,7 +190,7 @@ void *taosProcessAlarmSignal(void *tharg) { ...@@ -187,7 +190,7 @@ void *taosProcessAlarmSignal(void *tharg) {
} }
int signo; int signo;
while (1) { while (!stopTimer) {
if (sigwait(&sigset, &signo)) { if (sigwait(&sigset, &signo)) {
uError("Failed to wait signal: number %d", signo); uError("Failed to wait signal: number %d", signo);
continue; continue;
...@@ -202,7 +205,6 @@ void *taosProcessAlarmSignal(void *tharg) { ...@@ -202,7 +205,6 @@ void *taosProcessAlarmSignal(void *tharg) {
return NULL; return NULL;
} }
static pthread_t timerThread;
int taosInitTimer(void (*callback)(int), int ms) { int taosInitTimer(void (*callback)(int), int ms) {
pthread_attr_t tattr; pthread_attr_t tattr;
...@@ -217,7 +219,7 @@ int taosInitTimer(void (*callback)(int), int ms) { ...@@ -217,7 +219,7 @@ int taosInitTimer(void (*callback)(int), int ms) {
} }
void taosUninitTimer() { void taosUninitTimer() {
pthread_cancel(timerThread); stopTimer = true;
pthread_join(timerThread, NULL); pthread_join(timerThread, NULL);
} }
......
...@@ -267,8 +267,10 @@ static void httpStopThread(HttpThread* pThread) { ...@@ -267,8 +267,10 @@ static void httpStopThread(HttpThread* pThread) {
struct epoll_event event = { .events = EPOLLIN }; struct epoll_event event = { .events = EPOLLIN };
eventfd_t fd = eventfd(1, 0); eventfd_t fd = eventfd(1, 0);
if (fd == -1) { if (fd == -1) {
httpError("%s, failed to create eventfd, will call pthread_cancel instead, which may result in data corruption: %s", pThread->label, strerror(errno));
pthread_cancel(pThread->thread); pthread_cancel(pThread->thread);
} else if (epoll_ctl(pThread->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { } else if (epoll_ctl(pThread->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) {
httpError("%s, failed to call epoll_ctl, will call pthread_cancel instead, which may result in data corruption: %s", pThread->label, strerror(errno));
pthread_cancel(pThread->thread); pthread_cancel(pThread->thread);
} }
......
...@@ -147,8 +147,10 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) { ...@@ -147,8 +147,10 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) {
struct epoll_event event = { .events = EPOLLIN }; struct epoll_event event = { .events = EPOLLIN };
eventfd_t fd = eventfd(1, 0); eventfd_t fd = eventfd(1, 0);
if (fd == -1) { if (fd == -1) {
tError("%s, failed to create eventfd, will call pthread_cancel instead, which may result in data corruption: %s", pThreadObj->label, strerror(errno));
pthread_cancel(pThreadObj->thread); pthread_cancel(pThreadObj->thread);
} else if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { } else if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) {
tError("%s, failed to call epoll_ctl, will call pthread_cancel instead, which may result in data corruption: %s", pThreadObj->label, strerror(errno));
pthread_cancel(pThreadObj->thread); pthread_cancel(pThreadObj->thread);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册