stdio/file: unify group file list to common single queue
unify group file list to common single queue Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
parent
8e0bf9a0b4
commit
d4d49e9645
@ -40,6 +40,7 @@
|
||||
#include <nuttx/spinlock.h>
|
||||
#include <nuttx/mm/map.h>
|
||||
#include <nuttx/spawn.h>
|
||||
#include <nuttx/queue.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -538,7 +539,7 @@ struct filelist
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
struct file_struct
|
||||
{
|
||||
FAR struct file_struct *fs_next; /* Pointer to next file stream */
|
||||
sq_entry_t fs_entry; /* Entry of file stream */
|
||||
rmutex_t fs_lock; /* Recursive lock */
|
||||
cookie_io_functions_t fs_iofunc; /* Callbacks to user / system functions */
|
||||
FAR void *fs_cookie; /* Pointer to file descriptor / cookie struct */
|
||||
@ -563,8 +564,7 @@ struct streamlist
|
||||
{
|
||||
mutex_t sl_lock; /* For thread safety */
|
||||
struct file_struct sl_std[3];
|
||||
FAR struct file_struct *sl_head;
|
||||
FAR struct file_struct *sl_tail;
|
||||
sq_queue_t sl_queue;
|
||||
};
|
||||
#endif /* CONFIG_FILE_STREAM */
|
||||
|
||||
|
@ -59,8 +59,6 @@
|
||||
int fclose(FAR FILE *stream)
|
||||
{
|
||||
FAR struct streamlist *slist;
|
||||
FAR FILE *prev = NULL;
|
||||
FAR FILE *next;
|
||||
int errcode = EINVAL;
|
||||
int ret = ERROR;
|
||||
int status;
|
||||
@ -91,27 +89,7 @@ int fclose(FAR FILE *stream)
|
||||
slist = lib_get_streams();
|
||||
nxmutex_lock(&slist->sl_lock);
|
||||
|
||||
for (next = slist->sl_head; next; prev = next, next = next->fs_next)
|
||||
{
|
||||
if (next == stream)
|
||||
{
|
||||
if (next == slist->sl_head)
|
||||
{
|
||||
slist->sl_head = next->fs_next;
|
||||
}
|
||||
else
|
||||
{
|
||||
prev->fs_next = next->fs_next;
|
||||
}
|
||||
|
||||
if (next == slist->sl_tail)
|
||||
{
|
||||
slist->sl_tail = prev;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
sq_rem(&stream->fs_entry, &slist->sl_queue);
|
||||
|
||||
nxmutex_unlock(&slist->sl_lock);
|
||||
|
||||
|
@ -98,16 +98,7 @@ FAR FILE *fdopen(int fd, FAR const char *mode)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (list->sl_tail)
|
||||
{
|
||||
list->sl_tail->fs_next = filep;
|
||||
list->sl_tail = filep;
|
||||
}
|
||||
else
|
||||
{
|
||||
list->sl_head = filep;
|
||||
list->sl_tail = filep;
|
||||
}
|
||||
sq_addlast(&filep->fs_entry, &list->sl_queue);
|
||||
|
||||
nxmutex_unlock(&list->sl_lock);
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/nuttx.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "libc.h"
|
||||
@ -47,6 +48,7 @@
|
||||
|
||||
int lib_flushall_unlocked(FAR struct streamlist *list)
|
||||
{
|
||||
FAR sq_entry_t *entry;
|
||||
int lasterrno = OK;
|
||||
int ret;
|
||||
|
||||
@ -64,8 +66,10 @@ int lib_flushall_unlocked(FAR struct streamlist *list)
|
||||
lib_fflush_unlocked(&list->sl_std[i]);
|
||||
}
|
||||
|
||||
for (stream = list->sl_head; stream != NULL; stream = stream->fs_next)
|
||||
sq_for_every(&list->sl_queue, entry)
|
||||
{
|
||||
stream = container_of(entry, struct file_struct, fs_entry);
|
||||
|
||||
/* If the stream is opened for writing, then flush all of
|
||||
* the pending write data in the stream.
|
||||
*/
|
||||
@ -95,6 +99,7 @@ int lib_flushall_unlocked(FAR struct streamlist *list)
|
||||
|
||||
int lib_flushall(FAR struct streamlist *list)
|
||||
{
|
||||
FAR sq_entry_t *entry;
|
||||
int lasterrno = OK;
|
||||
int ret;
|
||||
|
||||
@ -114,8 +119,10 @@ int lib_flushall(FAR struct streamlist *list)
|
||||
lib_fflush(&list->sl_std[i]);
|
||||
}
|
||||
|
||||
for (stream = list->sl_head; stream != NULL; stream = stream->fs_next)
|
||||
sq_for_every(&list->sl_queue, entry)
|
||||
{
|
||||
stream = container_of(entry, struct file_struct, fs_entry);
|
||||
|
||||
/* If the stream is opened for writing, then flush all of
|
||||
* the pending write data in the stream.
|
||||
*/
|
||||
|
@ -52,8 +52,7 @@ static void task_init_stream(FAR struct streamlist *list)
|
||||
/* Initialize the list access mutex */
|
||||
|
||||
nxmutex_init(&list->sl_lock);
|
||||
list->sl_head = NULL;
|
||||
list->sl_tail = NULL;
|
||||
sq_init(&list->sl_queue);
|
||||
|
||||
/* Initialize stdin, stdout and stderr stream */
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/nuttx.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/mutex.h>
|
||||
#include <nuttx/list.h>
|
||||
@ -47,6 +48,8 @@ static void task_uninit_stream(FAR struct task_group_s *group)
|
||||
{
|
||||
FAR struct streamlist *list;
|
||||
FAR struct file_struct *stream;
|
||||
FAR sq_entry_t *curr;
|
||||
FAR sq_entry_t *next;
|
||||
|
||||
DEBUGASSERT(group && group->tg_info);
|
||||
list = &group->tg_info->ta_streamlist;
|
||||
@ -66,11 +69,9 @@ static void task_uninit_stream(FAR struct task_group_s *group)
|
||||
|
||||
/* Release each stream in the list */
|
||||
|
||||
list->sl_tail = NULL;
|
||||
while (list->sl_head != NULL)
|
||||
sq_for_every_safe(&list->sl_queue, curr, next)
|
||||
{
|
||||
stream = list->sl_head;
|
||||
list->sl_head = stream->fs_next;
|
||||
stream = container_of(curr, struct file_struct, fs_entry);
|
||||
|
||||
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
||||
/* Destroy the mutex that protects the IO buffer */
|
||||
|
Loading…
x
Reference in New Issue
Block a user