SerialQueue/Map: Take the serial type as type paramater.

This is in preparation for follow-up CLs that will use typed integers
for the various serial types.

Bug: dawn:442

Change-Id: I5296546e96acd6ac9f7a0bfc46dc7eba40cb3cf5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/28921
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez
2020-09-28 12:28:13 +00:00
committed by Commit Bot service account
parent ed2b465f86
commit 145f115c54
20 changed files with 121 additions and 81 deletions

View File

@@ -19,65 +19,65 @@
#include <vector>
template <typename T>
template <typename Serial, typename Value>
class SerialQueue;
template <typename T>
struct SerialStorageTraits<SerialQueue<T>> {
using Value = T;
using SerialPair = std::pair<Serial, std::vector<T>>;
template <typename SerialT, typename ValueT>
struct SerialStorageTraits<SerialQueue<SerialT, ValueT>> {
using Serial = SerialT;
using Value = ValueT;
using SerialPair = std::pair<Serial, std::vector<Value>>;
using Storage = std::vector<SerialPair>;
using StorageIterator = typename Storage::iterator;
using ConstStorageIterator = typename Storage::const_iterator;
};
// SerialQueue stores an associative list mapping a Serial to T.
// SerialQueue stores an associative list mapping a Serial to Value.
// It enforces that the Serials enqueued are strictly non-decreasing.
// This makes it very efficient iterate or clear all items added up
// to some Serial value because they are stored contiguously in memory.
template <typename T>
class SerialQueue : public SerialStorage<SerialQueue<T>> {
template <typename Serial, typename Value>
class SerialQueue : public SerialStorage<SerialQueue<Serial, Value>> {
public:
using SerialPair = typename SerialStorageTraits<SerialQueue<T>>::SerialPair;
// The serial must be given in (not strictly) increasing order.
void Enqueue(const T& value, Serial serial);
void Enqueue(T&& value, Serial serial);
void Enqueue(const std::vector<T>& values, Serial serial);
void Enqueue(std::vector<T>&& values, Serial serial);
void Enqueue(const Value& value, Serial serial);
void Enqueue(Value&& value, Serial serial);
void Enqueue(const std::vector<Value>& values, Serial serial);
void Enqueue(std::vector<Value>&& values, Serial serial);
};
// SerialQueue
template <typename T>
void SerialQueue<T>::Enqueue(const T& value, Serial serial) {
template <typename Serial, typename Value>
void SerialQueue<Serial, Value>::Enqueue(const Value& value, Serial serial) {
DAWN_ASSERT(this->Empty() || this->mStorage.back().first <= serial);
if (this->Empty() || this->mStorage.back().first < serial) {
this->mStorage.emplace_back(serial, std::vector<T>{});
this->mStorage.emplace_back(serial, std::vector<Value>{});
}
this->mStorage.back().second.push_back(value);
}
template <typename T>
void SerialQueue<T>::Enqueue(T&& value, Serial serial) {
template <typename Serial, typename Value>
void SerialQueue<Serial, Value>::Enqueue(Value&& value, Serial serial) {
DAWN_ASSERT(this->Empty() || this->mStorage.back().first <= serial);
if (this->Empty() || this->mStorage.back().first < serial) {
this->mStorage.emplace_back(serial, std::vector<T>{});
this->mStorage.emplace_back(serial, std::vector<Value>{});
}
this->mStorage.back().second.push_back(std::move(value));
}
template <typename T>
void SerialQueue<T>::Enqueue(const std::vector<T>& values, Serial serial) {
template <typename Serial, typename Value>
void SerialQueue<Serial, Value>::Enqueue(const std::vector<Value>& values, Serial serial) {
DAWN_ASSERT(values.size() > 0);
DAWN_ASSERT(this->Empty() || this->mStorage.back().first <= serial);
this->mStorage.emplace_back(serial, values);
}
template <typename T>
void SerialQueue<T>::Enqueue(std::vector<T>&& values, Serial serial) {
template <typename Serial, typename Value>
void SerialQueue<Serial, Value>::Enqueue(std::vector<Value>&& values, Serial serial) {
DAWN_ASSERT(values.size() > 0);
DAWN_ASSERT(this->Empty() || this->mStorage.back().first <= serial);
this->mStorage.emplace_back(serial, values);