2016-12-10 23:12:35 +01:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/pthread/pthread_setcancelstate.c
|
2016-12-10 23:12:35 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2016-12-10 23:12:35 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-12-10 23:12:35 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-12-10 23:12:35 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
2021-03-02 14:33:27 +01:00
|
|
|
|
|
|
|
/* These are defined in different header files but must have the same
|
|
|
|
* values.
|
|
|
|
*/
|
2016-12-10 23:12:35 +01:00
|
|
|
|
|
|
|
#if PTHREAD_CANCEL_ENABLE != TASK_CANCEL_ENABLE
|
|
|
|
# error We must have PTHREAD_CANCEL_ENABLE == TASK_CANCEL_ENABLE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PTHREAD_CANCEL_DISABLE != TASK_CANCEL_DISABLE
|
|
|
|
# error We must have PTHREAD_CANCEL_DISABLE == TASK_CANCEL_DISABLE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: pthread_setcancelstate
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The pthread_setcancelstate() function atomically both sets the calling
|
|
|
|
* thread's cancelability state to the indicated state and returns the
|
|
|
|
* previous cancelability state at the location referenced by oldstate.
|
|
|
|
* Legal values for state are PTHREAD_CANCEL_ENABLE and
|
|
|
|
* PTHREAD_CANCEL_DISABLE.
|
|
|
|
*
|
|
|
|
* The cancelability state and type of any newly created threads,
|
|
|
|
* including the thread in which main() was first invoked, are
|
|
|
|
* PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_DEFERRED respectively.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int pthread_setcancelstate(int state, FAR int *oldstate)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* task_setcancelstate() can do this */
|
|
|
|
|
|
|
|
ret = task_setcancelstate(state, oldstate);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2018-01-31 00:57:36 +01:00
|
|
|
ret = get_errno();
|
2016-12-10 23:12:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|