From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1921) id 3235E3843852; Fri, 13 May 2022 11:20:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3235E3843852 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Sebastian Huber To: cygwin-cvs@sourceware.org, newlib-cvs@sourceware.org Subject: [newlib-cygwin] stdio: Replace _fwalk_reent() with _fwalk_sglue() X-Act-Checkin: newlib-cygwin X-Git-Author: Sebastian Huber X-Git-Refname: refs/heads/master X-Git-Oldrev: 26747c47bc0a1137e02e0377306d721cc3478855 X-Git-Newrev: 3941c8a88ad1a1670ceac6e1889496174efd398f Message-Id: <20220513112007.3235E3843852@sourceware.org> Date: Fri, 13 May 2022 11:20:07 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 11:20:07 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D3941c8a88ad= 1a1670ceac6e1889496174efd398f commit 3941c8a88ad1a1670ceac6e1889496174efd398f Author: Sebastian Huber Date: Fri Apr 1 13:32:32 2022 +0200 stdio: Replace _fwalk_reent() with _fwalk_sglue() =20 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. Diff: --- newlib/libc/include/sys/reent.h | 3 +++ newlib/libc/stdio/fcloseall.c | 2 +- newlib/libc/stdio/fflush.c | 2 +- newlib/libc/stdio/findfp.c | 14 ++++++++++---- newlib/libc/stdio/fwalk.c | 16 ++++++++-------- newlib/libc/stdio/local.h | 1 - newlib/libc/stdio/refill.c | 4 ++-- winsup/cygwin/syscalls.cc | 6 ++---- 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reen= t.h index 067294dc7..469f2df28 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -841,6 +841,9 @@ extern void (*__stdio_exit_handler) (void); =20 void _reclaim_reent (struct _reent *); =20 +extern int _fwalk_sglue (struct _reent *, int (*)(struct _reent *, __FILE = *), + struct _glue *); + /* #define _REENT_ONLY define this to get only reentrant routines */ =20 #if defined(__DYNAMIC_REENT__) && !defined(__SINGLE_THREAD__) 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: <>, <>, <>= , <>, int _fcloseall_r (struct _reent *ptr) { - return _fwalk_reent (ptr, _fclose_r); + return _fwalk_sglue (ptr, _fclose_r, &ptr->__sglue); } =20 #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 =3D=3D NULL) - return _fwalk_reent (_GLOBAL_REENT, _fflush_r); + return _fwalk_sglue (_GLOBAL_REENT, _fflush_r, &_GLOBAL_REENT->__sglue= ); =20 return _fflush_r (_REENT, fp); } diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index 719886e27..1627032a3 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_exit_handler (void) { - (void) _fwalk_reent (_GLOBAL_REENT, CLEANUP_FILE); + (void) _fwalk_sglue (_GLOBAL_REENT, CLEANUP_FILE, &_GLOBAL_REENT->__sglu= e); } =20 /* @@ -240,7 +240,7 @@ cleanup_stdio (struct _reent *ptr) if (ptr->_stderr !=3D &__sf[2]) CLEANUP_FILE (ptr, ptr->_stderr); #endif - (void) _fwalk_reent (ptr, CLEANUP_FILE); + (void) _fwalk_sglue (ptr, CLEANUP_FILE, &ptr->__sglue); } =20 /* @@ -323,15 +323,21 @@ __fp_unlock (struct _reent * ptr __unused, FILE * fp) void __fp_lock_all (void) { + struct _reent *ptr; + __sfp_lock_acquire (); =20 - (void) _fwalk_reent (_REENT, __fp_lock); + ptr =3D _REENT; + (void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue); } =20 void __fp_unlock_all (void) { - (void) _fwalk_reent (_REENT, __fp_unlock); + struct _reent *ptr; + + ptr =3D _REENT; + (void) _fwalk_sglue (ptr, __fp_unlock, &ptr->__sglue); =20 __sfp_lock_release (); } diff --git a/newlib/libc/stdio/fwalk.c b/newlib/libc/stdio/fwalk.c index 2cefcc40e..b1284c6ea 100644 --- a/newlib/libc/stdio/fwalk.c +++ b/newlib/libc/stdio/fwalk.c @@ -25,15 +25,13 @@ static char sccsid[] =3D "%W% (Berkeley) %G%"; #include #include #include -#include "local.h" =20 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 =3D 0; - register struct _glue *g; + FILE *fp; + int n, ret =3D 0; =20 /* * 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 * introduce a potential deadlock in [at least] refill.c. */ - for (g =3D &ptr->__sglue; g !=3D NULL; g =3D g->_next) + do { for (fp =3D g->_iobs, n =3D g->_niobs; --n >=3D 0; fp++) if (fp->_flags !=3D 0 && fp->_flags !=3D 1 && fp->_file !=3D -1) - ret |=3D (*reent_function) (ptr, fp); + ret |=3D (*func) (ptr, fp); + g =3D g->_next; + } while (g !=3D NULL); =20 return ret; } diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h index 9c6f63fdb..e245fdb4e 100644 --- a/newlib/libc/stdio/local.h +++ b/newlib/libc/stdio/local.h @@ -182,7 +182,6 @@ extern int __stextmode (int); extern void __sinit (struct _reent *); 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 __submore (struct _reent *, FILE *); =20 #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 =3D fp->_flags; fp->_flags =3D 1; - (void) _fwalk_reent (_GLOBAL_REENT, lflush); + (void) _fwalk_sglue (_GLOBAL_REENT, lflush, &_GLOBAL_REENT->__sglue); fp->_flags =3D orig_flags; =20 /* Now flush this file without locking it. */ diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 1cecaa017..fb994ac41 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -63,6 +63,7 @@ details. */ #include "sync.h" #include "child_info.h" #include /* needed for RENAME_NOREPLACE */ +#include /* needed for _fwalk_sglue() declaration */ =20 #undef _close #undef _lseek @@ -3057,9 +3058,6 @@ _cygwin_istext_for_stdio (int fd) return 1; } =20 -/* internal newlib function */ -extern "C" int _fwalk_reent (struct _reent *ptr, int (*function) (struct _= reent *, FILE *)); - static int setmode_helper (struct _reent *ptr __unused, FILE *f) { @@ -3137,7 +3135,7 @@ cygwin_setmode (int fd, int mode) _my_tls.locals.setmode_mode =3D O_TEXT; else _my_tls.locals.setmode_mode =3D O_BINARY; - _fwalk_reent (_GLOBAL_REENT, setmode_helper); + _fwalk_sglue (_GLOBAL_REENT, setmode_helper, &_GLOBAL_REENT->__sglue= ); } return res; }