From 10dcf7e718e250e222f00bc648c9cb43100edf88 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Thu, 25 Mar 2004 22:29:18 +0000 Subject: 2004-03-25 Thomas Pfaff * libc/stdio/fclose.c (fclose): Protect file pointer list when releasing a file. * libc/stdio/fcloseall.c (_fcloseall_r): Close all files via fwalk. * libc/stdio/fdopen.c (_fdopen_r): Add calls to _flockfile/_funlockfile. * libc/stdio/findfp.c: Move __sfp_lock. Change __sfp_lock type to recursive. Change __lock_acquire/__lock_release calls for __sfp_lock to __sfp_lock_acquire/__sfp_lock_release throughout. (std): Make sure that file lock is only initialized once. (__sfp): Move _file initialization. Initialize file lock. (__sfp_lock_acquire): New function. (__sfp_lock_release): Ditto. (__fp_lock_all): Remove __sfp_lock_acquire call. (__fp_unlock_all): Remove __sfp_lock_release call. * libc/stdio/fopen.c (_fopen_r): Protect file pointer list. Add calls to _flockfile/_funlockfile. Remove __lock_init_recursive call. * libc/stdio/freopen.c (_freopen_r): Protect file pointer list. * libc/stdio/fwalk.c (__fwalk): New static function. (_fwalk): Protect file pointer list. Use __fwalk to walk through file pointers. * libc/stdio/local.h: Add defines for __sfp_lock_acquire/__sfp_lock_release when single threaded. Add function prototypes otherwise. * libc/stdio64/fdopen64.c (_fdopen64_r): Add calls to _flockfile/_funlockfile. * libc/stdio/fopen64.c (_fopen64_r): Protect file pointer list. Add calls to _flockfile/_funlockfile. Remove __lock_init_recursive call. * libc/stdio/freopen64.c (_freopen64_r): Protect file pointer list. --- newlib/libc/stdio/fwalk.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'newlib/libc/stdio/fwalk.c') diff --git a/newlib/libc/stdio/fwalk.c b/newlib/libc/stdio/fwalk.c index b147da3af..566fa4af8 100644 --- a/newlib/libc/stdio/fwalk.c +++ b/newlib/libc/stdio/fwalk.c @@ -26,8 +26,8 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #include #include "local.h" -int -_fwalk (ptr, function) +static int +__fwalk (ptr, function) struct _reent *ptr; register int (*function) (); { @@ -35,20 +35,36 @@ _fwalk (ptr, function) register int n, ret = 0; register struct _glue *g; + for (g = &ptr->__sglue; g != NULL; g = g->_next) + for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) + if (fp->_flags != 0) + { + _flockfile (fp); + if (fp->_flags != 0 && fp->_file != -1) + ret |= (*function) (fp); + _funlockfile (fp); + } + + return ret; +} + +int +_fwalk (ptr, function) + struct _reent *ptr; + register int (*function) (); +{ + register int ret = 0; + + __sfp_lock_acquire (); + /* Must traverse given list for std streams. */ if (ptr != _GLOBAL_REENT) - { - for (g = &ptr->__sglue; g != NULL; g = g->_next) - for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) - if (fp->_flags != 0) - ret |= (*function) (fp); - } + ret |= __fwalk (ptr, function); /* Must traverse global list for all other streams. */ - for (g = &_GLOBAL_REENT->__sglue; g != NULL; g = g->_next) - for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) - if (fp->_flags != 0) - ret |= (*function) (fp); + ret |= __fwalk (_GLOBAL_REENT, function); + + __sfp_lock_release (); return ret; } -- cgit v1.2.3