maht commented on code in PR #6152: URL: https://github.com/apache/incubator-nuttx/pull/6152#discussion_r861656908
########## libs/libc/stdio/lib_funlockfile.c: ########## @@ -0,0 +1,81 @@ +/**************************************************************************** + * libs/libc/stdio/lib_funlockfile.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: funlockfile + * + * Description: + * funlockfile() relinquish the ownership of a stream granted to the + * thread. + * + * The behavior is undefined if called by a thread other than the current + * owner. + * + ****************************************************************************/ + +void funlockfile(FAR FILE *stream) +{ + /* I better be holding at least one reference to the semaphore */ + + DEBUGASSERT(stream->fs_holder == getpid()); + + /* Do I hold multiple references to the semphore */ + + if (stream->fs_counts > 1) + { + /* Yes, just release one count and return */ + + stream->fs_counts--; + } + else + { + /* Nope, this is the last reference I have */ + + stream->fs_holder = -1; Review Comment: Thanks, I will add it at the beginning/end, since this would be a change from original code. -- 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]
