* @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
| 1398 | * @see pthread_setcancelstate, pthread_setcanceltype, pthread_cancel |
| 1399 | */ |
| 1400 | void 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 | } |
| 1416 | RTM_EXPORT(pthread_testcancel); |
| 1417 | |
| 1418 | /** |
no test coverage detected