ccapi: Upgrade to v5.31.2
This commit is contained in:
1 parent
b91431e518
commit
7a3fae62c3
32 files changed
+203
-17
No files matched your search
@@ -7,13 +7,18 @@
|
||||
#include "ccapi_cpp/ccapi_logger.h"
|
||||
namespace ccapi {
|
||||
template <class T>
|
||||
/**
|
||||
* This class represents a generic FIFO queue.
|
||||
*/
|
||||
class Queue {
|
||||
public:
|
||||
std::string EXCEPTION_QUEUE_FULL = "queue is full";
|
||||
std::string EXCEPTION_QUEUE_EMPTY = "queue is empty";
|
||||
explicit Queue(const size_t maxSize = 0) : maxSize(maxSize) {}
|
||||
void pushBack(T&& t) {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
if (this->maxSize <= 0 || this->queue.size() < this->maxSize) {
|
||||
CCAPI_LOGGER_TRACE("this->queue.size() = " + size_tToString(this->queue.size()));
|
||||
this->queue.push_back(t);
|
||||
@@ -22,7 +27,9 @@ class Queue {
|
||||
}
|
||||
}
|
||||
T popBack() {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
if (this->queue.empty()) {
|
||||
throw std::runtime_error(EXCEPTION_QUEUE_EMPTY);
|
||||
} else {
|
||||
@@ -32,13 +39,17 @@ class Queue {
|
||||
}
|
||||
}
|
||||
std::vector<T> purge() {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
std::vector<T> p;
|
||||
std::swap(p, this->queue);
|
||||
return p;
|
||||
}
|
||||
void removeAll(std::vector<T>& c) {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
if (c.empty()) {
|
||||
c = std::move(this->queue);
|
||||
} else {
|
||||
@@ -48,11 +59,15 @@ class Queue {
|
||||
this->queue.clear();
|
||||
}
|
||||
size_t size() const {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
return this->queue.size();
|
||||
}
|
||||
bool empty() const {
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
std::lock_guard<std::mutex> lock(this->m);
|
||||
#endif
|
||||
return this->queue.empty();
|
||||
}
|
||||
#ifndef CCAPI_EXPOSE_INTERNAL
|
||||
@@ -60,7 +75,9 @@ class Queue {
|
||||
private:
|
||||
#endif
|
||||
std::vector<T> queue;
|
||||
#ifndef CCAPI_USE_SINGLE_THREAD
|
||||
mutable std::mutex m;
|
||||
#endif
|
||||
size_t maxSize{};
|
||||
};
|
||||
} /* namespace ccapi */
|
||||
|
||||
Reference in new issue
Block a user