cppgc, heap: Add Clear and IsEmpty methods to Worklist::Local
Bug: v8:10990 Change-Id: I5166d9ecd6d8d8c55ecb17015d99d88ed60effa2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2488680 Commit-Queue: Omer Katz <omerkatz@chromium.org> Commit-Queue: Michael Lippautz <mlippautz@chromium.org> Auto-Submit: Omer Katz <omerkatz@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Cr-Commit-Position: refs/heads/master@{#70668}
This commit is contained in:
parent
7da1a952c7
commit
75049771c3
@ -285,6 +285,9 @@ class Worklist<EntryType, SegmentSize>::Local {
|
||||
void Publish();
|
||||
void Merge(Worklist<EntryType, SegmentSize>::Local* other);
|
||||
|
||||
bool IsEmpty() const;
|
||||
void Clear();
|
||||
|
||||
size_t PushSegmentSize() const { return push_segment_->Size(); }
|
||||
|
||||
private:
|
||||
@ -445,6 +448,17 @@ bool Worklist<EntryType, SegmentSize>::Local::StealPopSegment() {
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename EntryType, uint16_t SegmentSize>
|
||||
bool Worklist<EntryType, SegmentSize>::Local::IsEmpty() const {
|
||||
return push_segment_->IsEmpty() && pop_segment_->IsEmpty();
|
||||
}
|
||||
|
||||
template <typename EntryType, uint16_t SegmentSize>
|
||||
void Worklist<EntryType, SegmentSize>::Local::Clear() {
|
||||
push_segment_->Clear();
|
||||
pop_segment_->Clear();
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
} // namespace heap
|
||||
|
||||
|
@ -110,21 +110,45 @@ TEST(CppgcWorkListTest, LocalPushPop) {
|
||||
|
||||
TEST(CppgcWorkListTest, LocalPushStaysPrivate) {
|
||||
TestWorklist worklist;
|
||||
TestWorklist::Local worklist_view1(&worklist);
|
||||
TestWorklist::Local worklist_view2(&worklist);
|
||||
TestWorklist::Local worklist_local1(&worklist);
|
||||
TestWorklist::Local worklist_local2(&worklist);
|
||||
SomeObject dummy;
|
||||
SomeObject* retrieved = nullptr;
|
||||
EXPECT_TRUE(worklist.IsEmpty());
|
||||
EXPECT_EQ(0U, worklist.Size());
|
||||
worklist_view1.Push(&dummy);
|
||||
worklist_local1.Push(&dummy);
|
||||
EXPECT_EQ(0U, worklist.Size());
|
||||
EXPECT_FALSE(worklist_view2.Pop(&retrieved));
|
||||
EXPECT_FALSE(worklist_local2.Pop(&retrieved));
|
||||
EXPECT_EQ(nullptr, retrieved);
|
||||
EXPECT_TRUE(worklist_view1.Pop(&retrieved));
|
||||
EXPECT_TRUE(worklist_local1.Pop(&retrieved));
|
||||
EXPECT_EQ(&dummy, retrieved);
|
||||
EXPECT_EQ(0U, worklist.Size());
|
||||
}
|
||||
|
||||
TEST(CppgcWorkListTest, LocalClear) {
|
||||
TestWorklist worklist;
|
||||
TestWorklist::Local worklist_local(&worklist);
|
||||
SomeObject* object;
|
||||
object = reinterpret_cast<SomeObject*>(&object);
|
||||
// Check push segment:
|
||||
EXPECT_TRUE(worklist_local.IsEmpty());
|
||||
worklist_local.Push(object);
|
||||
EXPECT_FALSE(worklist_local.IsEmpty());
|
||||
worklist_local.Clear();
|
||||
EXPECT_TRUE(worklist_local.IsEmpty());
|
||||
// Check pop segment:
|
||||
worklist_local.Push(object);
|
||||
worklist_local.Push(object);
|
||||
EXPECT_FALSE(worklist_local.IsEmpty());
|
||||
worklist_local.Publish();
|
||||
EXPECT_TRUE(worklist_local.IsEmpty());
|
||||
SomeObject* retrieved;
|
||||
worklist_local.Pop(&retrieved);
|
||||
EXPECT_FALSE(worklist_local.IsEmpty());
|
||||
worklist_local.Clear();
|
||||
EXPECT_TRUE(worklist_local.IsEmpty());
|
||||
}
|
||||
|
||||
TEST(CppgcWorkListTest, GlobalUpdateNull) {
|
||||
TestWorklist worklist;
|
||||
TestWorklist::Local worklist_local(&worklist);
|
||||
|
Loading…
Reference in New Issue
Block a user