From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 121423 invoked by alias); 7 Aug 2017 11:08:25 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 120096 invoked by uid 89); 7 Aug 2017 11:08:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1598, H*i:sk:5b3ee17, H*f:sk:5b3ee17, H*c:application X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Aug 2017 11:08:23 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 832D9806B4 for ; Mon, 7 Aug 2017 11:08:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 832D9806B4 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=vinschen@redhat.com Received: from calimero.vinschen.de (ovpn-117-128.ams2.redhat.com [10.36.117.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C06395239 for ; Mon, 7 Aug 2017 11:08:22 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id 81A8BA8056F; Mon, 7 Aug 2017 13:08:21 +0200 (CEST) Date: Mon, 07 Aug 2017 11:08:00 -0000 From: Corinna Vinschen To: newlib@sourceware.org Subject: Re: [PATCH] Proper locking for getchar() and putchar() Message-ID: <20170807110821.GB21011@calimero.vinschen.de> Reply-To: newlib@sourceware.org Mail-Followup-To: newlib@sourceware.org References: <20170807063330.16281-1-sebastian.huber@embedded-brains.de> <20170807094957.GA18389@calimero.vinschen.de> <5b3ee17d-6e9f-4421-b1d2-5279a7de9a28@embedded-brains.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mP3DRpeJDSE+ciuQ" Content-Disposition: inline In-Reply-To: <5b3ee17d-6e9f-4421-b1d2-5279a7de9a28@embedded-brains.de> User-Agent: Mutt/1.8.3 (2017-05-23) X-SW-Source: 2017/txt/msg00726.txt.bz2 --mP3DRpeJDSE+ciuQ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 1593 On Aug 7 12:53, Sebastian Huber wrote: > On 07/08/17 11:49, Corinna Vinschen wrote: >=20 > > Hi Sebastian, > >=20 > > On Aug 7 08:33, Sebastian Huber wrote: > > > +#ifdef __SINGLE_THREAD__ > > > +#define getc(_p) __sgetc_r(_REENT, _p) > > > +#define putc(_c, _p) __sputc_r(_REENT, _c, _p) > > > +#define getchar() _getchar_unlocked() > > > +#define putchar(_c) _putchar_unlocked(_c) > > > +#endif /* __SINGLE_THREAD__ */ > > > #endif /* __cplusplus */ > > That looks good, but I wonder, wouldn't it make sense to replace the > > inline _getchar_unlocked/_putchar_unlocked with inline > > _getc_unlocked/_puts_unlocked? > >=20 > > I'm asking because that would allow to #define all four, > > getc/putc/getchar/putchar, so that the parameters are only evaluated > > once. > >=20 > > What do you think? >=20 > For getc()/putc() you have the FILE object already and only need _REENT. >=20 > For getchar()/putchar() you have nothing and need the _REENT plus > stdin/stdout. >=20 > I don't know how you would unify/simplify this further? I wasn't thinking of simplification. You said it yourself, your implementation has the benefit of evaluating the reent pointer only once. While looking into your patch, it immediately struck me as beneficial to getc/putc, too. So I was thinking of something like inline _getc_unlocked (_p) { struct _reent *_ptr =3D _REENT; return (__sgetc_r(_ptr, _p)_; } #define getc(_p) _getc_unlocked(_p) #define getchar() _getc_unlocked(_stdin_r(_REENT)) Does that make sense? Thanks, Corinna --=20 Corinna Vinschen Cygwin Maintainer Red Hat --mP3DRpeJDSE+ciuQ Content-Type: application/pgp-signature; name="signature.asc" Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJZiEolAAoJEPU2Bp2uRE+g8lIP/AibfBuEBLdizf3sPDr9Sp5D fcUQlXj0xZRMZ/ZjAfqPhpoULD/OeZ4zmGg1keXLJUtfjxeNRo/vyZMX819SHsNH ksm7tp1gHrpvc7lU6TReAmcDtpLoSrsnZvYg9nMWANbhOC8IkISDb77/HvU8jE+q kKWMoapKqqHOjOCT2zlMnbBWlCsbGaroxr8GHcKBbpcG+VKHKcFu9nLLKYDY9CF7 xpWCThge2I+L7vjo9sWia0rMb7eveoj4zcYs5MpBDp5b/QcfX1o4RB9poCF99jHx 8als8EkCv9ub3oXiXDgJEk5MQJs1cY8HKPASQxvFE9859L7ChCV3yzedQT9OBC0N HDwKTouwS9ofiNfbsKu0KdUOP5bzsxphV4bzd6KYj7IP/vX7ddLQgb9qwXZdRifI wksJhTOIbUyYm5bw/f5ncUJpYhNaijE87PYLqhw5W/gcZCWAdDjw+m7WvGEBVr/9 SABwplxP10uxDYlreiVgK8hCgcUW7gdUz9dmytzABrWXI5eoZc6HLr1HIUHgX2eX ZhJ6tI8CHXfwm/H0Wa6DCPbe7dB8DkrdGDC27VRxQhzHQov+EI7osNXV9cc+UH1M R6+65Hk+Sn4Pb0bksJoQutEskWztW9Qu1R8crn1vtJRnrMhpojEbGZaWmEnP9jyx yg2DXgWCMaUM956rUCMI =rjaa -----END PGP SIGNATURE----- --mP3DRpeJDSE+ciuQ--