Commit 6feaa084 by Kaveh R. Ghazi Committed by Kaveh Ghazi

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
parent 41704a38
2005-04-16 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* libiberty.h (unlock_stream): New.
2005-04-13 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2005-04-13 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* libiberty.h (fopen_unlocked, fdopen_unlocked, freopen_unlocked): * libiberty.h (fopen_unlocked, fdopen_unlocked, freopen_unlocked):
......
...@@ -48,6 +48,12 @@ extern "C" { ...@@ -48,6 +48,12 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
/* If the OS supports it, ensure that the supplied stream is setup to
avoid any multi-threaded locking. Otherwise leave the FILE pointer
unchanged. If the stream is NULL do nothing. */
extern void unlock_stream (FILE *);
/* Open and return a FILE pointer. If the OS supports it, ensure that /* Open and return a FILE pointer. If the OS supports it, ensure that
the stream is setup to avoid any multi-threaded locking. Otherwise the stream is setup to avoid any multi-threaded locking. Otherwise
return the FILE pointer unchanged. */ return the FILE pointer unchanged. */
......
2005-04-16 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* fopen_unlocked.c (unlock_stream): New.
Consolidate unlocking code into a helper function.
* functions.texi: Regenerate.
2005-04-13 Gabriel Dos Reis <gdr@integrable-solutions.net> 2005-04-13 Gabriel Dos Reis <gdr@integrable-solutions.net>
* asprintf.c: Include config.h. * asprintf.c: Include config.h.
......
...@@ -20,6 +20,14 @@ Boston, MA 02111-1307, USA. */ ...@@ -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}) @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 Opens and returns a @code{FILE} pointer via @code{fopen}. If the
...@@ -59,14 +67,29 @@ unchanged. ...@@ -59,14 +67,29 @@ unchanged.
#include "libiberty.h" #include "libiberty.h"
FILE * /* This is an inline helper function to consolidate attempts to unlock
fopen_unlocked (const char *path, const char *mode) 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 defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER)
if (fp) if (fp)
__fsetlocking (fp, FSETLOCKING_BYCALLER); __fsetlocking (fp, FSETLOCKING_BYCALLER);
#endif #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; return fp;
} }
...@@ -74,10 +97,7 @@ FILE * ...@@ -74,10 +97,7 @@ FILE *
fdopen_unlocked (int fildes, const char *mode) fdopen_unlocked (int fildes, const char *mode)
{ {
FILE *const fp = fdopen (fildes, mode); FILE *const fp = fdopen (fildes, mode);
#if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER) unlock_1 (fp);
if (fp)
__fsetlocking (fp, FSETLOCKING_BYCALLER);
#endif
return fp; return fp;
} }
...@@ -85,9 +105,6 @@ FILE * ...@@ -85,9 +105,6 @@ FILE *
freopen_unlocked (const char *path, const char *mode, FILE *stream) freopen_unlocked (const char *path, const char *mode, FILE *stream)
{ {
FILE *const fp = freopen (path, mode, stream); FILE *const fp = freopen (path, mode, stream);
#if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER) unlock_1 (fp);
if (fp)
__fsetlocking (fp, FSETLOCKING_BYCALLER);
#endif
return fp; return fp;
} }
...@@ -362,7 +362,7 @@ and inode numbers. ...@@ -362,7 +362,7 @@ and inode numbers.
@end deftypefn @end deftypefn
@c fopen_unlocked.c:32 @c fopen_unlocked.c:40
@deftypefn Extension FILE * fdopen_unlocked (int @var{fildes}, const char * @var{mode}) @deftypefn Extension FILE * fdopen_unlocked (int @var{fildes}, const char * @var{mode})
Opens and returns a @code{FILE} pointer via @code{fdopen}. If the Opens and returns a @code{FILE} pointer via @code{fdopen}. If the
...@@ -431,7 +431,7 @@ Ignores case when performing the comparison. ...@@ -431,7 +431,7 @@ Ignores case when performing the comparison.
@end deftypefn @end deftypefn
@c fopen_unlocked.c:23 @c fopen_unlocked.c:31
@deftypefn Extension FILE * fopen_unlocked (const char *@var{path}, const char * @var{mode}) @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 Opens and returns a @code{FILE} pointer via @code{fopen}. If the
...@@ -451,7 +451,7 @@ itself. ...@@ -451,7 +451,7 @@ itself.
@end deftypefn @end deftypefn
@c fopen_unlocked.c:41 @c fopen_unlocked.c:49
@deftypefn Extension FILE * freopen_unlocked (const char * @var{path}, const char * @var{mode}, FILE * @var{stream}) @deftypefn Extension FILE * freopen_unlocked (const char * @var{path}, const char * @var{mode}, FILE * @var{stream})
Opens and returns a @code{FILE} pointer via @code{freopen}. If the Opens and returns a @code{FILE} pointer via @code{freopen}. If the
...@@ -1201,6 +1201,15 @@ was made to unlink the file because it is special. ...@@ -1201,6 +1201,15 @@ was made to unlink the file because it is special.
@end deftypefn @end deftypefn
@c fopen_unlocked.c:23
@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
@c vasprintf.c:47 @c vasprintf.c:47
@deftypefn Extension int vasprintf (char **@var{resptr}, const char *@var{format}, va_list @var{args}) @deftypefn Extension int vasprintf (char **@var{resptr}, const char *@var{format}, va_list @var{args})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment