stdio: Replace _fwalk_reent() with _fwalk_sglue()

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.
This commit is contained in:
Sebastian Huber 2022-04-01 13:32:32 +02:00
parent 26747c47bc
commit 3941c8a88a
8 changed files with 27 additions and 21 deletions

View File

@ -841,6 +841,9 @@ extern void (*__stdio_exit_handler) (void);
void _reclaim_reent (struct _reent *); void _reclaim_reent (struct _reent *);
extern int _fwalk_sglue (struct _reent *, int (*)(struct _reent *, __FILE *),
struct _glue *);
/* #define _REENT_ONLY define this to get only reentrant routines */ /* #define _REENT_ONLY define this to get only reentrant routines */
#if defined(__DYNAMIC_REENT__) && !defined(__SINGLE_THREAD__) #if defined(__DYNAMIC_REENT__) && !defined(__SINGLE_THREAD__)

View File

@ -59,7 +59,7 @@ Required OS subroutines: <<close>>, <<fstat>>, <<isatty>>, <<lseek>>,
int int
_fcloseall_r (struct _reent *ptr) _fcloseall_r (struct _reent *ptr)
{ {
return _fwalk_reent (ptr, _fclose_r); return _fwalk_sglue (ptr, _fclose_r, &ptr->__sglue);
} }
#ifndef _REENT_ONLY #ifndef _REENT_ONLY

View File

@ -286,7 +286,7 @@ int
fflush (register FILE * fp) fflush (register FILE * fp)
{ {
if (fp == NULL) 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); return _fflush_r (_REENT, fp);
} }

View File

@ -158,7 +158,7 @@ sfmoreglue (struct _reent *d, int n)
static void static void
stdio_exit_handler (void) stdio_exit_handler (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]) if (ptr->_stderr != &__sf[2])
CLEANUP_FILE (ptr, ptr->_stderr); CLEANUP_FILE (ptr, ptr->_stderr);
#endif #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 void
__fp_lock_all (void) __fp_lock_all (void)
{ {
struct _reent *ptr;
__sfp_lock_acquire (); __sfp_lock_acquire ();
(void) _fwalk_reent (_REENT, __fp_lock); ptr = _REENT;
(void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue);
} }
void void
__fp_unlock_all (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 (); __sfp_lock_release ();
} }

View File

@ -25,15 +25,13 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include "local.h"
int int
_fwalk_reent (struct _reent *ptr, _fwalk_sglue (struct _reent *ptr, int (*func) (struct _reent *, FILE *),
register int (*reent_function) (struct _reent *, FILE *)) struct _glue *g)
{ {
register FILE *fp; FILE *fp;
register int n, ret = 0; int n, ret = 0;
register struct _glue *g;
/* /*
* It should be safe to walk the list without locking it; * It should be safe to walk the list without locking it;
@ -43,10 +41,12 @@ _fwalk_reent (struct _reent *ptr,
* Avoid locking this list while walking it or else you will * Avoid locking this list while walking it or else you will
* introduce a potential deadlock in [at least] refill.c. * 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++) for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1) 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; return ret;
} }

View File

@ -182,7 +182,6 @@ extern int __stextmode (int);
extern void __sinit (struct _reent *); extern void __sinit (struct _reent *);
extern void __smakebuf_r (struct _reent *, FILE *); extern void __smakebuf_r (struct _reent *, FILE *);
extern int __swhatbuf_r (struct _reent *, FILE *, size_t *, int *); extern int __swhatbuf_r (struct _reent *, FILE *, size_t *, int *);
extern int _fwalk_reent (struct _reent *, int (*)(struct _reent *, FILE *));
extern int __submore (struct _reent *, FILE *); extern int __submore (struct _reent *, FILE *);
#ifdef __LARGE64_FILES #ifdef __LARGE64_FILES

View File

@ -102,10 +102,10 @@ __srefill_r (struct _reent * ptr,
*/ */
if (fp->_flags & (__SLBF | __SNBF)) 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; short orig_flags = fp->_flags;
fp->_flags = 1; fp->_flags = 1;
(void) _fwalk_reent (_GLOBAL_REENT, lflush); (void) _fwalk_sglue (_GLOBAL_REENT, lflush, &_GLOBAL_REENT->__sglue);
fp->_flags = orig_flags; fp->_flags = orig_flags;
/* Now flush this file without locking it. */ /* Now flush this file without locking it. */

View File

@ -63,6 +63,7 @@ details. */
#include "sync.h" #include "sync.h"
#include "child_info.h" #include "child_info.h"
#include <cygwin/fs.h> /* needed for RENAME_NOREPLACE */ #include <cygwin/fs.h> /* needed for RENAME_NOREPLACE */
#include <sys/reent.h> /* needed for _fwalk_sglue() declaration */
#undef _close #undef _close
#undef _lseek #undef _lseek
@ -3057,9 +3058,6 @@ _cygwin_istext_for_stdio (int fd)
return 1; return 1;
} }
/* internal newlib function */
extern "C" int _fwalk_reent (struct _reent *ptr, int (*function) (struct _reent *, FILE *));
static int static int
setmode_helper (struct _reent *ptr __unused, FILE *f) setmode_helper (struct _reent *ptr __unused, FILE *f)
{ {
@ -3137,7 +3135,7 @@ cygwin_setmode (int fd, int mode)
_my_tls.locals.setmode_mode = O_TEXT; _my_tls.locals.setmode_mode = O_TEXT;
else else
_my_tls.locals.setmode_mode = O_BINARY; _my_tls.locals.setmode_mode = O_BINARY;
_fwalk_reent (_GLOBAL_REENT, setmode_helper); _fwalk_sglue (_GLOBAL_REENT, setmode_helper, &_GLOBAL_REENT->__sglue);
} }
return res; return res;
} }