This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Properly protect the Communication class with reader/writer lock
ClosedPublic

Authored by augusto2112 on Aug 11 2023, 2:56 PM.

Details

Summary

This patch picks up where https://reviews.llvm.org/D157159 left of, but
allows for concurrent reads/writes, but protects setting up and tearing
down the underlying Connection object.

Diff Detail

Event Timeline

augusto2112 created this revision.Aug 11 2023, 2:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2023, 2:56 PM
augusto2112 requested review of this revision.Aug 11 2023, 2:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2023, 2:56 PM
bulbazord added inline comments.Aug 14 2023, 10:30 AM
lldb/include/lldb/Core/Communication.h
86–90

This isn't necessarily introduced by your patch, but I don't think this lock does much other than make sure nobody can change m_connection_sp in between you calling GetConnection and you actually receiving the Connection pointer. It still comes with all the pitfalls of handing out a raw pointer (instead of a shared_ptr).

As a follow-up or maybe even precursor, we should probably stop handing out the raw connection pointer...

JDevlieghere added inline comments.Aug 14 2023, 1:59 PM
lldb/include/lldb/Core/Communication.h
172–175

Why do we need both? Can't we use m_connection_mutex in write mode instead of m_write_mutex?

augusto2112 added inline comments.Aug 14 2023, 2:30 PM
lldb/include/lldb/Core/Communication.h
86–90

I agree. I think we should do it after this patch though.

172–175

If we use m_connection_mutex in write mode instead of m_write_mutex then we can't have concurrent reads and writes.

This revision was not accepted when it landed; it landed in state Needs Review.Aug 15 2023, 3:47 PM
This revision was automatically updated to reflect the committed changes.