From: Corinna Vinschen <vinschen@redhat.com>
To: newlib@sourceware.org
Subject: Re: [PATCH] Fix __fp_lock_all() and __fp_unlock_all()
Date: Thu, 19 May 2022 14:02:49 +0200 [thread overview]
Message-ID: <YoYx6ZcIBvg+xvPQ@calimero.vinschen.de> (raw)
In-Reply-To: <20220518171307.53663-1-sebastian.huber@embedded-brains.de>
On May 18 19:13, Sebastian Huber wrote:
> For _REENT_GLOBAL_STDIO_STREAMS, lock/unlock all FILE objects. In the
> repository, this function is only used by Cygwin during process forks. Since
> Cygwin enabled _REENT_GLOBAL_STDIO_STREAMS recently, without this fix no FILE
> object at all was locked.
> ---
> newlib/libc/stdio/findfp.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
> index 6933ff1db..a39082387 100644
> --- a/newlib/libc/stdio/findfp.c
> +++ b/newlib/libc/stdio/findfp.c
> @@ -333,6 +333,8 @@ __fp_lock_all (void)
> #ifndef _REENT_GLOBAL_STDIO_STREAMS
> ptr = _REENT;
> (void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue);
> +#else
> + (void) _fwalk_sglue (NULL, __fp_lock, &__sglue);
> #endif
The resulting __fp_lock_all/__fp_unlock_all functions look a bit weird
to me, codewise. Counter-proposal:
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 118637a18f5b..ebfbf0976de5 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -329,31 +329,24 @@ __fp_unlock (struct _reent * ptr __unused, FILE * fp)
return 0;
}
+#ifdef _REENT_GLOBAL_STDIO_STREAMS
+# define _PTR NULL
+# define _GLUE __sglue
+#else
+# define _PTR _REENT
+# define _GLUE _PTR->__sglue
+#endif
+
void
__fp_lock_all (void)
{
-#ifndef _REENT_GLOBAL_STDIO_STREAMS
- struct _reent *ptr;
-#endif
-
- __sfp_lock_acquire ();
-
-#ifndef _REENT_GLOBAL_STDIO_STREAMS
- ptr = _REENT;
- (void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue);
-#endif
+ _fwalk_sglue (_PTR, __fp_lock, &_GLUE);
}
void
__fp_unlock_all (void)
{
-#ifndef _REENT_GLOBAL_STDIO_STREAMS
- struct _reent *ptr;
-
- ptr = _REENT;
- (void) _fwalk_sglue (ptr, __fp_unlock, &ptr->__sglue);
-#endif
-
+ _fwalk_sglue (_PTR, __fp_unlock, &_GLUE);
__sfp_lock_release ();
}
#endif
What do you think?
Thanks,
Corinna
next prev parent reply other threads:[~2022-05-19 12:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-18 17:13 Sebastian Huber
2022-05-18 17:13 ` [PATCH] Fix __sFILE::_lock initialization Sebastian Huber
2022-05-19 12:04 ` Corinna Vinschen
2022-05-18 17:13 ` [PATCH] Use weak reference for _REENT_SMALL Sebastian Huber
2022-05-19 12:05 ` Corinna Vinschen
2022-05-19 12:02 ` Corinna Vinschen [this message]
2022-05-19 17:08 ` [PATCH] Fix __fp_lock_all() and __fp_unlock_all() Sebastian Huber
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=YoYx6ZcIBvg+xvPQ@calimero.vinschen.de \
--to=vinschen@redhat.com \
--cc=newlib@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).