libc/misc: Add lib_ prefix to stream_semtake and tream_semgive

and merge lib_streamsem.c to lib_stream.c

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2021-11-01 12:00:39 +08:00 committed by Alin Jerpelea
parent 391ccdc42b
commit ad2f82898a
6 changed files with 30 additions and 73 deletions

View File

@ -77,8 +77,8 @@ extern "C"
/* Defined in lib_streamsem.c */ /* Defined in lib_streamsem.c */
#ifdef CONFIG_FILE_STREAM #ifdef CONFIG_FILE_STREAM
void stream_semtake(FAR struct streamlist *list); void lib_stream_semtake(FAR struct streamlist *list);
void stream_semgive(FAR struct streamlist *list); void lib_stream_semgive(FAR struct streamlist *list);
#endif #endif
/* Defined in lib_dtoa.c */ /* Defined in lib_dtoa.c */

View File

@ -20,7 +20,7 @@
# Add the internal C files to the build # Add the internal C files to the build
CSRCS += lib_stream.c lib_umask.c lib_utsname.c CSRCS += lib_umask.c lib_utsname.c
CSRCS += lib_xorshift128.c lib_tea_encrypt.c lib_tea_decrypt.c CSRCS += lib_xorshift128.c lib_tea_encrypt.c lib_tea_decrypt.c
ifneq ($(CONFIG_STDIO_DISABLE_BUFFERING),y) ifneq ($(CONFIG_STDIO_DISABLE_BUFFERING),y)
@ -35,7 +35,7 @@ CSRCS += lib_uadd32x64.c lib_uadd64.c lib_usub64x32.c lib_usub64.c
# Add C files that depend on file OR socket descriptors # Add C files that depend on file OR socket descriptors
ifeq ($(CONFIG_FILE_STREAM),y) ifeq ($(CONFIG_FILE_STREAM),y)
CSRCS += lib_streamsem.c CSRCS += lib_stream.c
endif endif
ifeq ($(CONFIG_PIPES),y) ifeq ($(CONFIG_PIPES),y)

View File

@ -52,7 +52,6 @@
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_FILE_STREAM
void lib_stream_initialize(FAR struct task_group_s *group) void lib_stream_initialize(FAR struct task_group_s *group)
{ {
FAR struct streamlist *list; FAR struct streamlist *list;
@ -80,7 +79,6 @@ void lib_stream_initialize(FAR struct task_group_s *group)
list->sl_std[2].fs_fd = -1; list->sl_std[2].fs_fd = -1;
lib_sem_initialize(&list->sl_std[2]); lib_sem_initialize(&list->sl_std[2]);
} }
#endif /* CONFIG_FILE_STREAM */
/**************************************************************************** /****************************************************************************
* Name: lib_stream_release * Name: lib_stream_release
@ -92,7 +90,6 @@ void lib_stream_initialize(FAR struct task_group_s *group)
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_FILE_STREAM
void lib_stream_release(FAR struct task_group_s *group) void lib_stream_release(FAR struct task_group_s *group)
{ {
FAR struct streamlist *list; FAR struct streamlist *list;
@ -151,5 +148,26 @@ void lib_stream_release(FAR struct task_group_s *group)
#endif #endif
} }
#endif /* CONFIG_FILE_STREAM */
#endif /* CONFIG_BUILD_FLAT || __KERNEL__ */ #endif /* CONFIG_BUILD_FLAT || __KERNEL__ */
void lib_stream_semtake(FAR struct streamlist *list)
{
int ret;
/* Take the semaphore (perhaps waiting) */
while ((ret = _SEM_WAIT(&list->sl_sem)) < 0)
{
/* The only case that an error should occr here is if
* the wait was awakened by a signal.
*/
DEBUGASSERT(_SEM_ERRNO(ret) == EINTR || _SEM_ERRNO(ret) == ECANCELED);
UNUSED(ret);
}
}
void lib_stream_semgive(FAR struct streamlist *list)
{
_SEM_POST(&list->sl_sem);
}

View File

@ -1,61 +0,0 @@
/****************************************************************************
* libs/libc/misc/lib_streamsem.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 <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <nuttx/semaphore.h>
#include <nuttx/fs/fs.h>
#include "libc.h"
/****************************************************************************
* Public Functions
****************************************************************************/
void stream_semtake(FAR struct streamlist *list)
{
int ret;
/* Take the semaphore (perhaps waiting) */
while ((ret = _SEM_WAIT(&list->sl_sem)) < 0)
{
/* The only case that an error should occr here is if
* the wait was awakened by a signal.
*/
DEBUGASSERT(_SEM_ERRNO(ret) == EINTR || _SEM_ERRNO(ret) == ECANCELED);
UNUSED(ret);
}
}
void stream_semgive(FAR struct streamlist *list)
{
_SEM_POST(&list->sl_sem);
}

View File

@ -85,7 +85,7 @@ int fclose(FAR FILE *stream)
/* Remove FILE structure from the stream list */ /* Remove FILE structure from the stream list */
slist = nxsched_get_streams(); slist = nxsched_get_streams();
stream_semtake(slist); lib_stream_semtake(slist);
for (next = slist->sl_head; next; prev = next, next = next->fs_next) for (next = slist->sl_head; next; prev = next, next = next->fs_next)
{ {
@ -109,7 +109,7 @@ int fclose(FAR FILE *stream)
} }
} }
stream_semgive(slist); lib_stream_semgive(slist);
/* Check that the underlying file descriptor corresponds to an an open /* Check that the underlying file descriptor corresponds to an an open
* file. * file.

View File

@ -58,7 +58,7 @@ int lib_flushall(FAR struct streamlist *list)
/* Process each stream in the thread's stream list */ /* Process each stream in the thread's stream list */
stream_semtake(list); lib_stream_semtake(list);
stream = list->sl_head; stream = list->sl_head;
for (; stream != NULL; stream = stream->fs_next) for (; stream != NULL; stream = stream->fs_next)
{ {
@ -83,7 +83,7 @@ int lib_flushall(FAR struct streamlist *list)
} }
} }
stream_semgive(list); lib_stream_semgive(list);
} }
/* If any flush failed, return the errorcode of the last failed flush */ /* If any flush failed, return the errorcode of the last failed flush */