2012-11-10 17:06:01 +01:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/semaphore/sem_getvalue.c
|
2012-11-10 17:06:01 +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
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-10 17:06:01 +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.
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2017-10-03 20:51:15 +02:00
|
|
|
#include <nuttx/semaphore.h>
|
2012-11-10 17:06:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-10-03 20:51:15 +02:00
|
|
|
* Public Functions
|
2012-11-10 17:06:01 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-17 15:56:21 +02:00
|
|
|
* Name: nxsem_get_value
|
2017-10-03 20:51:15 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function updates the location referenced by 'sval' argument to
|
|
|
|
* have the value of the semaphore referenced by 'sem' without effecting
|
|
|
|
* the state of the semaphore. The updated value represents the actual
|
|
|
|
* semaphore value that occurred at some unspecified time during the call,
|
|
|
|
* but may not reflect the actual value of the semaphore when it is
|
|
|
|
* returned to the calling task.
|
|
|
|
*
|
2020-07-03 17:53:13 +02:00
|
|
|
* If 'sem' is locked, then the object to which 'sval' points shall either
|
|
|
|
* be zero or a negative number whose absolute value represents the number
|
2017-10-03 20:51:15 +02:00
|
|
|
* of tasks waiting for the semaphore.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-10-03 20:51:15 +02:00
|
|
|
* sem - Semaphore descriptor
|
|
|
|
* sval - Buffer by which the value is returned
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-10-03 20:51:15 +02:00
|
|
|
* This is an internal OS interface and should not be used by applications.
|
|
|
|
* It follows the NuttX internal error return policy: Zero (OK) is
|
|
|
|
* returned on success. A negated errno value is returned on failure.
|
|
|
|
*
|
2012-11-10 17:06:01 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-17 15:56:21 +02:00
|
|
|
int nxsem_get_value(FAR sem_t *sem, FAR int *sval)
|
2017-10-03 20:51:15 +02:00
|
|
|
{
|
2018-02-06 16:13:16 +01:00
|
|
|
if (sem != NULL && sval != NULL)
|
2017-10-03 20:51:15 +02:00
|
|
|
{
|
|
|
|
*sval = sem->semcount;
|
|
|
|
return OK;
|
|
|
|
}
|
2012-11-10 17:06:01 +01:00
|
|
|
|
2017-10-03 20:51:15 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-11-10 17:06:01 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: sem_getvalue
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function updates the location referenced by 'sval' argument to
|
|
|
|
* have the value of the semaphore referenced by 'sem' without effecting
|
|
|
|
* the state of the semaphore. The updated value represents the actual
|
|
|
|
* semaphore value that occurred at some unspecified time during the call,
|
|
|
|
* but may not reflect the actual value of the semaphore when it is
|
|
|
|
* returned to the calling task.
|
|
|
|
*
|
2020-07-03 17:53:13 +02:00
|
|
|
* If 'sem' is locked, then the object to which 'sval' points shall either
|
|
|
|
* be zero or a negative number whose absolute value represents the number
|
2012-11-10 17:06:01 +01:00
|
|
|
* of tasks waiting for the semaphore.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2012-11-10 17:06:01 +01:00
|
|
|
* sem - Semaphore descriptor
|
|
|
|
* sval - Buffer by which the value is returned
|
|
|
|
*
|
2017-10-03 20:51:15 +02:00
|
|
|
* This returns zero (OK) if successful. Otherwise, -1 (ERROR) is
|
|
|
|
* returned and the errno value is set appropriately.
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int sem_getvalue(FAR sem_t *sem, FAR int *sval)
|
|
|
|
{
|
2017-10-03 20:51:15 +02:00
|
|
|
int ret;
|
|
|
|
|
2020-05-17 15:56:21 +02:00
|
|
|
ret = nxsem_get_value(sem, sval);
|
2017-10-03 20:51:15 +02:00
|
|
|
if (ret < 0)
|
2012-11-10 17:06:01 +01:00
|
|
|
{
|
2017-10-03 20:51:15 +02:00
|
|
|
set_errno(-ret);
|
|
|
|
ret = ERROR;
|
2012-11-10 17:06:01 +01:00
|
|
|
}
|
2017-10-03 20:51:15 +02:00
|
|
|
|
|
|
|
return ret;
|
2012-11-10 17:06:01 +01:00
|
|
|
}
|