From: Matthew Joyce <matthew.joyce@embedded-brains.de>
To: newlib@sourceware.org
Subject: [PATCH 09/11] stdio: Replace _fwalk_reent() with _fwalk_sglue()
Date: Tue, 10 May 2022 10:09:25 +0200 [thread overview]
Message-ID: <20220510080927.28839-10-matthew.joyce@embedded-brains.de> (raw)
In-Reply-To: <20220510080927.28839-1-matthew.joyce@embedded-brains.de>
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
Replaced _fwalk_reent() with _fwalk_sglue(). The change adds an
extra __sglue object as a parameter, which will allow the passing
of a global __sglue object separate from the __sglue member of
struct _reent. The global __sglue object will be added in a
follow-on patch.
---
newlib/libc/stdio/fcloseall.c | 2 +-
newlib/libc/stdio/fflush.c | 2 +-
newlib/libc/stdio/findfp.c | 14 ++++++++++----
newlib/libc/stdio/fwalk.c | 15 ++++++++-------
newlib/libc/stdio/local.h | 3 ++-
newlib/libc/stdio/refill.c | 4 ++--
winsup/cygwin/syscalls.cc | 5 +++--
7 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/newlib/libc/stdio/fcloseall.c b/newlib/libc/stdio/fcloseall.c
index 014c451cd..4d4e3554b 100644
--- a/newlib/libc/stdio/fcloseall.c
+++ b/newlib/libc/stdio/fcloseall.c
@@ -59,7 +59,7 @@ Required OS subroutines: <<close>>, <<fstat>>, <<isatty>>, <<lseek>>,
int
_fcloseall_r (struct _reent *ptr)
{
- return _fwalk_reent (ptr, _fclose_r);
+ return _fwalk_sglue (ptr, _fclose_r, &ptr->__sglue);
}
#ifndef _REENT_ONLY
diff --git a/newlib/libc/stdio/fflush.c b/newlib/libc/stdio/fflush.c
index 2b5f13bff..6e946da7b 100644
--- a/newlib/libc/stdio/fflush.c
+++ b/newlib/libc/stdio/fflush.c
@@ -286,7 +286,7 @@ int
fflush (register FILE * fp)
{
if (fp == NULL)
- return _fwalk_reent (_GLOBAL_REENT, _fflush_r);
+ return _fwalk_sglue (_GLOBAL_REENT, _fflush_r, &_GLOBAL_REENT->__sglue);
return _fflush_r (_REENT, fp);
}
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 022a298df..221052bd4 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -158,7 +158,7 @@ sfmoreglue (struct _reent *d, int n)
static void
stdio_atexit (void)
{
- (void) _fwalk_reent (_GLOBAL_REENT, CLEANUP_FILE);
+ (void) _fwalk_sglue (_GLOBAL_REENT, CLEANUP_FILE, &_GLOBAL_REENT->__sglue);
}
/*
@@ -240,7 +240,7 @@ cleanup_stdio (struct _reent *ptr)
if (ptr->_stderr != &__sf[2])
CLEANUP_FILE (ptr, ptr->_stderr);
#endif
- (void) _fwalk_reent (ptr, CLEANUP_FILE);
+ (void) _fwalk_sglue (ptr, CLEANUP_FILE, &ptr->__sglue);
}
/*
@@ -323,15 +323,21 @@ __fp_unlock (struct _reent * ptr __unused, FILE * fp)
void
__fp_lock_all (void)
{
+ struct _reent *ptr;
+
__sfp_lock_acquire ();
- (void) _fwalk_reent (_REENT, __fp_lock);
+ ptr = _REENT;
+ (void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue);
}
void
__fp_unlock_all (void)
{
- (void) _fwalk_reent (_REENT, __fp_unlock);
+ struct _reent *ptr;
+
+ ptr = _REENT;
+ (void) _fwalk_sglue (ptr, __fp_unlock, &ptr->__sglue);
__sfp_lock_release ();
}
diff --git a/newlib/libc/stdio/fwalk.c b/newlib/libc/stdio/fwalk.c
index 2cefcc40e..0fdad9d31 100644
--- a/newlib/libc/stdio/fwalk.c
+++ b/newlib/libc/stdio/fwalk.c
@@ -28,12 +28,11 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include "local.h"
int
-_fwalk_reent (struct _reent *ptr,
- register int (*reent_function) (struct _reent *, FILE *))
+_fwalk_sglue (struct _reent *ptr, int (*func) (struct _reent *, FILE *),
+ struct _glue *g)
{
- register FILE *fp;
- register int n, ret = 0;
- register struct _glue *g;
+ FILE *fp;
+ int n, ret = 0;
/*
* It should be safe to walk the list without locking it;
@@ -43,10 +42,12 @@ _fwalk_reent (struct _reent *ptr,
* Avoid locking this list while walking it or else you will
* introduce a potential deadlock in [at least] refill.c.
*/
- for (g = &ptr->__sglue; g != NULL; g = g->_next)
+ do {
for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1)
- ret |= (*reent_function) (ptr, fp);
+ ret |= (*func) (ptr, fp);
+ g = g->_next;
+ } while (g != NULL);
return ret;
}
diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h
index c892f8378..0c1432d67 100644
--- a/newlib/libc/stdio/local.h
+++ b/newlib/libc/stdio/local.h
@@ -183,7 +183,8 @@ extern void __sinit (struct _reent *);
extern void (*__stdio_atexit) (void);
extern void __smakebuf_r (struct _reent *, FILE *);
extern int __swhatbuf_r (struct _reent *, FILE *, size_t *, int *);
-extern int _fwalk_reent (struct _reent *, int (*)(struct _reent *, FILE *));
+extern int _fwalk_sglue (struct _reent *, int (*)(struct _reent *, FILE *),
+ struct _glue *);
extern int __submore (struct _reent *, FILE *);
#ifdef __LARGE64_FILES
diff --git a/newlib/libc/stdio/refill.c b/newlib/libc/stdio/refill.c
index 31665bcd9..4084d7250 100644
--- a/newlib/libc/stdio/refill.c
+++ b/newlib/libc/stdio/refill.c
@@ -102,10 +102,10 @@ __srefill_r (struct _reent * ptr,
*/
if (fp->_flags & (__SLBF | __SNBF))
{
- /* Ignore this file in _fwalk_reent to avoid potential deadlock. */
+ /* Ignore this file in _fwalk_sglue to avoid potential deadlock. */
short orig_flags = fp->_flags;
fp->_flags = 1;
- (void) _fwalk_reent (_GLOBAL_REENT, lflush);
+ (void) _fwalk_sglue (_GLOBAL_REENT, lflush, &_GLOBAL_REENT->__sglue);
fp->_flags = orig_flags;
/* Now flush this file without locking it. */
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 1cecaa017..5bf6d8fc7 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -3058,7 +3058,8 @@ _cygwin_istext_for_stdio (int fd)
}
/* internal newlib function */
-extern "C" int _fwalk_reent (struct _reent *ptr, int (*function) (struct _reent *, FILE *));
+extern "C" int _fwalk_sglue (struct _reent *ptr,
+ int (*function) (struct _reent *, FILE *), struct _sglue *);
static int
setmode_helper (struct _reent *ptr __unused, FILE *f)
@@ -3137,7 +3138,7 @@ cygwin_setmode (int fd, int mode)
_my_tls.locals.setmode_mode = O_TEXT;
else
_my_tls.locals.setmode_mode = O_BINARY;
- _fwalk_reent (_GLOBAL_REENT, setmode_helper);
+ _fwalk_sglue (_GLOBAL_REENT, setmode_helper, &_GLOBAL_REENT->__sglue);
}
return res;
}
--
2.31.1
next prev parent reply other threads:[~2022-05-10 8:09 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-10 8:09 [PATCH 00/11] Decouple global file object list from _GLOBAL_REENT Matthew Joyce
2022-05-10 8:09 ` [PATCH 01/11] Remove duplicate stdio initializations Matthew Joyce
2022-05-10 8:09 ` [PATCH 02/11] Remove duplicate sglue initializations Matthew Joyce
2022-05-10 8:09 ` [PATCH 03/11] Declare global __sf[] only once Matthew Joyce
2022-05-10 8:09 ` [PATCH 04/11] Add two __sglue initialization macros Matthew Joyce
2022-05-10 8:09 ` [PATCH 05/11] Remove __sinit_locks / __sinit_recursive_mutex Matthew Joyce
2022-05-10 8:09 ` [PATCH 06/11] Move __sglue initializations to __sfp() Matthew Joyce
2022-05-10 8:09 ` [PATCH 07/11] Add CLEANUP_FILE define Matthew Joyce
2022-05-10 8:09 ` [PATCH 08/11] Add stdio atexit handler Matthew Joyce
2022-05-11 15:23 ` Corinna Vinschen
2022-05-11 16:54 ` Corinna Vinschen
2022-05-11 17:51 ` Sebastian Huber
2022-05-11 17:51 ` Sebastian Huber
2022-05-10 8:09 ` Matthew Joyce [this message]
2022-05-11 15:56 ` [PATCH 09/11] stdio: Replace _fwalk_reent() with _fwalk_sglue() Corinna Vinschen
2022-05-11 17:55 ` Sebastian Huber
2022-05-12 7:59 ` Corinna Vinschen
2022-05-10 8:09 ` [PATCH 10/11] Add global __sglue object for all configurations Matthew Joyce
2022-05-10 8:09 ` [PATCH 11/11] Remove __sglue member for one configuration Matthew Joyce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220510080927.28839-10-matthew.joyce@embedded-brains.de \
--to=matthew.joyce@embedded-brains.de \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).