maht commented on code in PR #6152: URL: https://github.com/apache/incubator-nuttx/pull/6152#discussion_r861656152
########## libs/libc/stdio/lib_ftrylockfile.c: ########## @@ -0,0 +1,100 @@ +/**************************************************************************** + * libs/libc/stdio/lib_ftrylockfile.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdio.h> + +#include <sys/types.h> +#include <unistd.h> +#include <errno.h> +#include <assert.h> + +#include <nuttx/semaphore.h> +#include <nuttx/fs/fs.h> + +#include "libc.h" + +#ifndef CONFIG_STDIO_DISABLE_BUFFERING + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: _take_semaphore_nonblocking + * + * Description: + * Take a semaphore if its available, returning inmediately if not. + * + * Input Parameters: + * sem - The semaphore. + * + * Returned Value: + * OK - The semaphore is taken successfully. + * -EAGAIN - The semaphore is not available. + * -EINVAL - Invalid attempt to get the semaphore. + * + ****************************************************************************/ + +static int _take_semaphore_nonblocking(sem_t *sem) +{ + int ret; + + /* Try to take the semaphore (without waiting) */ + + if ((ret = _SEM_TRYWAIT(sem)) < 0) + { + DEBUGASSERT(_SEM_ERRNO(ret) == EAGAIN || + _SEM_ERRNO(ret) == EINVAL); Review Comment: Because these are the values defined in [`nxsem_trywait()`](https://github.com/apache/incubator-nuttx/blob/dcb440a4d9f953361696a19bc41810247f6dde70/sched/semaphore/sem_trywait.c#L67). But maybe this needs a revision, since `_SEM_TRYWAIT` can be also be defined to [`sem_trywait()`](https://github.com/apache/incubator-nuttx/blob/dcb440a4d9f953361696a19bc41810247f6dde70/sched/semaphore/sem_trywait.c#L137) and then the error is returned in `errno`. I will rework this. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
