mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 17:33:08 +08:00
libc/stdio: Allocate file_struct dynamically
1.Reduce the default size of task_group_s(~512B each task) 2.Scale better between simple and complex application Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: Ia872137504fddcf64d89c48d6f0593d76d582710
This commit is contained in:
+1
-1
@@ -138,7 +138,7 @@
|
||||
#define _POSIX_OPEN_MAX CONFIG_NFILE_DESCRIPTORS
|
||||
#define _POSIX_PATH_MAX CONFIG_PATH_MAX
|
||||
#define _POSIX_PIPE_BUF 512
|
||||
#define _POSIX_STREAM_MAX CONFIG_NFILE_STREAMS
|
||||
#define _POSIX_STREAM_MAX CONFIG_NFILE_DESCRIPTORS
|
||||
#define _POSIX_TZNAME_MAX 3
|
||||
|
||||
#ifdef CONFIG_SMALL_MEMORY
|
||||
|
||||
+20
-18
@@ -456,33 +456,35 @@ struct filelist
|
||||
* buffer+1
|
||||
*/
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
struct file_struct
|
||||
{
|
||||
int fs_fd; /* File descriptor associated with stream */
|
||||
FAR struct file_struct *fs_next; /* Pointer to next file stream */
|
||||
int fs_fd; /* File descriptor associated with stream */
|
||||
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
||||
sem_t fs_sem; /* For thread safety */
|
||||
pid_t fs_holder; /* Holder of sem */
|
||||
int fs_counts; /* Number of times sem is held */
|
||||
FAR unsigned char *fs_bufstart; /* Pointer to start of buffer */
|
||||
FAR unsigned char *fs_bufend; /* Pointer to 1 past end of buffer */
|
||||
FAR unsigned char *fs_bufpos; /* Current position in buffer */
|
||||
FAR unsigned char *fs_bufread; /* Pointer to 1 past last buffered read char. */
|
||||
sem_t fs_sem; /* For thread safety */
|
||||
pid_t fs_holder; /* Holder of sem */
|
||||
int fs_counts; /* Number of times sem is held */
|
||||
FAR unsigned char *fs_bufstart; /* Pointer to start of buffer */
|
||||
FAR unsigned char *fs_bufend; /* Pointer to 1 past end of buffer */
|
||||
FAR unsigned char *fs_bufpos; /* Current position in buffer */
|
||||
FAR unsigned char *fs_bufread; /* Pointer to 1 past last buffered read char. */
|
||||
#endif
|
||||
uint16_t fs_oflags; /* Open mode flags */
|
||||
uint8_t fs_flags; /* Stream flags */
|
||||
uint16_t fs_oflags; /* Open mode flags */
|
||||
uint8_t fs_flags; /* Stream flags */
|
||||
#if CONFIG_NUNGET_CHARS > 0
|
||||
uint8_t fs_nungotten; /* The number of characters buffered for ungetc */
|
||||
unsigned char fs_ungotten[CONFIG_NUNGET_CHARS];
|
||||
uint8_t fs_nungotten; /* The number of characters buffered for ungetc */
|
||||
unsigned char fs_ungotten[CONFIG_NUNGET_CHARS];
|
||||
#endif
|
||||
};
|
||||
|
||||
struct streamlist
|
||||
{
|
||||
sem_t sl_sem; /* For thread safety */
|
||||
struct file_struct sl_streams[CONFIG_NFILE_STREAMS];
|
||||
sem_t sl_sem; /* For thread safety */
|
||||
FAR struct file_struct *sl_head;
|
||||
FAR struct file_struct *sl_tail;
|
||||
};
|
||||
#endif /* CONFIG_NFILE_STREAMS */
|
||||
#endif /* CONFIG_FILE_STREAM */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
@@ -1029,7 +1031,7 @@ int close_blockdriver(FAR struct inode *inode);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
struct tcb_s; /* Forward reference */
|
||||
int fs_fdopen(int fd, int oflags, FAR struct tcb_s *tcb,
|
||||
FAR struct file_struct **filep);
|
||||
@@ -1044,7 +1046,7 @@ int fs_fdopen(int fd, int oflags, FAR struct tcb_s *tcb,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
int lib_flushall(FAR struct streamlist *list);
|
||||
#endif
|
||||
|
||||
|
||||
+16
-2
@@ -2,7 +2,8 @@
|
||||
* include/nuttx/lib/lib.h
|
||||
* Non-standard, internal APIs available in lib/.
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2012-2014, 2016 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2012-2014, 2016 Gregory Nutt. All rights
|
||||
* reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -65,18 +66,31 @@ extern "C"
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* Hook for library initialization. No is needed now, however */
|
||||
|
||||
#define lib_initialize()
|
||||
|
||||
/* Functions contained in lib_streams.c *************************************/
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
struct task_group_s;
|
||||
void lib_stream_initialize(FAR struct task_group_s *group);
|
||||
void lib_stream_release(FAR struct task_group_s *group);
|
||||
#endif
|
||||
|
||||
/* Functions defined in lib_filesem.c ***************************************/
|
||||
|
||||
#ifdef CONFIG_STDIO_DISABLE_BUFFERING
|
||||
# define lib_sem_initialize(s)
|
||||
# define lib_take_semaphore(s)
|
||||
# define lib_give_semaphore(s)
|
||||
#else
|
||||
void lib_sem_initialize(FAR struct file_struct *stream);
|
||||
void lib_take_semaphore(FAR struct file_struct *stream);
|
||||
void lib_give_semaphore(FAR struct file_struct *stream);
|
||||
#endif
|
||||
|
||||
/* Functions defined in lib_srand.c *****************************************/
|
||||
|
||||
unsigned long nrand(unsigned long limit);
|
||||
|
||||
@@ -580,7 +580,7 @@ struct task_group_s
|
||||
|
||||
struct filelist tg_filelist; /* Maps file descriptor to file */
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
/* FILE streams ***************************************************************/
|
||||
|
||||
/* In a flat, single-heap build. The stream list is allocated with this
|
||||
@@ -913,9 +913,9 @@ int nxsched_release_tcb(FAR struct tcb_s *tcb, uint8_t ttype);
|
||||
*/
|
||||
|
||||
FAR struct filelist *nxsched_get_files(void);
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
FAR struct streamlist *nxsched_get_streams(void);
|
||||
#endif /* CONFIG_NFILE_STREAMS */
|
||||
#endif /* CONFIG_FILE_STREAM */
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
FAR struct socketlist *nxsched_get_sockets(void);
|
||||
|
||||
+3
-3
@@ -78,9 +78,9 @@
|
||||
|
||||
/* The first three _iob entries are reserved for standard I/O */
|
||||
|
||||
#define stdin (&nxsched_get_streams()->sl_streams[0])
|
||||
#define stdout (&nxsched_get_streams()->sl_streams[1])
|
||||
#define stderr (&nxsched_get_streams()->sl_streams[2])
|
||||
#define stdin (nxsched_get_streams()->sl_head)
|
||||
#define stdout (nxsched_get_streams()->sl_head->fs_next)
|
||||
#define stderr (nxsched_get_streams()->sl_head->fs_next->fs_next)
|
||||
|
||||
/* Path to the directory where temporary files can be created */
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ SYSCALL_LOOKUP(telldir, 1)
|
||||
SYSCALL_LOOKUP(nx_mkfifo, 3)
|
||||
#endif
|
||||
|
||||
#if CONFIG_NFILE_STREAMS > 0
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
SYSCALL_LOOKUP(fs_fdopen, 4)
|
||||
SYSCALL_LOOKUP(nxsched_get_streams, 0)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user