Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions runtime/src/retire_tickets.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RetireTickets {
while (!pending_.empty()) {
const Entry& front = pending_.front();
if (!front.idle && !query(front.semaphore, front.value)) break;
completed_ = front.ticket;
if (front.ticket > completed_) completed_ = front.ticket;
pending_.pop_front();
}
return completed_;
Expand All @@ -34,8 +34,18 @@ class RetireTickets {
// that must have them done (and may not hold the lock that guards this object while it waits) waits for.
std::vector<std::pair<Semaphore, std::uint64_t>> pending_through(std::uint64_t ticket) const {
std::vector<std::pair<Semaphore, std::uint64_t>> out;
for (const Entry& entry : pending_)
if (entry.ticket <= ticket && !entry.idle) out.emplace_back(entry.semaphore, entry.value);
for (const Entry& entry : pending_) {
if (entry.ticket > ticket || entry.idle) continue;
bool merged = false;
for (auto& [sem, val] : out) {
if (sem == entry.semaphore) {
if (entry.value > val) val = entry.value;
merged = true;
break;
}
}
if (!merged) out.emplace_back(entry.semaphore, entry.value);
}
return out;
}

Expand Down
18 changes: 18 additions & 0 deletions runtime/test/retire_tickets_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ int main() {
queue_one_destroyed = true;
if (tickets.completed(query) != 4 || queried_destroyed) return 4;

// pending_through() must coalesce repeated submissions on the same queue to the highest
// timeline value, omit idle queues, and exclude tickets past the requested cutoff.
tickets.record(5, 1, 10);
tickets.record(6, 2, 20);
tickets.record(7, 1, 12);
tickets.record(8, 1, 15);
tickets.record(9, 2, 25);
tickets.queue_idle(2);
const auto wait_list = tickets.pending_through(7);
if (wait_list.size() != 1 || wait_list[0].first != 1 || wait_list[0].second != 12) return 5;

// A non-monotonic ticket must not move the completed prefix backward.
done[1] = 15;
if (tickets.completed(query) != 9) return 6;
tickets.record(3, 1, 16);
done[1] = 16;
if (tickets.completed(query) != 9) return 7;

std::puts("out-of-order queue completion kept the retirement prefix safe");
return 0;
}
Loading