2008-01-30 21:59:12 +00:00
|
|
|
/****************************************************************************
|
2018-05-29 13:21:26 -06:00
|
|
|
* libs/libc/pthread/pthread_conddestroy.c
|
2007-02-17 23:21:28 +00: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
|
2007-02-17 23:21:28 +00:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-17 23:21:28 +00: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.
|
2007-02-17 23:21:28 +00:00
|
|
|
*
|
2008-01-30 21:59:12 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2008-01-30 21:59:12 +00:00
|
|
|
/****************************************************************************
|
2007-02-17 23:21:28 +00:00
|
|
|
* Included Files
|
2008-01-30 21:59:12 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2009-12-14 18:39:29 +00:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2007-02-17 23:21:28 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2008-01-30 21:59:12 +00:00
|
|
|
/****************************************************************************
|
2015-10-02 16:30:35 -06:00
|
|
|
* Public Functions
|
2008-01-30 21:59:12 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2008-01-30 21:59:12 +00:00
|
|
|
/****************************************************************************
|
2012-07-14 19:30:31 +00:00
|
|
|
* Name: pthread_cond_destroy
|
2007-02-17 23:21:28 +00:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* A thread can delete condition variables.
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2007-02-17 23:21:28 +00:00
|
|
|
* None
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2021-01-18 20:09:25 +08:00
|
|
|
* OK (0) on success; a (non-negated) errno value on failure. The errno
|
|
|
|
* variable is not set. EBUSY is returned when the implementation has
|
|
|
|
* detected an attempt to destroy the object referenced by cond while
|
|
|
|
* it is referenced. EINVAL is returned when cond is invalid.
|
2007-02-17 23:21:28 +00:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
2008-01-30 21:59:12 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2008-01-30 21:59:12 +00:00
|
|
|
int pthread_cond_destroy(FAR pthread_cond_t *cond)
|
2007-02-17 23:21:28 +00:00
|
|
|
{
|
|
|
|
int ret = OK;
|
2021-01-18 20:09:25 +08:00
|
|
|
int sval = 0;
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2016-06-11 16:42:42 -06:00
|
|
|
sinfo("cond=0x%p\n", cond);
|
2007-02-17 23:21:28 +00:00
|
|
|
|
|
|
|
if (!cond)
|
|
|
|
{
|
|
|
|
ret = EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-10-07 19:59:14 -06:00
|
|
|
/* Destroy the semaphore contained in the structure */
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2021-01-18 20:09:25 +08:00
|
|
|
else
|
2007-02-17 23:21:28 +00:00
|
|
|
{
|
2021-01-18 20:09:25 +08:00
|
|
|
ret = sem_getvalue(&cond->sem, &sval);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ret = -ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (sval < 0)
|
|
|
|
{
|
|
|
|
ret = EBUSY;
|
|
|
|
}
|
|
|
|
else if (sem_destroy(&cond->sem) != OK)
|
|
|
|
{
|
2021-01-28 17:03:22 +08:00
|
|
|
ret = get_errno();
|
2021-01-18 20:09:25 +08:00
|
|
|
}
|
|
|
|
}
|
2007-02-17 23:21:28 +00:00
|
|
|
}
|
|
|
|
|
2016-06-11 16:42:42 -06:00
|
|
|
sinfo("Returning %d\n", ret);
|
2007-02-17 23:21:28 +00:00
|
|
|
return ret;
|
|
|
|
}
|