[Lldb-commits] [PATCH] D111396: [lldb] [ConnectionFileDescriptorPosix] Combine m_read_sp & m_write_sp
This revision was automatically updated to reflect the committed changes. Closed by commit rGfee461b1d830: [lldb] [ConnectionFileDescriptorPosix] Combine m_read_sp m_write_sp (authored by mgorny). Herald added a project: LLDB. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D111396/new/ https://reviews.llvm.org/D111396 Files: lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp Index: lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp === --- lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -63,9 +63,8 @@ ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd) : Connection(), m_pipe(), m_mutex(), m_shutting_down(false), m_waiting_for_accept(false), m_child_processes_inherit(false) { - m_write_sp = + m_io_sp = std::make_shared(fd, File::eOpenOptionReadWrite, owns_fd); - m_read_sp = m_write_sp; Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); @@ -120,8 +119,7 @@ } bool ConnectionFileDescriptor::IsConnected() const { - return (m_read_sp && m_read_sp->IsValid()) || - (m_write_sp && m_write_sp->IsValid()); + return m_io_sp && m_io_sp->IsValid(); } ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path, @@ -191,9 +189,8 @@ return eConnectionStatusSuccess; } - if (m_read_sp && m_read_sp->IsValid() && - m_read_sp->GetFdType() == IOObject::eFDTypeSocket) -static_cast(*m_read_sp).PreDisconnect(); + if (m_io_sp->GetFdType() == IOObject::eFDTypeSocket) +static_cast(*m_io_sp).PreDisconnect(); // Try to get the ConnectionFileDescriptor's mutex. If we fail, that is // quite likely because somebody is doing a blocking read on our file @@ -222,12 +219,11 @@ // Prevents reads and writes during shutdown. m_shutting_down = true; - Status error = m_read_sp->Close(); - Status error2 = m_write_sp->Close(); - if (error.Fail() || error2.Fail()) + Status error = m_io_sp->Close(); + if (error.Fail()) status = eConnectionStatusError; if (error_ptr) -*error_ptr = error.Fail() ? error : error2; +*error_ptr = error; // Close any pipes we were using for async interrupts m_pipe.Close(); @@ -269,14 +265,14 @@ Status error; size_t bytes_read = dst_len; - error = m_read_sp->Read(dst, bytes_read); + error = m_io_sp->Read(dst, bytes_read); if (log) { LLDB_LOGF(log, "%p ConnectionFileDescriptor::Read() fd = %" PRIu64 ", dst = %p, dst_len = %" PRIu64 ") => %" PRIu64 ", error = %s", static_cast(this), - static_cast(m_read_sp->GetWaitableHandle()), + static_cast(m_io_sp->GetWaitableHandle()), static_cast(dst), static_cast(dst_len), static_cast(bytes_read), error.AsCString()); } @@ -295,7 +291,7 @@ switch (error_value) { case EAGAIN: // The file was marked for non-blocking I/O, and no data were // ready to be read. - if (m_read_sp->GetFdType() == IOObject::eFDTypeSocket) + if (m_io_sp->GetFdType() == IOObject::eFDTypeSocket) status = eConnectionStatusTimedOut; else status = eConnectionStatusSuccess; @@ -373,14 +369,14 @@ Status error; size_t bytes_sent = src_len; - error = m_write_sp->Write(src, bytes_sent); + error = m_io_sp->Write(src, bytes_sent); if (log) { LLDB_LOGF(log, "%p ConnectionFileDescriptor::Write(fd = %" PRIu64 ", src = %p, src_len = %" PRIu64 ") => %" PRIu64 " (error = %s)", static_cast(this), - static_cast(m_write_sp->GetWaitableHandle()), + static_cast(m_io_sp->GetWaitableHandle()), static_cast(src), static_cast(src_len), static_cast(bytes_sent), error.AsCString()); } @@ -443,7 +439,7 @@ // Make a copy of the file descriptors to make sure we don't have another // thread change these values out from under us and cause problems in the // loop below where like in FS_SET() - const IOObject::WaitableHandle handle = m_read_sp->GetWaitableHandle(); + const IOObject::WaitableHandle handle = m_io_sp->GetWaitableHandle(); const int pipe_fd = m_pipe.GetReadFileDescriptor(); if (handle != IOObject::kInvalidHandleValue) { @@ -464,7 +460,7 @@ if (have_pipe_fd) select_helper.FDSetRead(pipe_fd); -while (handle == m_read_sp->GetWaitableHandle()) { +while (handle == m_io_sp->GetWaitableHandle()) { Status error = select_helper.Select(); @@ -533,11 +529,9 @@ Socket::UnixDomainAccept(socket_name, m_child_processes_inherit, socket); if (error_ptr) *error_ptr = error; -
[Lldb-commits] [PATCH] D111396: [lldb] [ConnectionFileDescriptorPosix] Combine m_read_sp & m_write_sp
labath accepted this revision. labath added a comment. This revision is now accepted and ready to land. seems like a nice cleanup CHANGES SINCE LAST ACTION https://reviews.llvm.org/D111396/new/ https://reviews.llvm.org/D111396 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D111396: [lldb] [ConnectionFileDescriptorPosix] Combine m_read_sp & m_write_sp
mgorny created this revision. mgorny added reviewers: labath, teemperor, krytarowski, emaste. mgorny requested review of this revision. Combine m_read_sp and m_write_sp into a single m_io_sp. In all currently existing code paths, they are pointing to the same object anyway. https://reviews.llvm.org/D111396 Files: lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp Index: lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp === --- lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp +++ lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp @@ -63,9 +63,8 @@ ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd) : Connection(), m_pipe(), m_mutex(), m_shutting_down(false), m_waiting_for_accept(false), m_child_processes_inherit(false) { - m_write_sp = + m_io_sp = std::make_shared(fd, File::eOpenOptionReadWrite, owns_fd); - m_read_sp = m_write_sp; Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); @@ -120,8 +119,7 @@ } bool ConnectionFileDescriptor::IsConnected() const { - return (m_read_sp && m_read_sp->IsValid()) || - (m_write_sp && m_write_sp->IsValid()); + return m_io_sp && m_io_sp->IsValid(); } ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path, @@ -191,9 +189,8 @@ return eConnectionStatusSuccess; } - if (m_read_sp && m_read_sp->IsValid() && - m_read_sp->GetFdType() == IOObject::eFDTypeSocket) -static_cast(*m_read_sp).PreDisconnect(); + if (m_io_sp->GetFdType() == IOObject::eFDTypeSocket) +static_cast(*m_io_sp).PreDisconnect(); // Try to get the ConnectionFileDescriptor's mutex. If we fail, that is // quite likely because somebody is doing a blocking read on our file @@ -222,12 +219,11 @@ // Prevents reads and writes during shutdown. m_shutting_down = true; - Status error = m_read_sp->Close(); - Status error2 = m_write_sp->Close(); - if (error.Fail() || error2.Fail()) + Status error = m_io_sp->Close(); + if (error.Fail()) status = eConnectionStatusError; if (error_ptr) -*error_ptr = error.Fail() ? error : error2; +*error_ptr = error; // Close any pipes we were using for async interrupts m_pipe.Close(); @@ -269,14 +265,14 @@ Status error; size_t bytes_read = dst_len; - error = m_read_sp->Read(dst, bytes_read); + error = m_io_sp->Read(dst, bytes_read); if (log) { LLDB_LOGF(log, "%p ConnectionFileDescriptor::Read() fd = %" PRIu64 ", dst = %p, dst_len = %" PRIu64 ") => %" PRIu64 ", error = %s", static_cast(this), - static_cast(m_read_sp->GetWaitableHandle()), + static_cast(m_io_sp->GetWaitableHandle()), static_cast(dst), static_cast(dst_len), static_cast(bytes_read), error.AsCString()); } @@ -295,7 +291,7 @@ switch (error_value) { case EAGAIN: // The file was marked for non-blocking I/O, and no data were // ready to be read. - if (m_read_sp->GetFdType() == IOObject::eFDTypeSocket) + if (m_io_sp->GetFdType() == IOObject::eFDTypeSocket) status = eConnectionStatusTimedOut; else status = eConnectionStatusSuccess; @@ -373,14 +369,14 @@ Status error; size_t bytes_sent = src_len; - error = m_write_sp->Write(src, bytes_sent); + error = m_io_sp->Write(src, bytes_sent); if (log) { LLDB_LOGF(log, "%p ConnectionFileDescriptor::Write(fd = %" PRIu64 ", src = %p, src_len = %" PRIu64 ") => %" PRIu64 " (error = %s)", static_cast(this), - static_cast(m_write_sp->GetWaitableHandle()), + static_cast(m_io_sp->GetWaitableHandle()), static_cast(src), static_cast(src_len), static_cast(bytes_sent), error.AsCString()); } @@ -443,7 +439,7 @@ // Make a copy of the file descriptors to make sure we don't have another // thread change these values out from under us and cause problems in the // loop below where like in FS_SET() - const IOObject::WaitableHandle handle = m_read_sp->GetWaitableHandle(); + const IOObject::WaitableHandle handle = m_io_sp->GetWaitableHandle(); const int pipe_fd = m_pipe.GetReadFileDescriptor(); if (handle != IOObject::kInvalidHandleValue) { @@ -464,7 +460,7 @@ if (have_pipe_fd) select_helper.FDSetRead(pipe_fd); -while (handle == m_read_sp->GetWaitableHandle()) { +while (handle == m_io_sp->GetWaitableHandle()) { Status error = select_helper.Select(); @@ -533,11 +529,9 @@ Socket::UnixDomainAccept(socket_name, m_child_processes_inherit, socket); if (error_ptr) *error_ptr = error; - m_write_sp.reset(socket); - m_read_sp = m_write_sp; - if