summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/Threading.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-06-12 11:56:21 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-06-12 11:56:21 +0000
commit9d8f61ad6097a308edd2f453d94c3eb0623b88a1 (patch)
tree9d3e54977addf60af36b5ece3514795bc44b5164 /clang-tools-extra/clangd/Threading.cpp
parent73bf3206ae2154f712b708a655a154eb1d7f946a (diff)
downloadbcm5719-llvm-9d8f61ad6097a308edd2f453d94c3eb0623b88a1.tar.gz
bcm5719-llvm-9d8f61ad6097a308edd2f453d94c3eb0623b88a1.zip
[clangd] Trace time the operations wait on Semaphore.
The Semaphore is currently used to limit the number of concurrently running tasks. Tracing the wait times will allow to find out how much time is wasted waiting on other operations to complete. llvm-svn: 334495
Diffstat (limited to 'clang-tools-extra/clangd/Threading.cpp')
-rw-r--r--clang-tools-extra/clangd/Threading.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/clang-tools-extra/clangd/Threading.cpp b/clang-tools-extra/clangd/Threading.cpp
index 22206114ff8..dfd0d2eec28 100644
--- a/clang-tools-extra/clangd/Threading.cpp
+++ b/clang-tools-extra/clangd/Threading.cpp
@@ -1,4 +1,5 @@
#include "Threading.h"
+#include "Trace.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Threading.h"
@@ -23,9 +24,14 @@ void Notification::wait() const {
Semaphore::Semaphore(std::size_t MaxLocks) : FreeSlots(MaxLocks) {}
void Semaphore::lock() {
- std::unique_lock<std::mutex> Lock(Mutex);
- SlotsChanged.wait(Lock, [&]() { return FreeSlots > 0; });
- --FreeSlots;
+ trace::Span Span("WaitForFreeSemaphoreSlot");
+ // trace::Span can also acquire locks in ctor and dtor, we make sure it
+ // happens when Semaphore's own lock is not held.
+ {
+ std::unique_lock<std::mutex> Lock(Mutex);
+ SlotsChanged.wait(Lock, [&]() { return FreeSlots > 0; });
+ --FreeSlots;
+ }
}
void Semaphore::unlock() {
OpenPOWER on IntegriCloud