diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2004-03-25 22:29:18 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2004-03-25 22:29:18 +0000 |
commit | 10dcf7e718e250e222f00bc648c9cb43100edf88 (patch) | |
tree | 1cc4e335de067dd59ad3391266a0f4bd5e0e4018 /newlib/libc/stdio/findfp.c | |
parent | 4ee0dce2d7b81143c6b7ca5d8746ee3705f02ec4 (diff) | |
download | cygnal-10dcf7e718e250e222f00bc648c9cb43100edf88.tar.gz cygnal-10dcf7e718e250e222f00bc648c9cb43100edf88.tar.bz2 cygnal-10dcf7e718e250e222f00bc648c9cb43100edf88.zip |
2004-03-25 Thomas Pfaff <tpfaff@gmx.net>
* 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.
Diffstat (limited to 'newlib/libc/stdio/findfp.c')
-rw-r--r-- | newlib/libc/stdio/findfp.c | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index 0ddbf9403..10f01b271 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -25,10 +25,6 @@ #include <sys/lock.h> #include "local.h" -#ifndef __SINGLE_THREAD__ -__LOCK_INIT(static, __sfp_lock); -#endif - static void std (ptr, flags, file, data) FILE *ptr; @@ -49,8 +45,12 @@ std (ptr, flags, file, data) ptr->_write = __swrite; ptr->_seek = __sseek; ptr->_close = __sclose; -#ifndef __SINGLE_THREAD__ +#if !defined(__SINGLE_THREAD__) && !defined(_REENT_SMALL) __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&ptr->_lock); + /* + * #else + * lock is already initialized in __sfp + */ #endif #ifdef __SCLE @@ -90,9 +90,7 @@ __sfp (d) int n; struct _glue *g; -#ifndef __SINGLE_THREAD__ - __lock_acquire(__sfp_lock); -#endif + __sfp_lock_acquire (); if (!_GLOBAL_REENT->__sdidinit) __sinit (_GLOBAL_REENT); @@ -105,24 +103,24 @@ __sfp (d) (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL) break; } -#ifndef __SINGLE_THREAD__ - __lock_release(__sfp_lock); -#endif + __sfp_lock_release (); d->_errno = ENOMEM; return NULL; found: + fp->_file = -1; /* no file */ fp->_flags = 1; /* reserve this slot; caller sets real flags */ #ifndef __SINGLE_THREAD__ - __lock_release(__sfp_lock); + __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); #endif + __sfp_lock_release (); + fp->_p = NULL; /* no current pointer */ fp->_w = 0; /* nothing to read or write */ fp->_r = 0; fp->_bf._base = NULL; /* no buffer */ fp->_bf._size = 0; fp->_lbfsize = 0; /* not line buffered */ - fp->_file = -1; /* no file */ /* fp->_cookie = <any>; */ /* caller sets cookie, _read/_write etc */ fp->_ub._base = NULL; /* no ungetc buffer */ fp->_ub._size = 0; @@ -197,6 +195,20 @@ __sinit (s) #ifndef __SINGLE_THREAD__ +__LOCK_INIT_RECURSIVE(static, __sfp_lock); + +void +__sfp_lock_acquire () +{ + __lock_acquire(__sfp_lock); +} + +void +__sfp_lock_release () +{ + __lock_release(__sfp_lock); +} + /* Walkable file locking routine. */ static int __fp_lock (ptr) @@ -220,8 +232,6 @@ __fp_unlock (ptr) void __fp_lock_all () { - __lock_acquire(__sfp_lock); - (void) _fwalk (_REENT, __fp_lock); } @@ -229,7 +239,5 @@ void __fp_unlock_all () { (void) _fwalk (_REENT, __fp_unlock); - - __lock_release(__sfp_lock); } #endif |