Delete tc_cas_queue.h

This commit is contained in:
Douwanna 2020-05-20 02:33:08 +08:00 committed by GitHub
parent 33f8fd6d64
commit 9d05e78ddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,264 +0,0 @@
#ifndef __TC_CAS_QUEUE_H_
#define __TC_CAS_QUEUE_H_
#include <deque>
#include <vector>
#include <cassert>
#include "util/tc_lock.h"
#include "util/tc_spin_lock.h"
using namespace std;
namespace tars
{
/////////////////////////////////////////////////
/**
* @file tc_cas_queue.h
* @brief No Lock Threads
* @brief 线
*
*
* @author ruanshudong@qq.com
*/
/////////////////////////////////////////////////
/**
* @brief 线
*/
template<typename T, typename D = deque<T> >
class TC_CasQueue
{
public:
TC_CasQueue():_size(0){};
public:
typedef D queue_type;
/**
* @brief Get data from the head, if there's no data, throw exception.
* @brief ,
*
* @param t
*
* @return bool:true-> get data successfully, false-> no data
* @return bool: true, , false,
*/
T front();
/**
* @brief
*
* @param t
*
* @return bool:true-> get data successfully, false-> no data
* @return bool: true, , false,
*/
bool pop_front(T& t);
/**
* @brief Get data from the head
* @brief
*
* @return bool:true-> get data successfully, false-> no data
* @return bool: true, , false,
*/
bool pop_front();
/**
* @brief Set data at the bottom of the queue
* @brief .
*
* @param t
*/
void push_back(const T& t);
/**
* @brief
* @brief .
*
* @param vt
*/
void push_back(const queue_type &qt);
/**
* @brief .
*
* @param t
*/
void push_front(const T& t);
/**
* @brief .
*
* @param vt
*/
void push_front(const queue_type &qt);
/**
* @brief
*
* @param q
* @return true, false
*/
bool swap(queue_type &q);
/**
* @brief .
*
* @return size_t
*/
size_t size() const;
/**
* @brief
*/
void clear();
/**
* @brief .
*
* @return bool truefalse
*/
bool empty() const;
protected:
TC_CasQueue(const TC_CasQueue&) = delete;
TC_CasQueue(TC_CasQueue&&) = delete;
TC_CasQueue& operator=(const TC_CasQueue&) = delete;
TC_CasQueue& operator=(TC_CasQueue&&) = delete;
protected:
/**
*
*/
queue_type _queue;
/**
*
*/
size_t _size;
//锁
TC_SpinLock _mutex;
};
template<typename T, typename D> T TC_CasQueue<T, D>::front()
{
TC_LockT<TC_SpinLock> lock (_mutex);
return _queue.front();
}
template<typename T, typename D> bool TC_CasQueue<T, D>::pop_front(T& t)
{
TC_LockT<TC_SpinLock> lock (_mutex);
if (_queue.empty())
{
return false;
}
t = _queue.front();
_queue.pop_front();
assert(_size > 0);
--_size;
return true;
}
template<typename T, typename D> bool TC_CasQueue<T, D>::pop_front()
{
TC_LockT<TC_SpinLock> lock (_mutex);
if (_queue.empty())
{
return false;
}
_queue.pop_front();
assert(_size > 0);
--_size;
return true;
}
template<typename T, typename D> void TC_CasQueue<T, D>::push_back(const T& t)
{
TC_LockT<TC_SpinLock> lock (_mutex);
_queue.push_back(t);
++_size;
}
template<typename T, typename D> void TC_CasQueue<T, D>::push_back(const queue_type &qt)
{
TC_LockT<TC_SpinLock> lock (_mutex);
typename queue_type::const_iterator it = qt.begin();
typename queue_type::const_iterator itEnd = qt.end();
while (it != itEnd) {
_queue.push_back(*it);
++it;
++_size;
}
}
template<typename T, typename D> void TC_CasQueue<T, D>::push_front(const T& t)
{
TC_LockT<TC_SpinLock> lock (_mutex);
_queue.push_front(t);
++_size;
}
template<typename T, typename D> void TC_CasQueue<T, D>::push_front(const queue_type &qt)
{
TC_LockT<TC_SpinLock> lock (_mutex);
typename queue_type::const_iterator it = qt.begin();
typename queue_type::const_iterator itEnd = qt.end();
while (it != itEnd) {
_queue.push_front(*it);
++it;
++_size;
}
}
template<typename T, typename D> bool TC_CasQueue<T, D>::swap(queue_type &q)
{
TC_LockT<TC_SpinLock> lock (_mutex);
if (_queue.empty()) {
return false;
}
q.swap(_queue);
_size = _queue.size();
return true;
}
template<typename T, typename D> size_t TC_CasQueue<T, D>::size() const
{
TC_LockT<TC_SpinLock> lock(_mutex);
return _size;
}
template<typename T, typename D> void TC_CasQueue<T, D>::clear()
{
TC_LockT<TC_SpinLock> lock(_mutex);
_queue.clear();
_size = 0;
}
template<typename T, typename D> bool TC_CasQueue<T, D>::empty() const
{
TC_LockT<TC_SpinLock> lock(_mutex);
return _queue.empty();
}
}
#endif