llvm.org GIT mirror llvm / bb7c983
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 Rafael Espindola 3 years ago
2 changed file(s) with 2 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
348348 ///
349349 bool Error;
350350
351 /// Controls whether the stream should attempt to use atomic writes, when
352 /// possible.
353 bool UseAtomicWrites;
354
355351 uint64_t pos;
356352
357353 bool SupportsSeeking;
401397 /// to the offset specified from the beginning of the file.
402398 uint64_t seek(uint64_t off);
403399
404 /// Set the stream to attempt to use atomic writes for individual output
405 /// routines where possible.
406 ///
407 /// Note that because raw_ostream's are typically buffered, this flag is only
408 /// sensible when used on unbuffered streams which will flush their output
409 /// immediately.
410 void SetUseAtomicWrites(bool Value) {
411 UseAtomicWrites = Value;
412 }
413
414400 raw_ostream &changeColor(enum Colors colors, bool bold=false,
415401 bool bg=false) override;
416402 raw_ostream &resetColor() override;
516516 /// closes the file when the stream is destroyed.
517517 raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered)
518518 : raw_pwrite_stream(unbuffered), FD(fd), ShouldClose(shouldClose),
519 Error(false), UseAtomicWrites(false) {
519 Error(false) {
520520 if (FD < 0 ) {
521521 ShouldClose = false;
522522 return;
567567 pos += Size;
568568
569569 do {
570 ssize_t ret;
571
572 // Check whether we should attempt to use atomic writes.
573 if (LLVM_LIKELY(!UseAtomicWrites)) {
574 ret = ::write(FD, Ptr, Size);
575 } else {
576 // Use ::writev() where available.
577 #if defined(HAVE_WRITEV)
578 const void *Addr = static_cast(Ptr);
579 struct iovec IOV = {const_cast(Addr), Size };
580 ret = ::writev(FD, &IOV, 1);
581 #else
582 ret = ::write(FD, Ptr, Size);
583 #endif
584 }
570 ssize_t ret = ::write(FD, Ptr, Size);
585571
586572 if (ret < 0) {
587573 // If it's a recoverable error, swallow it and retry the write.