public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] readelf: Call __fsetlocking (stdout, FSETLOCKING_BYCALLER).
Date: Mon, 04 Jun 2018 16:55:00 -0000	[thread overview]
Message-ID: <1528131293-2191-1-git-send-email-mark@klomp.org> (raw)

We only call printf on stdout from one thread, so we don't need internal
stdio locking for stdout.

On my machine eu-readelf -N --debug-dump=info libxul.so > /dev/null
goes from 65 seconds to 63 seconds.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog | 4 ++++
 src/readelf.c | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/src/ChangeLog b/src/ChangeLog
index cc12d83..19f4210 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2018-06-04  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (main): Call __fsetlocking (stdout, FSETLOCKING_BYCALLER).
+
 2018-05-31  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (print_debug_units): Print the dwo name and id when
diff --git a/src/readelf.c b/src/readelf.c
index 0725313..a578b27 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -35,6 +35,8 @@
 #include <locale.h>
 #include <stdarg.h>
 #include <stdbool.h>
+#include <stdio.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
@@ -310,6 +312,9 @@ static void dump_archive_index (Elf *, const char *);
 int
 main (int argc, char *argv[])
 {
+  /* We use no threads here which can interfere with handling a stream.  */
+  (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER);
+
   /* Set locale.  */
   setlocale (LC_ALL, "");
 
-- 
1.8.3.1

             reply	other threads:[~2018-06-04 16:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-04 16:55 Mark Wielaard [this message]
2018-06-06 20:34 ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1528131293-2191-1-git-send-email-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).