From patchwork Thu Aug 18 08:54:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 56844 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0233D3854154 for ; Thu, 18 Aug 2022 08:56:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0233D3854154 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1660812969; bh=Ln8RqQQHP1HBdFrTdTZHzLWPKJkvgErKRznbGLvLcn8=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UDe8LaecYkbdUrLvMkmjeN93hx+RdTl5YRj40iLHZPiG1WISxilsn5/4iT+LAvJC5 XPOj5KXM963iosMTNmaNrWI1Mx9LlC5gHeB2wvmteGeYWTx/JjDO0sDIhLs2hw9Rbi mm2mFqes2j3dLdgw99jVa9XxZg4uFPOYAz4I2Sxk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E58263858029 for ; Thu, 18 Aug 2022 08:54:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E58263858029 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-562-_S2IOg_hNPajMy-TQti9ag-1; Thu, 18 Aug 2022 04:54:53 -0400 X-MC-Unique: _S2IOg_hNPajMy-TQti9ag-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8DD12185A7B2 for ; Thu, 18 Aug 2022 08:54:51 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BBF84010E49 for ; Thu, 18 Aug 2022 08:54:50 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH v4 06/11] stdio-common: Add lock optimization to vfprintf and vfwprintf In-Reply-To: References: X-From-Line: ebd7ff3c2772390a5293ed87fbcf699ceed84f54 Mon Sep 17 00:00:00 2001 Message-Id: Date: Thu, 18 Aug 2022 10:54:49 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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(+) 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. */