class TSLQIter {
public:
TSLQIter(std::mutex &mutex,
- std::weak_ptr<TSLQNode> currentNode);
+ std::weak_ptr<TSLQNode> currentNode,
+ unsigned long long *msize);
~TSLQIter();
std::optional<T> current();
private:
std::lock_guard<std::mutex> lock;
std::weak_ptr<TSLQNode> currentNode;
+ unsigned long long *msize;
+
};
public:
template <typename T>
TSLQueue<T>::TSLQIter::TSLQIter(std::mutex &mutex,
- std::weak_ptr<TSLQNode> currentNode) :
+ std::weak_ptr<TSLQNode> currentNode,
+ unsigned long long *msize) :
lock(mutex),
-currentNode(currentNode)
+currentNode(currentNode),
+msize(msize)
{
}
currentNode->next->prev = parent;
parent->next = currentNode->next;
+ assert(*msize > 0);
+ --(*msize);
+
return parent->next->isNormal();
}
template <typename T>
typename TSLQueue<T>::TSLQIter TSLQueue<T>::begin() {
- return TSLQIter(mutex, head->next);
+ return TSLQIter(mutex, head->next, &msize);
}
#endif
for(int i = 0; i < 10; ++i) {
q.push(i);
}
+ EXPECT_EQ(q.size(), 10);
{
// iteration
EXPECT_TRUE(op.has_value());
EXPECT_EQ(op.value(), 2);
}
+ EXPECT_EQ(q.size(), 9);
// check that "3" was removed from queue
int i = 0;
q.push(1);
q.push(2);
q.push(3);
+ EXPECT_EQ(q.size(), 4);
{
auto iter = q.begin();
EXPECT_TRUE(iter.remove());
}
+ EXPECT_EQ(q.size(), 3);
i = 1;
while(!q.empty()) {
op = q.top();
q.push(1);
q.push(2);
q.push(3);
+ EXPECT_EQ(q.size(), 4);
{
auto iter = q.begin();
while(true) {
}
}
}
+ EXPECT_EQ(q.size(), 3);
i = 0;
while(!q.empty()) {
op = q.top();