2011-07-19 15:40:15 +02:00
|
|
|
/****************************************************************************
|
2014-08-08 21:53:29 +02:00
|
|
|
* sched/semaphore/sem_timedwait.c
|
2011-07-19 15:40:15 +02:00
|
|
|
*
|
2020-03-29 16:56:18 +02: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
|
2011-07-19 15:40:15 +02:00
|
|
|
*
|
2020-03-29 16:56:18 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-07-19 15:40:15 +02:00
|
|
|
*
|
2020-03-29 16:56:18 +02: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.
|
2011-07-19 15:40:15 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-27 07:46:03 +02:00
|
|
|
#include <nuttx/semaphore.h>
|
2011-07-19 15:40:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-10-05 15:24:54 +02:00
|
|
|
* Name: nxsem_timedwait
|
2011-07-19 15:40:15 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2017-10-05 15:24:54 +02:00
|
|
|
* This is an internal OS interface. It is functionally equivalent to
|
|
|
|
* sem_wait except that:
|
|
|
|
*
|
2019-08-23 19:57:35 +02:00
|
|
|
* - It is not a cancellation point, and
|
2017-10-05 15:24:54 +02:00
|
|
|
* - It does not modify the errno value.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-10-05 15:24:54 +02:00
|
|
|
* sem - Semaphore object
|
2011-07-19 15:40:15 +02:00
|
|
|
* abstime - The absolute time to wait until a timeout is declared.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-10-05 15:24:54 +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.
|
|
|
|
* That may be one of:
|
2011-07-19 15:40:15 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-10-05 15:24:54 +02:00
|
|
|
int nxsem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime)
|
2011-07-19 15:40:15 +02:00
|
|
|
{
|
2020-07-27 07:46:03 +02:00
|
|
|
return nxsem_clockwait(sem, CLOCK_REALTIME, abstime);
|
2017-10-05 15:24:54 +02:00
|
|
|
}
|
2011-07-19 15:40:15 +02: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 21:51:28 +01: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 16:56:18 +02:00
|
|
|
* ECANCELED May be returned if the thread is canceled while waiting.
|
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 21:51:28 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int nxsem_timedwait_uninterruptible(FAR sem_t *sem,
|
|
|
|
FAR const struct timespec *abstime)
|
|
|
|
{
|
2020-07-27 07:46:03 +02:00
|
|
|
return nxsem_clockwait_uninterruptible(sem, CLOCK_REALTIME, abstime);
|
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 21:51:28 +01:00
|
|
|
}
|
|
|
|
|
2017-10-05 15:24:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: sem_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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-10-05 15:24:54 +02:00
|
|
|
* sem - Semaphore object
|
|
|
|
* abstime - The absolute time to wait until a timeout is declared.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-10-05 15:24:54 +02:00
|
|
|
* Zero (OK) is returned on success. On failure, -1 (ERROR) is returned
|
|
|
|
* and the errno is set appropriately:
|
|
|
|
*
|
|
|
|
* 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 16:56:18 +02:00
|
|
|
* ECANCELED May be returned if the thread is canceled while waiting.
|
2017-10-05 15:24:54 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2011-07-19 15:40:15 +02:00
|
|
|
|
2017-10-05 15:24:54 +02:00
|
|
|
int sem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime)
|
|
|
|
{
|
2020-07-27 07:46:03 +02:00
|
|
|
return sem_clockwait(sem, CLOCK_REALTIME, abstime);
|
2011-07-19 15:40:15 +02:00
|
|
|
}
|