aboutsummaryrefslogtreecommitdiff
path: root/libiberty/fopen_unlocked.c
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2005-04-16 16:58:35 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2005-04-16 16:58:35 +0000
commit6feaa084f88c96b72f840c2e9ed280fc742b1f98 (patch)
treed156f4f535f6fa53299a5cfac16c2d29a981988e /libiberty/fopen_unlocked.c
parent41704a387ef7a69778f2d06325b1c10b800bca0d (diff)
downloadgcc-6feaa084f88c96b72f840c2e9ed280fc742b1f98.zip
gcc-6feaa084f88c96b72f840c2e9ed280fc742b1f98.tar.gz
gcc-6feaa084f88c96b72f840c2e9ed280fc742b1f98.tar.bz2
libiberty.h (unlock_stream): New.
include: * libiberty.h (unlock_stream): New. libiberty: * fopen_unlocked.c (unlock_stream): New. Consolidate unlocking code into a helper function. * functions.texi: Regenerate. From-SVN: r98234
Diffstat (limited to 'libiberty/fopen_unlocked.c')
-rw-r--r--libiberty/fopen_unlocked.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/libiberty/fopen_unlocked.c b/libiberty/fopen_unlocked.c
index b193dfd..8f9f300 100644
--- a/libiberty/fopen_unlocked.c
+++ b/libiberty/fopen_unlocked.c
@@ -20,6 +20,14 @@ Boston, MA 02111-1307, USA. */
/*
+@deftypefn Extension void unlock_stream (FILE * @var{stream})
+
+If the OS supports it, ensure that the supplied stream is setup to
+avoid any multi-threaded locking. Otherwise leave the @code{FILE}
+pointer unchanged. If the @var{stream} is @code{NULL} 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
@@ -59,14 +67,29 @@ unchanged.
#include "libiberty.h"
-FILE *
-fopen_unlocked (const char *path, const char *mode)
+/* This is an inline helper function to consolidate attempts to unlock
+ a stream. */
+
+static inline void
+unlock_1 (FILE *const fp ATTRIBUTE_UNUSED)
{
- FILE *const fp = fopen (path, mode);
#if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER)
if (fp)
__fsetlocking (fp, FSETLOCKING_BYCALLER);
#endif
+}
+
+void
+unlock_stream(FILE *fp)
+{
+ unlock_1 (fp);
+}
+
+FILE *
+fopen_unlocked (const char *path, const char *mode)
+{
+ FILE *const fp = fopen (path, mode);
+ unlock_1 (fp);
return fp;
}
@@ -74,10 +97,7 @@ FILE *
fdopen_unlocked (int fildes, const char *mode)
{
FILE *const fp = fdopen (fildes, mode);
-#if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER)
- if (fp)
- __fsetlocking (fp, FSETLOCKING_BYCALLER);
-#endif
+ unlock_1 (fp);
return fp;
}
@@ -85,9 +105,6 @@ FILE *
freopen_unlocked (const char *path, const char *mode, FILE *stream)
{
FILE *const fp = freopen (path, mode, stream);
-#if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER)
- if (fp)
- __fsetlocking (fp, FSETLOCKING_BYCALLER);
-#endif
+ unlock_1 (fp);
return fp;
}