/* The pthread_cancel(), pthread_setcancelstate(), and pthread_setcanceltype() functions are defined to be async-cancel safe.  */
int pthread_setcancelstate(int state, int *oldstate)
/* The pthread_cancel(), pthread_setcancelstate(), and pthread_setcanceltype() functions are defined to be async-cancel safe.  */
int pthread_setcancelstate(int state, int *oldstate)
{
    _pthread_data_t *ptd;
    if (rt_thread_self() == NULL) return EINVAL;
    ptd = (_pthread_data_t *)rt_thread_self()->user_data;
    RT_ASSERT(ptd != RT_NULL);
    if ((state == PTHREAD_CANCEL_ENABLE) || (state == PTHREAD_CANCEL_DISABLE))
    {
        if (oldstate)
            *oldstate = ptd->cancelstate;
        ptd->cancelstate = state;
        return 0;
    }
    return EINVAL;
}