MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pthread_testcancel

Function pthread_testcancel

components/libc/posix/pthreads/pthread.c:1400–1415  ·  view source on GitHub ↗

* @brief Explicitly checks for pending cancellation requests in the calling thread. * * The `pthread_testcancel` function allows a thread to determine if it has a pending * cancellation request. If a cancellation request is pending and the thread's cancelability * state is set to `PTHREAD_CANCEL_ENABLE`, the thread will terminate immediately. * * @note * - This function is a cancellation

Source from the content-addressed store, hash-verified

1398 * @see pthread_setcancelstate, pthread_setcanceltype, pthread_cancel
1399 */
1400void pthread_testcancel(void)
1401{
1402 int cancel = 0;
1403 _pthread_data_t *ptd;
1404
1405 if (rt_thread_self() == NULL) return;
1406
1407 /* get pthread data from pthread_data of thread */
1408 ptd = (_pthread_data_t *)rt_thread_self()->pthread_data;
1409 RT_ASSERT(ptd != RT_NULL);
1410
1411 if (ptd->cancelstate == PTHREAD_CANCEL_ENABLE)
1412 cancel = ptd->canceled;
1413 if (cancel)
1414 pthread_exit((void *)PTHREAD_CANCELED);
1415}
1416RTM_EXPORT(pthread_testcancel);
1417
1418/**

Callers 1

searchFunction · 0.85

Calls 2

rt_thread_selfFunction · 0.85
pthread_exitFunction · 0.85

Tested by

no test coverage detected