This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 04/20] unlocked stdio extensions


On 2014-12-17 14:10, Corinna Vinschen wrote:
On Dec 17 12:33, Yaakov Selkowitz wrote:
Index: libc/stdio/fflush_u.c
[snip]
Patch 01-03 are ok.  For this code here we should have a comment describing
what we do in _fflush_r only.  The comment here in _fflush_unlocked_r
should point to the comment in fflush_r instead.   Both comments should
clearly point out that a change requires to change both files.

Revised patch attached.

--
Yaakov Selkowitz
Associate Software Engineer, ARM
Red Hat, Inc.
Index: libc/stdio/fflush.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fflush.c,v
retrieving revision 1.20
diff -u -p -r1.20 fflush.c
--- libc/stdio/fflush.c	17 Jan 2014 10:55:31 -0000	1.20
+++ libc/stdio/fflush.c	17 Dec 2014 21:22:25 -0000
@@ -17,19 +17,32 @@
 
 /*
 FUNCTION
-<<fflush>>---flush buffered file output
+<<fflush>>, <<fflush_unlocked>>---flush buffered file output
 
 INDEX
 	fflush
 INDEX
+	fflush_unlocked
+INDEX
 	_fflush_r
+INDEX
+	_fflush_unlocked_r
 
 ANSI_SYNOPSIS
 	#include <stdio.h>
 	int fflush(FILE *<[fp]>);
 
+	#define _BSD_SOURCE
+	#include <stdio.h>
+	int fflush_unlocked(FILE *<[fp]>);
+
+	#include <stdio.h>
 	int _fflush_r(struct _reent *<[reent]>, FILE *<[fp]>);
 
+	#define _BSD_SOURCE
+	#include <stdio.h>
+	int _fflush_unlocked_r(struct _reent *<[reent]>, FILE *<[fp]>);
+
 DESCRIPTION
 The <<stdio>> output functions can buffer output before delivering it
 to the host system, in order to minimize the overhead of system calls.
@@ -45,9 +58,18 @@ descriptor, set the position of the file
 unread byte, useful for obeying POSIX semantics when ending a process
 without consuming all input from the stream.
 
-The alternate function <<_fflush_r>> is a reentrant version, where the
-extra argument <[reent]> is a pointer to a reentrancy structure, and
-<[fp]> must not be NULL.
+<<fflush_unlocked>> is a non-thread-safe version of <<fflush>>.
+<<fflush_unlocked>> may only safely be used within a scope
+protected by flockfile() (or ftrylockfile()) and funlockfile().  This
+function may safely be used in a multi-threaded program if and only
+if they are called while the invoking thread owns the (FILE *)
+object, as is the case after a successful call to the flockfile() or
+ftrylockfile() functions.  If threads are disabled, then
+<<fflush_unlocked>> is equivalent to <<fflush>>.
+
+The alternate functions <<_fflush_r>> and <<_fflush_unlocked_r>> are
+reentrant versions, where the extra argument <[reent]> is a pointer to
+a reentrancy structure, and <[fp]> must not be NULL.
 
 RETURNS
 <<fflush>> returns <<0>> unless it encounters a write error; in that
@@ -57,6 +79,8 @@ PORTABILITY
 ANSI C requires <<fflush>>.  The behavior on input streams is only
 specified by POSIX, and not all implementations follow POSIX rules.
 
+<<fflush_unlocked>> is a BSD extension also provided by GNU libc.
+
 No supporting OS subroutines are required.
 */
 
@@ -65,6 +89,12 @@ No supporting OS subroutines are require
 #include <errno.h>
 #include "local.h"
 
+#ifdef __IMPL_UNLOCKED__
+#define _fflush_r _fflush_unlocked_r
+#define fflush fflush_unlocked
+#endif
+
+#ifndef __IMPL_UNLOCKED__
 /* Flush a single file, or (if fp is NULL) all files.  */
 
 /* Core function which does not lock file pointer.  This gets called
@@ -217,6 +247,8 @@ _DEFUN(__sflushw_r, (ptr, fp),
 }
 #endif
 
+#endif /* __IMPL_UNLOCKED__ */
+
 int
 _DEFUN(_fflush_r, (ptr, fp),
        struct _reent *ptr _AND
@@ -235,7 +267,8 @@ _DEFUN(_fflush_r, (ptr, fp),
      are two alternatives to fix this:  1) make a reentrant fflush
      or 2) simply recognize that this file has nothing to flush
      and return immediately before performing a CHECK_INIT.  Choice
-     2 is implemented here due to its simplicity.  */
+     2 is implemented here due to its simplicity.  Any future change
+     must also be synced in fflush_u.c. */
   if (fp->_bf._base == NULL)
     return 0;
 #endif /* _REENT_SMALL  */
Index: libc/stdio/fflush_u.c
===================================================================
RCS file: libc/stdio/fflush_u.c
diff -N libc/stdio/fflush_u.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libc/stdio/fflush_u.c	17 Dec 2014 21:22:25 -0000
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#define __IMPL_UNLOCKED__
+#include "fflush.c"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]