jlaitine commented on code in PR #16030: URL: https://github.com/apache/nuttx/pull/16030#discussion_r2013466633
########## include/nuttx/sem_fast.h: ########## @@ -0,0 +1,184 @@ +/**************************************************************************** + * include/nuttx/sem_fast.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_SEM_FAST_H +#define __INCLUDE_NUTTX_SEM_FAST_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/atomic.h> +#include <nuttx/semaphore.h> + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nxsem_*_slow + * + * Description: + * Kernel default implementations for the nxsem functions. These are + * called when the fast locking / unlocking can't be performed. For the + * parameters and return values, see the _impl functions below. + */ + +int nxsem_trywait_slow(sem_t *sem); +int nxsem_wait_slow(sem_t *sem); +int nxsem_post_slow(sem_t *sem); + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/* Mutex/semaphore fast path using atomics is not relevant when using + * CONFIG_LIBC_ARCH_ATOMIC, since libc atomic implementation uses spinlocks. + * Spinlocks should not be called from libc, and also in the kernel it is + * faster to take the slow path directly. + */ + +#ifndef CONFIG_LIBC_ARCH_ATOMIC + +/**************************************************************************** + * Name: nxsem_trywait_impl + * + * Description: + * Try to wait on semaphore using fast atomic exchange. If the atomic + * exchange can't be used, call the default implementation in kernel. + * + * Input Parameters: + * sem - The semaphore to wait on + * + * Returned Value: + * OK - Semaphore taken + * -EINVAL - Invalid attempt to get the semaphore + * -EAGAIN - The semaphore is not available. + * + * Assumptions: + * None + * + ****************************************************************************/ + +static inline_function int nxsem_trywait_impl(sem_t *sem) Review Comment: I respectfully disagree on that and won't do, se the reasoning above. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org