Commit 7b1d3f7a authored by Dominik Inführ's avatar Dominik Inführ Committed by V8 LUCI CQ

[heap] Optimize ParkedMutexGuard

We do not need to park/unpark when we can acquire the lock without
blocking.

Bug: v8:10315, chromium:1218318
Change-Id: I7909936531ffe83087182d50e759113a9305fbcf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2953287
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75097}
parent de252121
...@@ -45,18 +45,24 @@ class V8_NODISCARD UnparkedScope { ...@@ -45,18 +45,24 @@ class V8_NODISCARD UnparkedScope {
}; };
class V8_NODISCARD ParkedMutexGuard { class V8_NODISCARD ParkedMutexGuard {
base::Mutex* guard_;
public: public:
explicit ParkedMutexGuard(LocalIsolate* local_isolate, base::Mutex* guard) explicit ParkedMutexGuard(LocalIsolate* local_isolate, base::Mutex* mutex)
: ParkedMutexGuard(local_isolate->heap(), guard) {} : ParkedMutexGuard(local_isolate->heap(), mutex) {}
explicit ParkedMutexGuard(LocalHeap* local_heap, base::Mutex* guard) explicit ParkedMutexGuard(LocalHeap* local_heap, base::Mutex* mutex)
: guard_(guard) { : mutex_(mutex) {
if (!mutex_->TryLock()) {
ParkedScope scope(local_heap); ParkedScope scope(local_heap);
guard_->Lock(); mutex_->Lock();
}
} }
~ParkedMutexGuard() { guard_->Unlock(); } ParkedMutexGuard(const ParkedMutexGuard&) = delete;
ParkedMutexGuard& operator=(const ParkedMutexGuard&) = delete;
~ParkedMutexGuard() { mutex_->Unlock(); }
private:
base::Mutex* mutex_;
}; };
} // namespace internal } // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment