OSDN Git Service

2004-01-22 Thomas Pfaff <tpfaff@gmx.net>
authorjjohnstn <jjohnstn>
Thu, 22 Jan 2004 22:06:56 +0000 (22:06 +0000)
committerjjohnstn <jjohnstn>
Thu, 22 Jan 2004 22:06:56 +0000 (22:06 +0000)
        * libc/stdio/findfp.c (__sfp): Protect global FILE pointer list
        by a lock when newlib is multithreaded.

newlib/ChangeLog
newlib/libc/stdio/findfp.c

index a3e0ff9..0421e7e 100644 (file)
@@ -1,3 +1,8 @@
+2004-01-22  Thomas Pfaff  <tpfaff@gmx.net>
+
+       * libc/stdio/findfp.c (__sfp): Protect global FILE pointer list
+       by a lock when newlib is multithreaded. 
+
 2004-01-21  Jeff Johnston  <jjohnstn@redhat.com>
 
        * libc/stdlib/mbrtowc.c (_mbrtowc_r): Fix case where s is null
index aff231e..0ea7e31 100644 (file)
@@ -86,6 +86,12 @@ __sfp (d)
   int n;
   struct _glue *g;
 
+#ifndef __SINGLE_THREAD__
+  __LOCK_INIT(static, lock);
+
+  __lock_acquire(lock); 
+#endif
+
   if (!_GLOBAL_REENT->__sdidinit)
     __sinit (_GLOBAL_REENT);
   for (g = &_GLOBAL_REENT->__sglue;; g = g->_next)
@@ -97,11 +103,17 @@ __sfp (d)
          (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL)
        break;
     }
+#ifndef __SINGLE_THREAD__
+  __lock_release(lock); 
+#endif
   d->_errno = ENOMEM;
   return NULL;
 
 found:
   fp->_flags = 1;              /* reserve this slot; caller sets real flags */
+#ifndef __SINGLE_THREAD__
+  __lock_release(lock); 
+#endif
   fp->_p = NULL;               /* no current pointer */
   fp->_w = 0;                  /* nothing to read or write */
   fp->_r = 0;