Commit ca6bb805 authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[util] Fix LockedQueue size

We increment the size before enqueueing the next element.
This guarantees that size > 0 when decrementing.

Bug: v8:12325
Change-Id: Ida256d9b22a9dd5cacb21312f099ee7186e2ca53
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3231335
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77457}
parent c2757f6c
......@@ -45,9 +45,9 @@ inline void LockedQueue<Record>::Enqueue(Record record) {
n->value = std::move(record);
{
base::MutexGuard guard(&tail_mutex_);
size_++;
tail_->next.SetValue(n);
tail_ = n;
size_++;
}
}
......@@ -61,8 +61,9 @@ inline bool LockedQueue<Record>::Dequeue(Record* record) {
if (next_node == nullptr) return false;
*record = std::move(next_node->value);
head_ = next_node;
DCHECK_GT(size_.load(), 0);
size_--;
size_t old_size = size_.fetch_sub(1);
USE(old_size);
DCHECK_GT(old_size, 0);
}
delete old_head;
return true;
......
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