2014-09-28 10:15:49 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* include/nuttx/semaphore.h
|
|
|
|
|
*
|
2020-03-29 11:56:18 -03: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
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
2014-09-28 10:15:49 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef __INCLUDE_NUTTX_SEMAPHORE_H
|
|
|
|
|
#define __INCLUDE_NUTTX_SEMAPHORE_H
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
2018-08-27 06:07:50 -06:00
|
|
|
#include <errno.h>
|
2014-09-28 10:15:49 -06:00
|
|
|
#include <semaphore.h>
|
|
|
|
|
|
2016-01-21 11:54:26 -06:00
|
|
|
#include <nuttx/clock.h>
|
2014-09-28 10:15:49 -06:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Pre-processor Definitions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2021-12-01 23:40:16 +08:00
|
|
|
/* Initializers */
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
2023-05-20 06:32:34 +08:00
|
|
|
# if CONFIG_SEM_PREALLOCHOLDERS > 0
|
2023-01-28 23:02:52 +08:00
|
|
|
/* semcount, flags, waitlist, hhead */
|
2022-09-19 18:17:14 +08:00
|
|
|
|
2023-05-20 06:32:34 +08:00
|
|
|
# define NXSEM_INITIALIZER(c, f) \
|
|
|
|
|
{(c), (f), SEM_WAITLIST_INITIALIZER, NULL}
|
|
|
|
|
# else
|
2023-01-28 23:02:52 +08:00
|
|
|
/* semcount, flags, waitlist, holder[2] */
|
2022-09-19 18:17:14 +08:00
|
|
|
|
2023-05-20 06:32:34 +08:00
|
|
|
# define NXSEM_INITIALIZER(c, f) \
|
2023-04-17 19:57:21 +08:00
|
|
|
{(c), (f), SEM_WAITLIST_INITIALIZER, SEMHOLDER_INITIALIZER}
|
2023-05-20 06:32:34 +08:00
|
|
|
# endif
|
2021-12-01 23:40:16 +08:00
|
|
|
#else /* CONFIG_PRIORITY_INHERITANCE */
|
2023-01-28 23:02:52 +08:00
|
|
|
/* semcount, flags, waitlist */
|
2022-09-19 18:17:14 +08:00
|
|
|
|
2021-12-01 23:40:16 +08:00
|
|
|
# define NXSEM_INITIALIZER(c, f) \
|
2023-05-20 06:32:34 +08:00
|
|
|
{(c), (f), SEM_WAITLIST_INITIALIZER}
|
2021-12-01 23:40:16 +08:00
|
|
|
#endif /* CONFIG_PRIORITY_INHERITANCE */
|
|
|
|
|
|
2014-09-28 10:15:49 -06:00
|
|
|
/****************************************************************************
|
2015-08-01 07:30:23 -06:00
|
|
|
* Public Type Definitions
|
2014-09-28 10:15:49 -06:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-09-28 13:02:36 -06:00
|
|
|
#ifdef CONFIG_FS_NAMED_SEMAPHORES
|
2014-09-28 10:15:49 -06:00
|
|
|
/* This is the named semaphore inode */
|
|
|
|
|
|
2014-09-28 15:58:56 -06:00
|
|
|
struct inode;
|
2014-09-28 14:35:17 -06:00
|
|
|
struct nsem_inode_s
|
2014-09-28 10:15:49 -06:00
|
|
|
{
|
2016-11-02 14:24:16 -06:00
|
|
|
/* This must be the first element of the structure. In sem_close() this
|
|
|
|
|
* structure must be cast compatible with sem_t.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-11-02 09:05:18 -06:00
|
|
|
sem_t ns_sem; /* The contained semaphore */
|
|
|
|
|
|
2016-11-02 18:21:46 -06:00
|
|
|
/* Inode payload unique to named semaphores. */
|
2014-09-28 15:58:56 -06:00
|
|
|
|
2015-10-23 07:09:25 +08:00
|
|
|
FAR struct inode *ns_inode; /* Containing inode */
|
2014-09-28 10:15:49 -06:00
|
|
|
};
|
2014-09-28 13:02:36 -06:00
|
|
|
#endif
|
2014-09-28 10:15:49 -06:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Data
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#else
|
|
|
|
|
#define EXTERN extern
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Function Prototypes
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2015-08-01 07:30:23 -06:00
|
|
|
/****************************************************************************
|
2017-10-03 12:51:15 -06:00
|
|
|
* Name: nxsem_init
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
2019-09-08 15:59:14 -06:00
|
|
|
* This function initializes the UNNAMED semaphore sem. Following a
|
2017-10-03 12:51:15 -06:00
|
|
|
* successful call to nxsem_init(), the semaphore may be used in subsequent
|
2017-10-03 15:35:24 -06:00
|
|
|
* calls to nxsem_wait(), nxsem_post(), and nxsem_trywait(). The semaphore
|
2017-10-03 12:51:15 -06:00
|
|
|
* remains usable until it is destroyed.
|
|
|
|
|
*
|
|
|
|
|
* Only sem itself may be used for performing synchronization. The result
|
|
|
|
|
* of referring to copies of sem in calls to sem_wait(), sem_trywait(),
|
|
|
|
|
* sem_post(), and sem_destroy() is undefined.
|
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2017-10-03 12:51:15 -06:00
|
|
|
* sem - Semaphore to be initialized
|
|
|
|
|
* pshared - Process sharing (not used)
|
|
|
|
|
* value - Semaphore initialization value
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-03 15:35:24 -06:00
|
|
|
* This is an internal OS interface and should not be used by applications.
|
2017-10-03 12:51:15 -06:00
|
|
|
* It follows the NuttX internal error return policy: Zero (OK) is
|
|
|
|
|
* returned on success. A negated errno value is returned on failure.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxsem_init(FAR sem_t *sem, int pshared, unsigned int value);
|
|
|
|
|
|
2017-10-03 15:35:24 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_destroy
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function is used to destroy the un-named semaphore indicated by
|
|
|
|
|
* 'sem'. Only a semaphore that was created using nxsem_init() may be
|
2020-03-29 11:56:18 -03:00
|
|
|
* destroyed using nxsem_destroy(); the effect of calling nxsem_destroy()
|
|
|
|
|
* with a named semaphore is undefined. The effect of subsequent use of
|
|
|
|
|
* the semaphore sem is undefined until sem is re-initialized by another
|
|
|
|
|
* call to nxsem_init().
|
2017-10-03 15:35:24 -06:00
|
|
|
*
|
|
|
|
|
* The effect of destroying a semaphore upon which other processes are
|
|
|
|
|
* currently blocked is undefined.
|
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2017-10-03 15:35:24 -06:00
|
|
|
* sem - Semaphore to be destroyed.
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-03 15:35:24 -06: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.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2020-01-02 10:49:34 -06:00
|
|
|
int nxsem_destroy(FAR sem_t *sem);
|
2017-10-04 15:22:27 -06:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_wait
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function attempts to lock the semaphore referenced by 'sem'. If
|
|
|
|
|
* the semaphore value is (<=) zero, then the calling task will not return
|
|
|
|
|
* until it successfully acquires the lock.
|
|
|
|
|
*
|
|
|
|
|
* This is an internal OS interface. It is functionally equivalent to
|
|
|
|
|
* sem_wait except that:
|
|
|
|
|
*
|
2019-08-23 11:57:35 -06:00
|
|
|
* - It is not a cancellation point, and
|
2017-10-04 15:22:27 -06:00
|
|
|
* - It does not modify the errno value.
|
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2017-10-04 15:22:27 -06:00
|
|
|
* sem - Semaphore descriptor.
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-04 15:22:27 -06: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.
|
|
|
|
|
* Possible returned errors:
|
|
|
|
|
*
|
2017-10-05 07:59:06 -06:00
|
|
|
* EINVAL - Invalid attempt to get the semaphore
|
|
|
|
|
* EINTR - The wait was interrupted by the receipt of a signal.
|
2017-10-04 15:22:27 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxsem_wait(FAR sem_t *sem);
|
2017-10-03 15:35:24 -06:00
|
|
|
|
2017-10-05 07:59:06 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_trywait
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function locks the specified semaphore only if the semaphore is
|
|
|
|
|
* currently not locked. Otherwise, it locks the semaphore. In either
|
|
|
|
|
* case, the call returns without blocking.
|
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2017-10-05 07:59:06 -06:00
|
|
|
* sem - the semaphore descriptor
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-05 07:59:06 -06: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.
|
|
|
|
|
* Possible returned errors:
|
|
|
|
|
*
|
|
|
|
|
* EINVAL - Invalid attempt to get the semaphore
|
|
|
|
|
* EAGAIN - The semaphore is not available.
|
|
|
|
|
*
|
|
|
|
|
* Assumptions:
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxsem_trywait(FAR sem_t *sem);
|
|
|
|
|
|
2017-10-05 07:24:54 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_timedwait
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function will lock the semaphore referenced by sem as in the
|
|
|
|
|
* sem_wait() function. However, if the semaphore cannot be locked without
|
|
|
|
|
* waiting for another process or thread to unlock the semaphore by
|
|
|
|
|
* performing a sem_post() function, this wait will be terminated when the
|
|
|
|
|
* specified timeout expires.
|
|
|
|
|
*
|
|
|
|
|
* The timeout will expire when the absolute time specified by abstime
|
|
|
|
|
* passes, as measured by the clock on which timeouts are based (that is,
|
|
|
|
|
* when the value of that clock equals or exceeds abstime), or if the
|
|
|
|
|
* absolute time specified by abstime has already been passed at the
|
|
|
|
|
* time of the call.
|
|
|
|
|
*
|
|
|
|
|
* This is an internal OS interface. It is functionally equivalent to
|
|
|
|
|
* sem_wait except that:
|
|
|
|
|
*
|
2019-08-23 11:57:35 -06:00
|
|
|
* - It is not a cancellation point, and
|
2017-10-05 07:24:54 -06:00
|
|
|
* - It does not modify the errno value.
|
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2017-10-05 07:24:54 -06:00
|
|
|
* sem - Semaphore object
|
|
|
|
|
* abstime - The absolute time to wait until a timeout is declared.
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-05 07:24:54 -06: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.
|
|
|
|
|
* That may be one of:
|
|
|
|
|
*
|
|
|
|
|
* EINVAL The sem argument does not refer to a valid semaphore. Or the
|
|
|
|
|
* thread would have blocked, and the abstime parameter specified
|
|
|
|
|
* a nanoseconds field value less than zero or greater than or
|
|
|
|
|
* equal to 1000 million.
|
|
|
|
|
* ETIMEDOUT The semaphore could not be locked before the specified timeout
|
|
|
|
|
* expired.
|
|
|
|
|
* EDEADLK A deadlock condition was detected.
|
|
|
|
|
* EINTR A signal interrupted this function.
|
2020-03-29 11:56:18 -03:00
|
|
|
* ECANCELED May be returned if the thread is canceled while waiting.
|
2017-10-05 07:24:54 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxsem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime);
|
|
|
|
|
|
2020-07-27 13:46:03 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_clockwait
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function will lock the semaphore referenced by sem as in the
|
|
|
|
|
* sem_wait() function. However, if the semaphore cannot be locked without
|
|
|
|
|
* waiting for another process or thread to unlock the semaphore by
|
|
|
|
|
* performing a sem_post() function, this wait will be terminated when the
|
|
|
|
|
* specified timeout expires.
|
|
|
|
|
*
|
|
|
|
|
* The timeout will expire when the absolute time specified by abstime
|
|
|
|
|
* passes, as measured by the clock on which timeouts are based (that is,
|
|
|
|
|
* when the value of that clock equals or exceeds abstime), or if the
|
|
|
|
|
* absolute time specified by abstime has already been passed at the
|
|
|
|
|
* time of the call.
|
|
|
|
|
*
|
|
|
|
|
* This is an internal OS interface. It is functionally equivalent to
|
|
|
|
|
* sem_wait except that:
|
|
|
|
|
*
|
|
|
|
|
* - It is not a cancellation point, and
|
|
|
|
|
* - It does not modify the errno value.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* sem - Semaphore object
|
|
|
|
|
* clockid - The timing source to use in the conversion
|
|
|
|
|
* abstime - The absolute time to wait until a timeout is declared.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* 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.
|
|
|
|
|
* That may be one of:
|
|
|
|
|
*
|
|
|
|
|
* EINVAL The sem argument does not refer to a valid semaphore. Or the
|
|
|
|
|
* thread would have blocked, and the abstime parameter specified
|
|
|
|
|
* a nanoseconds field value less than zero or greater than or
|
|
|
|
|
* equal to 1000 million.
|
|
|
|
|
* ETIMEDOUT The semaphore could not be locked before the specified timeout
|
|
|
|
|
* expired.
|
|
|
|
|
* EDEADLK A deadlock condition was detected.
|
|
|
|
|
* EINTR A signal interrupted this function.
|
|
|
|
|
* ECANCELED May be returned if the thread is canceled while waiting.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxsem_clockwait(FAR sem_t *sem, clockid_t clockid,
|
|
|
|
|
FAR const struct timespec *abstime);
|
|
|
|
|
|
2017-10-03 12:51:15 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_tickwait
|
2015-08-01 07:30:23 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function is a lighter weight version of sem_timedwait(). It is
|
|
|
|
|
* non-standard and intended only for use within the RTOS.
|
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2015-08-01 07:30:23 -06:00
|
|
|
* sem - Semaphore object
|
2015-08-01 14:57:31 -06:00
|
|
|
* delay - Ticks to wait from the start time until the semaphore is
|
|
|
|
|
* posted. If ticks is zero, then this function is equivalent
|
|
|
|
|
* to sem_trywait().
|
2015-08-01 07:30:23 -06:00
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-03 12:51:15 -06:00
|
|
|
* This is an internal OS interface, not available to applications, and
|
|
|
|
|
* hence follows the NuttX internal error return policy: Zero (OK) is
|
2020-03-29 11:56:18 -03:00
|
|
|
* returned on success. A negated errno value is returned on failure:
|
|
|
|
|
*
|
|
|
|
|
* -ETIMEDOUT is returned on the timeout condition.
|
|
|
|
|
* -ECANCELED may be returned if the thread is canceled while waiting.
|
2017-10-03 12:51:15 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2022-05-10 08:33:09 +08:00
|
|
|
int nxsem_tickwait(FAR sem_t *sem, uint32_t delay);
|
2017-10-03 12:51:15 -06:00
|
|
|
|
2017-10-03 15:35:24 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_post
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* When a kernel thread has finished with a semaphore, it will call
|
|
|
|
|
* nxsem_post(). This function unlocks the semaphore referenced by sem
|
|
|
|
|
* by performing the semaphore unlock operation on that semaphore.
|
|
|
|
|
*
|
|
|
|
|
* If the semaphore value resulting from this operation is positive, then
|
|
|
|
|
* no tasks were blocked waiting for the semaphore to become unlocked; the
|
|
|
|
|
* semaphore is simply incremented.
|
|
|
|
|
*
|
|
|
|
|
* If the value of the semaphore resulting from this operation is zero,
|
|
|
|
|
* then one of the tasks blocked waiting for the semaphore shall be
|
|
|
|
|
* allowed to return successfully from its call to sem_wait().
|
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2017-10-03 15:35:24 -06:00
|
|
|
* sem - Semaphore descriptor
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-03 15:35:24 -06: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.
|
|
|
|
|
*
|
|
|
|
|
* Assumptions:
|
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxsem_post(FAR sem_t *sem);
|
|
|
|
|
|
2017-10-03 12:51:15 -06:00
|
|
|
/****************************************************************************
|
2020-05-17 07:56:21 -06:00
|
|
|
* Name: nxsem_get_value
|
2017-10-03 12:51:15 -06: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-05-17 07:56:21 -06:00
|
|
|
* If 'sem' is locked, the value return by nxsem_get_value() will either be
|
2017-10-03 12:51:15 -06:00
|
|
|
* zero or a negative number whose absolute value represents the number
|
|
|
|
|
* of tasks waiting for the semaphore.
|
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2017-10-03 12:51:15 -06:00
|
|
|
* sem - Semaphore descriptor
|
|
|
|
|
* sval - Buffer by which the value is returned
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-03 12:51:15 -06: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.
|
2015-08-01 07:30:23 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2020-05-17 07:56:21 -06:00
|
|
|
int nxsem_get_value(FAR sem_t *sem, FAR int *sval);
|
2015-08-01 07:30:23 -06:00
|
|
|
|
2023-11-17 14:06:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_open
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function establishes a connection between named semaphores and a
|
|
|
|
|
* task. Following a call to sem_open() with the semaphore name, the task
|
|
|
|
|
* may reference the semaphore associated with name using the address
|
|
|
|
|
* returned by this call. The semaphore may be used in subsequent calls
|
|
|
|
|
* to sem_wait(), sem_trywait(), and sem_post(). The semaphore remains
|
|
|
|
|
* usable until the semaphore is closed by a successful call to
|
|
|
|
|
* sem_close().
|
|
|
|
|
*
|
|
|
|
|
* If a task makes multiple calls to sem_open() with the same name, then
|
|
|
|
|
* the same semaphore address is returned (provided there have been no
|
|
|
|
|
* calls to sem_unlink()).
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* name - Semaphore name
|
|
|
|
|
* oflags - Semaphore creation options. This may either or both of the
|
|
|
|
|
* following bit settings.
|
|
|
|
|
* oflags = 0: Connect to the semaphore only if it already exists.
|
|
|
|
|
* oflags = O_CREAT: Connect to the semaphore if it exists, otherwise
|
|
|
|
|
* create the semaphore.
|
|
|
|
|
* oflags = O_CREAT|O_EXCL: Create a new semaphore
|
|
|
|
|
* unless one of this name already exists.
|
|
|
|
|
* Optional parameters. When the O_CREAT flag is specified, two optional
|
|
|
|
|
* parameters are expected:
|
|
|
|
|
* 1. mode_t mode, and
|
|
|
|
|
* 2. unsigned int value. This initial value of the semaphore. Valid
|
|
|
|
|
* initial values of the semaphore must be less than or equal to
|
|
|
|
|
* SEM_VALUE_MAX.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* A pointer to sem_t or negated errno if unsuccessful.
|
|
|
|
|
*
|
|
|
|
|
* Assumptions:
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
FAR sem_t *nxsem_open(FAR const char *name, int oflags, ...);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_close
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function is called to indicate that the calling task is finished
|
|
|
|
|
* with the specified named semaphore, 'sem'. The sem_close() deallocates
|
|
|
|
|
* any system resources allocated by the system for this named semaphore.
|
|
|
|
|
*
|
|
|
|
|
* If the semaphore has not been removed with a call to sem_unlink(), then
|
|
|
|
|
* sem_close() has no effect on the named semaphore. However, when the
|
|
|
|
|
* named semaphore has been fully unlinked, the semaphore will vanish when
|
|
|
|
|
* the last task closes it.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* sem - semaphore descriptor
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* 0 (OK), or negated errno if unsuccessful.
|
|
|
|
|
*
|
|
|
|
|
* Assumptions:
|
|
|
|
|
* - Care must be taken to avoid risking the deletion of a semaphore that
|
|
|
|
|
* another calling task has already locked.
|
|
|
|
|
* - sem_close must not be called for an un-named semaphore
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxsem_close(FAR sem_t *sem);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_unlink
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function removes the semaphore named by the input parameter 'name.'
|
|
|
|
|
* If the semaphore named by 'name' is currently referenced by other task,
|
|
|
|
|
* the sem_unlink() will have no effect on the state of the semaphore. If
|
|
|
|
|
* one or more processes have the semaphore open when sem_unlink() is
|
|
|
|
|
* called, destruction of the semaphore will be postponed until all
|
|
|
|
|
* references to the semaphore have been destroyed by calls of sem_close().
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* name - Semaphore name
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* 0 (OK), or negated errno if unsuccessful.
|
|
|
|
|
*
|
|
|
|
|
* Assumptions:
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxsem_unlink(FAR const char *name);
|
|
|
|
|
|
2016-03-05 07:33:24 -06:00
|
|
|
/****************************************************************************
|
2017-10-03 12:51:15 -06:00
|
|
|
* Name: nxsem_reset
|
2016-03-05 07:33:24 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
2016-03-06 13:50:26 -06:00
|
|
|
* Reset a semaphore count to a specific value. This is similar to part
|
2017-10-03 12:51:15 -06:00
|
|
|
* of the operation of nxsem_init(). But nxsem_reset() may need to wake up
|
2016-03-06 13:50:26 -06:00
|
|
|
* tasks waiting on a count. This kind of operation is sometimes required
|
|
|
|
|
* within the OS (only) for certain error handling conditions.
|
2016-03-05 07:33:24 -06:00
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2016-03-05 07:33:24 -06:00
|
|
|
* sem - Semaphore descriptor to be reset
|
|
|
|
|
* count - The requested semaphore count
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-03 12:51:15 -06:00
|
|
|
* This is an internal OS interface, not available to applications, and
|
|
|
|
|
* hence follows the NuttX internal error return policy: Zero (OK) is
|
|
|
|
|
* returned on success. A negated errno value is returned on failure.
|
2016-03-05 07:33:24 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2017-10-03 12:51:15 -06:00
|
|
|
int nxsem_reset(FAR sem_t *sem, int16_t count);
|
2016-03-05 07:33:24 -06:00
|
|
|
|
2017-10-03 15:35:24 -06:00
|
|
|
/****************************************************************************
|
2020-05-17 07:56:21 -06:00
|
|
|
* Name: nxsem_get_protocol
|
2017-10-03 15:35:24 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Return the value of the semaphore protocol attribute.
|
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2017-10-03 15:35:24 -06:00
|
|
|
* sem - A pointer to the semaphore whose attributes are to be
|
|
|
|
|
* queried.
|
|
|
|
|
* protocol - The user provided location in which to store the protocol
|
|
|
|
|
* value.
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-03 15:35:24 -06: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.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2020-05-17 07:56:21 -06:00
|
|
|
#define nxsem_get_protocol(s,p) sem_getprotocol(s,p)
|
2017-10-03 15:35:24 -06:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-05-17 07:56:21 -06:00
|
|
|
* Name: nxsem_set_protocol
|
2017-10-03 15:35:24 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Set semaphore protocol attribute.
|
|
|
|
|
*
|
2019-09-08 15:59:14 -06:00
|
|
|
* One particularly important use of this function is when a semaphore
|
2017-10-03 15:35:24 -06:00
|
|
|
* is used for inter-task communication like:
|
|
|
|
|
*
|
|
|
|
|
* TASK A TASK B
|
|
|
|
|
* sem_init(sem, 0, 0);
|
|
|
|
|
* sem_wait(sem);
|
|
|
|
|
* sem_post(sem);
|
|
|
|
|
* Awakens as holder
|
|
|
|
|
*
|
|
|
|
|
* In this case priority inheritance can interfere with the operation of
|
|
|
|
|
* the semaphore. The problem is that when TASK A is restarted it is a
|
|
|
|
|
* holder of the semaphore. However, it never calls sem_post(sem) so it
|
|
|
|
|
* becomes *permanently* a holder of the semaphore and may have its
|
|
|
|
|
* priority boosted when any other task tries to acquire the semaphore.
|
|
|
|
|
*
|
2020-05-17 07:56:21 -06:00
|
|
|
* The fix is to call nxsem_set_protocol(SEM_PRIO_NONE) immediately after
|
2017-10-03 15:35:24 -06:00
|
|
|
* the sem_init() call so that there will be no priority inheritance
|
|
|
|
|
* operations on this semaphore.
|
|
|
|
|
*
|
2018-03-13 09:52:27 -06:00
|
|
|
* Input Parameters:
|
2017-10-03 15:35:24 -06:00
|
|
|
* sem - A pointer to the semaphore whose attributes are to be
|
|
|
|
|
* modified
|
|
|
|
|
* protocol - The new protocol to use
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Returned Value:
|
2017-10-03 15:35:24 -06: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.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2020-05-17 07:56:21 -06:00
|
|
|
int nxsem_set_protocol(FAR sem_t *sem, int protocol);
|
2017-10-03 15:35:24 -06:00
|
|
|
|
2018-08-27 06:07:50 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_wait_uninterruptible
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
2020-03-29 11:56:18 -03:00
|
|
|
* This function is wrapped version of nxsem_wait(), which is
|
|
|
|
|
* uninterruptible and convenient for use.
|
2018-08-27 06:07:50 -06:00
|
|
|
*
|
|
|
|
|
* Parameters:
|
|
|
|
|
* sem - Semaphore descriptor.
|
|
|
|
|
*
|
|
|
|
|
* Return Value:
|
2020-04-05 10:39:35 -06:00
|
|
|
* Zero(OK) - On success
|
|
|
|
|
* EINVAL - Invalid attempt to get the semaphore
|
|
|
|
|
* ECANCELED - May be returned if the thread is canceled while waiting.
|
2018-08-27 06:07:50 -06:00
|
|
|
*
|
2020-04-06 09:39:49 -06:00
|
|
|
* NOTE: It is essential that callers of this function handle the
|
|
|
|
|
* ECANCELED error. Correct handling is that the function should return the
|
|
|
|
|
* error and the error should propagate back up the calling tree to the
|
|
|
|
|
* cancellation point interface function where the thread termination will
|
|
|
|
|
* be handled gracefully
|
|
|
|
|
*
|
2018-08-27 06:07:50 -06:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
include/nuttx: Fix improper use of inline
I finally figured out why the ez80 code has gotten so big. It is because people have been put putting big inline functions in header files. That is a violation of the coding standard, since only c89 compatibility is required in all common code. But we have been tolerating inline function it because include/nuttx/compiler.h defines 'inline' to be nothing for C89 compilers.
As a result, static inline functions declared within a C file not so bad; the inline qualifier is ignored, if not supported, but otherwise all is well.
But it is catastrophic in header files. Those static inline functions are included as static functions and implemented in EVERY file that includes those header files, even if the functions are never called. That makes the code base huge!So there is another PR coming to fix some of the worst offenders.
This commit fixes two of the worst offenders I have encountered so far: include/nuttx/sempahore.h and cache.h. But there may be a few other changes needed. Under include/nuttx there are still inline functions thread.h, inclue/nuttx/list.h, mutex.h, tree.h, and include/nuttx/crypto/blake2s.h with no protection for compilers that do not handler the inline qualifier. Otherwise we are clean.
With the changes to these two header files, the size of the z20x build is reduced by about 40%. And incredible size savings.
2020-03-02 14:51:28 -06:00
|
|
|
int nxsem_wait_uninterruptible(FAR sem_t *sem);
|
2018-08-27 06:07:50 -06:00
|
|
|
|
2020-01-02 10:49:34 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_timedwait_uninterruptible
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function is wrapped version of nxsem_timedwait(), which is
|
|
|
|
|
* uninterruptible and convenient for use.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* sem - Semaphore object
|
|
|
|
|
* abstime - The absolute time to wait until a timeout is declared.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* EINVAL The sem argument does not refer to a valid semaphore. Or the
|
|
|
|
|
* thread would have blocked, and the abstime parameter specified
|
|
|
|
|
* a nanoseconds field value less than zero or greater than or
|
|
|
|
|
* equal to 1000 million.
|
|
|
|
|
* ETIMEDOUT The semaphore could not be locked before the specified timeout
|
|
|
|
|
* expired.
|
|
|
|
|
* EDEADLK A deadlock condition was detected.
|
2020-03-29 11:56:18 -03:00
|
|
|
* ECANCELED May be returned if the thread is canceled while waiting.
|
2020-01-02 10:49:34 -06:00
|
|
|
*
|
2020-04-06 09:39:49 -06:00
|
|
|
* NOTE: It is essential that callers of this function handle the
|
|
|
|
|
* ECANCELED error. Correct handling is that the function should return the
|
|
|
|
|
* error and the error should propagate back up the calling tree to the
|
|
|
|
|
* cancellation point interface function where the thread termination will
|
|
|
|
|
* be handled gracefully
|
|
|
|
|
*
|
2020-01-02 10:49:34 -06:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
include/nuttx: Fix improper use of inline
I finally figured out why the ez80 code has gotten so big. It is because people have been put putting big inline functions in header files. That is a violation of the coding standard, since only c89 compatibility is required in all common code. But we have been tolerating inline function it because include/nuttx/compiler.h defines 'inline' to be nothing for C89 compilers.
As a result, static inline functions declared within a C file not so bad; the inline qualifier is ignored, if not supported, but otherwise all is well.
But it is catastrophic in header files. Those static inline functions are included as static functions and implemented in EVERY file that includes those header files, even if the functions are never called. That makes the code base huge!So there is another PR coming to fix some of the worst offenders.
This commit fixes two of the worst offenders I have encountered so far: include/nuttx/sempahore.h and cache.h. But there may be a few other changes needed. Under include/nuttx there are still inline functions thread.h, inclue/nuttx/list.h, mutex.h, tree.h, and include/nuttx/crypto/blake2s.h with no protection for compilers that do not handler the inline qualifier. Otherwise we are clean.
With the changes to these two header files, the size of the z20x build is reduced by about 40%. And incredible size savings.
2020-03-02 14:51:28 -06:00
|
|
|
int nxsem_timedwait_uninterruptible(FAR sem_t *sem,
|
|
|
|
|
FAR const struct timespec *abstime);
|
2020-01-02 10:49:34 -06:00
|
|
|
|
2020-07-27 13:46:03 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_clockwait_uninterruptible
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
2022-05-10 09:32:31 +08:00
|
|
|
* This function is wrapped version of nxsem_clockwait(), which is
|
2020-07-27 13:46:03 +08:00
|
|
|
* uninterruptible and convenient for use.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* sem - Semaphore object
|
|
|
|
|
* clockid - The timing source to use in the conversion
|
|
|
|
|
* abstime - The absolute time to wait until a timeout is declared.
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* EINVAL The sem argument does not refer to a valid semaphore. Or the
|
|
|
|
|
* thread would have blocked, and the abstime parameter specified
|
|
|
|
|
* a nanoseconds field value less than zero or greater than or
|
|
|
|
|
* equal to 1000 million.
|
|
|
|
|
* ETIMEDOUT The semaphore could not be locked before the specified timeout
|
|
|
|
|
* expired.
|
|
|
|
|
* EDEADLK A deadlock condition was detected.
|
|
|
|
|
* ECANCELED May be returned if the thread is canceled while waiting.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: It is essential that callers of this function handle the
|
|
|
|
|
* ECANCELED error. Correct handling is that the function should return the
|
|
|
|
|
* error and the error should propagate back up the calling tree to the
|
|
|
|
|
* cancellation point interface function where the thread termination will
|
|
|
|
|
* be handled gracefully
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
int nxsem_clockwait_uninterruptible(FAR sem_t *sem, clockid_t clockid,
|
|
|
|
|
FAR const struct timespec *abstime);
|
|
|
|
|
|
2020-01-02 10:49:34 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: nxsem_tickwait_uninterruptible
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This function is wrapped version of nxsem_tickwait(), which is
|
|
|
|
|
* uninterruptible and convenient for use.
|
|
|
|
|
*
|
|
|
|
|
* Input Parameters:
|
|
|
|
|
* sem - Semaphore object
|
|
|
|
|
* delay - Ticks to wait from the start time until the semaphore is
|
|
|
|
|
* posted. If ticks is zero, then this function is equivalent
|
|
|
|
|
* to sem_trywait().
|
|
|
|
|
*
|
|
|
|
|
* Returned Value:
|
2020-03-29 11:56:18 -03:00
|
|
|
* This is an internal OS interface, not available to applications, and
|
|
|
|
|
* hence follows the NuttX internal error return policy: Zero (OK) is
|
|
|
|
|
* returned on success. A negated errno value is returned on failure:
|
|
|
|
|
*
|
|
|
|
|
* -ETIMEDOUT is returned on the timeout condition.
|
|
|
|
|
* -ECANCELED may be returned if the thread is canceled while waiting.
|
2020-01-02 10:49:34 -06:00
|
|
|
*
|
2020-04-06 09:39:49 -06:00
|
|
|
* NOTE: It is essential that callers of this function handle the
|
|
|
|
|
* ECANCELED error. Correct handling is that the function should return the
|
|
|
|
|
* error and the error should propagate back up the calling tree to the
|
|
|
|
|
* cancellation point interface function where the thread termination will
|
|
|
|
|
* be handled gracefully
|
|
|
|
|
*
|
2020-01-02 10:49:34 -06:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
2022-05-10 08:33:09 +08:00
|
|
|
int nxsem_tickwait_uninterruptible(FAR sem_t *sem, uint32_t delay);
|
2020-01-02 10:49:34 -06:00
|
|
|
|
2014-09-28 10:15:49 -06:00
|
|
|
#undef EXTERN
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
|
#endif /* __INCLUDE_NUTTX_SEMAPHORE_H */
|