MT#55524 add thread cancel helper macros

Convenience macros to enable and disable thread cancellation

Change-Id: I1c588af83a4c6a45c60b60d941aa446b07e72978
(cherry picked from commit 08a05e76ec)
mr10.5.3
Richard Fuchs 2 years ago
parent bb583c3382
commit 0fa1342a98

@ -52,8 +52,8 @@ void load_thread(void *dummy) {
}
}
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
thread_cancel_enable();
usleep(500000);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
thread_cancel_disable();
}
}

@ -119,9 +119,9 @@ static void sighandler(gpointer x) {
ts.tv_nsec = 0;
while (!rtpe_shutdown) {
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
thread_cancel_enable();
ret = sigtimedwait(&ss, NULL, &ts);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
thread_cancel_disable();
if (ret == -1) {
if (errno == EAGAIN || errno == EINTR)

@ -388,9 +388,9 @@ int poller_poll(struct poller *p, int timeout) {
mutex_unlock(&p->lock);
errno = 0;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
thread_cancel_enable();
ret = epoll_wait(p->fd, evs, sizeof(evs) / sizeof(*evs), timeout);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
thread_cancel_disable();
mutex_lock(&p->lock);
if (errno == EINTR)
@ -585,9 +585,9 @@ void poller_timer_loop(void *d) {
if (sleeptime <= 0)
goto now;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
thread_cancel_enable();
usleep(sleeptime);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
thread_cancel_disable();
continue;

@ -349,6 +349,9 @@ INLINE void thread_create_detach(void (*f)(void *), void *a, const char *name) {
thread_create_detach_prio(f, a, NULL, 0, name);
}
#define thread_cancel_enable() pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL)
#define thread_cancel_disable() pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL)

Loading…
Cancel
Save