This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[LIBIBERTY]: add function unlock_std_streams()
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: dj at redhat dot com, ian at airs dot com
- Date: Mon, 25 Apr 2005 07:37:17 -0400 (EDT)
- Subject: [LIBIBERTY]: add function unlock_std_streams()
Mark had requested/preapproved that I create this function:
http://gcc.gnu.org/ml/gcc-patches/2005-04/msg02528.html
I felt it should go in libiberty and I wanted to make sure there were
no objections from the libiberty maintainers.
(While there, I also fixed a whitespace formatting nit.)
Bootstrapped on x86_64-unknown-linux-gnu, no regressions.
Okay to install?
Thanks,
--Kaveh
2005-04-24 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
include:
* libiberty.h (unlock_std_streams): New.
libiberty:
* fopen_unlocked.c (unlock_std_streams): New.
* functions.texi: Regenerate.
diff -rup orig/egcc-CVS20050424/include/libiberty.h egcc-CVS20050424/include/libiberty.h
--- orig/egcc-CVS20050424/include/libiberty.h 2005-04-19 22:38:47.000000000 -0400
+++ egcc-CVS20050424/include/libiberty.h 2005-04-24 20:21:03.324707224 -0400
@@ -54,6 +54,12 @@ extern "C" {
extern void unlock_stream (FILE *);
+/* If the OS supports it, ensure that the standard I/O streams, stdin,
+ stdout and stderr are setup to avoid any multi-threaded locking.
+ Otherwise do nothing. */
+
+extern void unlock_std_streams (void);
+
/* Open and return a FILE pointer. If the OS supports it, ensure that
the stream is setup to avoid any multi-threaded locking. Otherwise
return the FILE pointer unchanged. */
diff -rup orig/egcc-CVS20050424/libiberty/fopen_unlocked.c egcc-CVS20050424/libiberty/fopen_unlocked.c
--- orig/egcc-CVS20050424/libiberty/fopen_unlocked.c 2005-04-16 21:33:26.000000000 -0400
+++ egcc-CVS20050424/libiberty/fopen_unlocked.c 2005-04-24 20:21:15.738819992 -0400
@@ -28,6 +28,14 @@ pointer unchanged. If the @var{stream}
@end deftypefn
+@deftypefn Extension void unlock_std_streams (void)
+
+If the OS supports it, ensure that the standard I/O streams,
+@code{stdin}, @code{stdout} and @code{stderr} are setup to avoid any
+multi-threaded locking. Otherwise do nothing.
+
+@end deftypefn
+
@deftypefn Extension FILE * fopen_unlocked (const char *@var{path}, const char * @var{mode})
Opens and returns a @code{FILE} pointer via @code{fopen}. If the
@@ -80,11 +88,19 @@ unlock_1 (FILE *const fp ATTRIBUTE_UNUSE
}
void
-unlock_stream(FILE *fp)
+unlock_stream (FILE *fp)
{
unlock_1 (fp);
}
+void
+unlock_std_streams (void)
+{
+ unlock_1 (stdin);
+ unlock_1 (stdout);
+ unlock_1 (stderr);
+}
+
FILE *
fopen_unlocked (const char *path, const char *mode)
{