Page MenuHomePhabricator

first pass for removing Mutex for std::{,recursive_}mutex
ClosedPublic

Authored by compnerd on May 15 2016, 6:10 PM.

Details

Summary

This is a pretty straightforward first pass over removing a number of uses of Mutex in favor of std::mutex or std::recursive_mutex. The problem is that there are interfaces which take Mutex::Locker & to lock internal locks. This patch cleans up most of the easy cases. The only non-trivial change is in CommandObjectTarget.cpp where a Mutex::Locker was split into two.

Although the patch is trivial, the question that I have is whether we should go ahead with this change and if doing it in multiple passes is reasonable.

Diff Detail

Event Timeline

compnerd updated this revision to Diff 57313.May 15 2016, 6:10 PM
compnerd retitled this revision from to first pass for removing Mutex for std::{,recursive_}mutex.
compnerd updated this object.
compnerd added reviewers: clayborg, zturner.
compnerd added a subscriber: lldb-commits.
zturner edited edge metadata.May 15 2016, 7:27 PM
zturner added a subscriber: zturner.

Personally I'm strongly in favor of standardizing on builtin language
constructs.

We already use std mutex in some places, and llvm does too, so i see no
issue with compiler support. I can't review the patch at the moment, but
please do make sure it's clang formatted

I don't think I can write code without clang-format anymore (so, yes, it is clang-formatted).

Figured as much, just making sure. What platforms did you run the test
suite on to confirm no breakages?

Looks good, however could we merge firstly Plugins/Process/NetBSD http://reviews.llvm.org/D20274 ? Otherwise I will need to keep syncing my patch forever for generic changes.

Thanks!

Looking at the 2 patches, they seem to be completely independent of each
other. Would this patch going in break you somehow?

There is Mutex:: used in my code. And it's going to be removed soon.

labath added a subscriber: labath.May 16 2016, 2:13 AM

Looks good, however could we merge firstly Plugins/Process/NetBSD http://reviews.llvm.org/D20274 ? Otherwise I will need to keep syncing my patch forever for generic changes.

Thanks!

I don't think we should connect these two patches in any way. What you are asking for here amounts to "let me merge my patch first, so that you can deal with the merge conflicts".

Also, I think merge conflicts for this patch, if we let it go stale, will be more painful that for the netbsd process plugin, as that localized to a certain set of files.

I gave the patch a quick run, and I've noticed no regressions on Linux (after fixing up a couple of compile errors in Linux-specific code), so +100 on the patch from me.

As for the compile errors, I'm going to prepare NativeProcessLinux ahead of time for this patch, to avoid breakage.

To be clear, I don't think this patch actually deletes LLDB's mutex. It just deletes uses of LLDB's mutex. So the NetBSD code should continue to work after merging this patch in. Sure it introduces another use of lldb's Mutex, but we can always remove that later. 5 is easier to remove than 500 :)

clayborg accepted this revision.May 16 2016, 12:12 PM
clayborg edited edge metadata.

Looks good. We should work toward remove Mutex.cpp and Mutex.h completely and also switch over to using std::condition_variable.

This revision is now accepted and ready to land.May 16 2016, 12:12 PM

Zach is correct, this doesn't *remove* the Mutex and Condition types, merely starts reducing the easier uses of it.

My thinking is to do this piecemeal, slowly reducing the local usage until the real uses remain in the cases where we need to actually change the structure of the code. In particular, it seems that there are places where we have Mutex::Locker passed in by reference to get a lock.

I agree that we want to start moving towards using std::condition_variable, however, that was a bit more involved as that will require adding a conversion operator for TimeValue. Switching to std::condition_variable requires the switch to std::mutex as std::conditional_variable::wait requires a std::unique_lock<std::mutex>.

I wanted to get as much of the mechanical change out of the way as possible so that when the rest of the uses are removed, it is easier to actually review the change to ensure that no subtle bugs are being introduced since it won't be as mechanical.

Which platforms did you run the test suite on?

krytarowski accepted this revision.May 16 2016, 5:58 PM
krytarowski added a reviewer: krytarowski.

I ran it on Darwin while I was working on this. Ill run it on Linux once before I commit the first pass.

If you haven't or can't run it on Windows, then give me a chance to test it
on Windows before you commit. I can do it tomorrow unless you are set up
to do it instead.

If you can run the test that would be wonderful. Im going to upload a slight update to this tonight that catches a few more of the trivial cases. I think minimizing the second pass is ideal since that is going to be much more involved (changing APIs and such).

compnerd updated this revision to Diff 57433.May 16 2016, 10:09 PM
compnerd edited edge metadata.

This looks good, no probelms on Windows that I can see. I ran clang-format on your patch just to confirm, and it fixed up some trailing whitespace at the end of lines. I'm not sure if the problem was in the generation of the patch on your end, the application of the patch on my end, or if the whitespace is really there on your end too, but just make sure it's all clean. Quick example just so you can look at this specific line and see if it's on your end:

 // Other libraries and framework includes
 // Project includes
diff --git a/include/lldb/Core/History.h b/include/lldb/Core/History.h
index 001ad3e..164d1bf 100644
--- a/include/lldb/Core/History.h
+++ b/include/lldb/Core/History.h
@@ -46,7 +46,7 @@ public:
     // onto the end of the history stack.

     virtual HistoryEvent
-    CreateHistoryEvent () = 0;
+    CreateHistoryEvent () = 0;

This line had whitespace at the end when I applied the patch.

zturner accepted this revision.May 17 2016, 5:35 PM
zturner edited edge metadata.

Ah, I just ran git-clang-format, and that found a few additional things. Incorporated that; Ill commit this tonight and hopefully have the second pass done soon.

compnerd closed this revision.May 17 2016, 7:38 PM

SVN r269877