[libc-commits] [libc] [libc] Lock the output stream for the 'puts' call (PR #76513)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Thu Dec 28 11:15:03 PST 2023


================
@@ -15,8 +15,21 @@
 
 namespace LIBC_NAMESPACE {
 
+// Simple helper to unlock the file once destroyed.
+struct ScopedLock {
+  ScopedLock(LIBC_NAMESPACE::File *stream) : stream(stream) { stream->lock(); }
+  ~ScopedLock() { stream->unlock(); }
+
+private:
+  LIBC_NAMESPACE::File *stream;
+};
+
 LLVM_LIBC_FUNCTION(int, puts, (const char *__restrict str)) {
----------------
jhuber6 wrote:

I think all of the implementations of string functions are like this. My best guess is that it's giving the same effect as `const char const *` without changing the signature or something. 

https://github.com/llvm/llvm-project/pull/76513


More information about the libc-commits mailing list