[v5,06/11] stdio-common: Add lock optimization to vfprintf and vfwprintf

Message ID a407f0532feffbc31a3fa89754dc2313bd56eb89.1670858473.git.fweimer@redhat.com
State Superseded
Headers
Series vfprintf refactor |

Commit Message

Florian Weimer Dec. 12, 2022, 3:23 p.m. UTC
  After the rewrite and the implicit unbuffered streams handling, this
is very straightforward to add.
---
 stdio-common/vfprintf-internal.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Adhemerval Zanella Netto Dec. 15, 2022, 3:58 p.m. UTC | #1
On 12/12/22 12:23, Florian Weimer via Libc-alpha wrote:
> After the rewrite and the implicit unbuffered streams handling, this
> is very straightforward to add.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  stdio-common/vfprintf-internal.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c
> index 83a6aea510..23ada8d0ff 100644
> --- a/stdio-common/vfprintf-internal.c
> +++ b/stdio-common/vfprintf-internal.c
> @@ -1452,6 +1452,14 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap, unsigned int mode_flags)
>      return EOF;
>  #endif
>  
> +  if (!_IO_need_lock (s))
> +    {
> +      struct Xprintf (buffer_to_file) wrap;
> +      Xprintf (buffer_to_file_init) (&wrap, s);
> +      Xprintf_buffer (&wrap.base, format, ap, mode_flags);
> +      return Xprintf (buffer_to_file_done) (&wrap);
> +    }
> +
>    int done;
>  
>    /* Lock stream.  */
  

Patch

diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c
index 83a6aea510..23ada8d0ff 100644
--- a/stdio-common/vfprintf-internal.c
+++ b/stdio-common/vfprintf-internal.c
@@ -1452,6 +1452,14 @@  vfprintf (FILE *s, const CHAR_T *format, va_list ap, unsigned int mode_flags)
     return EOF;
 #endif
 
+  if (!_IO_need_lock (s))
+    {
+      struct Xprintf (buffer_to_file) wrap;
+      Xprintf (buffer_to_file_init) (&wrap, s);
+      Xprintf_buffer (&wrap.base, format, ap, mode_flags);
+      return Xprintf (buffer_to_file_done) (&wrap);
+    }
+
   int done;
 
   /* Lock stream.  */