Commit 2a3504e7 authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[mutex] Create the SharedMutexGuardIf class

It creates a SharedMutexGuard if the boolean parameter in the
constructor is true.

Bug: v8:7790
Change-Id: I77647f648717af05b1239576b690aec6f4e8b268
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2531790
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71162}
parent 6507b975
......@@ -7,6 +7,7 @@
#include "src/base/base-export.h"
#include "src/base/lazy-instance.h"
#include "src/base/optional.h"
#if V8_OS_WIN
#include "src/base/win32-headers.h"
#endif
......@@ -340,6 +341,20 @@ class SharedMutexGuard final {
}
};
template <MutexSharedType kIsShared,
NullBehavior Behavior = NullBehavior::kRequireNotNull>
class SharedMutexGuardIf final {
public:
SharedMutexGuardIf(SharedMutex* mutex, bool enable_mutex) {
if (enable_mutex) mutex_.emplace(mutex);
}
SharedMutexGuardIf(const SharedMutexGuardIf&) = delete;
SharedMutexGuardIf& operator=(const SharedMutexGuardIf&) = delete;
private:
base::Optional<SharedMutexGuard<kIsShared, Behavior>> mutex_;
};
} // namespace base
} // namespace v8
......
......@@ -502,16 +502,11 @@ void NexusConfig::SetFeedbackPair(FeedbackVector vector,
std::pair<MaybeObject, MaybeObject> NexusConfig::GetFeedbackPair(
FeedbackVector vector, FeedbackSlot slot) const {
if (mode() == BackgroundThread) {
isolate()->feedback_vector_access()->LockShared();
}
base::SharedMutexGuardIf<base::kShared> scope(
isolate()->feedback_vector_access(), mode() == BackgroundThread);
MaybeObject feedback = vector.Get(slot);
MaybeObject feedback_extra = vector.Get(slot.WithOffset(1));
auto return_value = std::make_pair(feedback, feedback_extra);
if (mode() == BackgroundThread) {
isolate()->feedback_vector_access()->UnlockShared();
}
return return_value;
return std::make_pair(feedback, feedback_extra);
}
FeedbackNexus::FeedbackNexus(Handle<FeedbackVector> vector, FeedbackSlot slot)
......
......@@ -230,11 +230,9 @@ Map TransitionsAccessor::SearchTransition(Name name, PropertyKind kind,
return map;
}
case kFullTransitionArray: {
if (concurrent_access_) isolate_->transition_array_access()->LockShared();
Map result = transitions().SearchAndGetTarget(kind, name, attributes);
if (concurrent_access_)
isolate_->transition_array_access()->UnlockShared();
return result;
base::SharedMutexGuardIf<base::kShared> scope(
isolate_->transition_array_access(), concurrent_access_);
return transitions().SearchAndGetTarget(kind, name, attributes);
}
}
UNREACHABLE();
......
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