USB_Config_Vendor/CC_SDK/Include/basic/CCQueue.h

61 lines
1.2 KiB
C
Raw Permalink Normal View History

2026-02-03 14:36:30 +08:00
#ifndef CCQUEUE_H
#define CCQUEUE_H
#include "queue"
#include "mutex"
template<typename T>
class CCQueue :public std::queue<T> {
public:
using std::queue<T>::queue;
/**
*
* @param item
*/
void add_lock(const T& item) {
mutex_.lock();
std::queue<T>::push(item);
mutex_.unlock();
}
/**
*
* @param item
*/
void remove_lock(const T& item) {
mutex_.lock();
std::queue<T>::pop(item);
mutex_.unlock();
}
/**
*
*/
void clear_lock() {
mutex_.lock();
std::queue<T>::clear();
mutex_.unlock();
}
/**
*
* @return
*/
T poll_lock() {
mutex_.lock();
T item = std::queue<T>::front();
std::queue<T>::pop();
mutex_.unlock();
return item;
}
/**
*
* @return
*/
bool IsEmpty() {
mutex_.lock();
const bool is_empty = std::queue<T>::empty();
mutex_.unlock();
return is_empty;
}
protected:
std::mutex mutex_;
};
#endif