From bb7c983c5abf9cb8d8b827b24cd82e40c227e36b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 16 Dec 2015 22:59:06 +0000 Subject: [PATCH] Drop an unnecessary use of writev. It looks like the code this patch deletes is based on a misunderstanding of what guarantees writev provides. In particular, writev with 1 iovec is not "more atomic" than a write. Testing on OS X shows that both write and writev from multiple processes can be intermixed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255837 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/raw_ostream.h | 14 -------------- lib/Support/raw_ostream.cpp | 18 ++---------------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h index e5cc40e7d6b..d1e96f892a4 100644 --- a/include/llvm/Support/raw_ostream.h +++ b/include/llvm/Support/raw_ostream.h @@ -349,10 +349,6 @@ class raw_fd_ostream : public raw_pwrite_stream { /// bool Error; - /// Controls whether the stream should attempt to use atomic writes, when - /// possible. - bool UseAtomicWrites; - uint64_t pos; bool SupportsSeeking; @@ -402,16 +398,6 @@ public: /// to the offset specified from the beginning of the file. uint64_t seek(uint64_t off); - /// Set the stream to attempt to use atomic writes for individual output - /// routines where possible. - /// - /// Note that because raw_ostream's are typically buffered, this flag is only - /// sensible when used on unbuffered streams which will flush their output - /// immediately. - void SetUseAtomicWrites(bool Value) { - UseAtomicWrites = Value; - } - raw_ostream &changeColor(enum Colors colors, bool bold=false, bool bg=false) override; raw_ostream &resetColor() override; diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 49ef400c5f2..57c7ac32f55 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -517,7 +517,7 @@ raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC, /// closes the file when the stream is destroyed. raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered) : raw_pwrite_stream(unbuffered), FD(fd), ShouldClose(shouldClose), - Error(false), UseAtomicWrites(false) { + Error(false) { if (FD < 0 ) { ShouldClose = false; return; @@ -568,21 +568,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { pos += Size; do { - ssize_t ret; - - // Check whether we should attempt to use atomic writes. - if (LLVM_LIKELY(!UseAtomicWrites)) { - ret = ::write(FD, Ptr, Size); - } else { - // Use ::writev() where available. -#if defined(HAVE_WRITEV) - const void *Addr = static_cast(Ptr); - struct iovec IOV = {const_cast(Addr), Size }; - ret = ::writev(FD, &IOV, 1); -#else - ret = ::write(FD, Ptr, Size); -#endif - } + ssize_t ret = ::write(FD, Ptr, Size); if (ret < 0) { // If it's a recoverable error, swallow it and retry the write.