Skip to content

Commit 7006a0e

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "Add empty, dump methods to BlockingQueue" into main
2 parents 9af0a06 + 287f998 commit 7006a0e

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

include/input/BlockingQueue.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#pragma once
1818

19+
#include <input/PrintTools.h>
1920
#include <condition_variable>
2021
#include <functional>
2122
#include <list>
@@ -126,11 +127,21 @@ class BlockingQueue {
126127
* Primary used for debugging.
127128
* Does not block.
128129
*/
129-
size_t size() {
130+
size_t size() const {
130131
std::scoped_lock lock(mLock);
131132
return mQueue.size();
132133
}
133134

135+
bool empty() const {
136+
std::scoped_lock lock(mLock);
137+
return mQueue.empty();
138+
}
139+
140+
std::string dump(std::string (*toString)(const T&) = constToString) const {
141+
std::scoped_lock lock(mLock);
142+
return dumpContainer(mQueue, toString);
143+
}
144+
134145
private:
135146
const std::optional<size_t> mCapacity;
136147
/**
@@ -140,7 +151,7 @@ class BlockingQueue {
140151
/**
141152
* Lock for accessing and waiting on elements.
142153
*/
143-
std::mutex mLock;
154+
mutable std::mutex mLock;
144155
std::list<T> mQueue GUARDED_BY(mLock);
145156
};
146157

0 commit comments

Comments
 (0)