public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Avoid RMW of flags2 outside lock (BZ #27842)
@ 2022-05-19 15:10 Wilco Dijkstra
  2022-05-19 15:25 ` Andreas Schwab
  2022-05-19 15:47 ` Adhemerval Zanella
  0 siblings, 2 replies; 6+ messages in thread
From: Wilco Dijkstra @ 2022-05-19 15:10 UTC (permalink / raw)
  To: 'GNU C Library'


Remove an unconditional RMW on flags2 in flockfile - if _IO_FLAGS2_NEED_LOCK
is set, we are single-threaded and we can safely clear the flag. This fixes
BZ #27842.

---

diff --git a/stdio-common/flockfile.c b/stdio-common/flockfile.c
index a5decb450f8d477e3105d02661282afeab58f88b..7ba9ab59082d2c1dfba7d5e9a91175c9dec7ec49 100644
--- a/stdio-common/flockfile.c
+++ b/stdio-common/flockfile.c
@@ -22,7 +22,10 @@
 void
 __flockfile (FILE *stream)
 {
-  stream->_flags2 |= _IO_FLAGS2_NEED_LOCK;
+  /* If we're single-threaded, turn off single-thread optimizations
+     when locking a file.  Avoid updating flags2 if multi-threaded.  */
+  if (!_IO_need_lock (stream))
+    stream->_flags2 |= _IO_FLAGS2_NEED_LOCK;
   _IO_lock_lock (*stream->_lock);
 }
 weak_alias (__flockfile, flockfile);

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-05-20 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19 15:10 [PATCH] Avoid RMW of flags2 outside lock (BZ #27842) Wilco Dijkstra
2022-05-19 15:25 ` Andreas Schwab
2022-05-19 15:47 ` Adhemerval Zanella
2022-05-19 16:26   ` Wilco Dijkstra
2022-05-19 16:57     ` Adhemerval Zanella
2022-05-20 10:34       ` Wilco Dijkstra

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).