91 lines
1.5 KiB
C++
91 lines
1.5 KiB
C++
/*
|
|
* eth_ecat_queue.hpp
|
|
*
|
|
* Created on: Jun 2, 2023
|
|
* Author: algin
|
|
*/
|
|
|
|
#ifndef FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_QUEUE_HPP_
|
|
#define FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_QUEUE_HPP_
|
|
|
|
#include <atomic>
|
|
|
|
namespace free_rtos {
|
|
|
|
namespace queue {
|
|
|
|
template<typename DataType>
|
|
class QueueEntity {
|
|
public:
|
|
QueueEntity(DataType *data)
|
|
: data_{data} { }
|
|
|
|
DataType* get_data() {
|
|
return data_;
|
|
}
|
|
|
|
QueueEntity* get_next() {
|
|
return next_;
|
|
}
|
|
|
|
void detach() {
|
|
next_ = nullptr;
|
|
first_ = this;
|
|
last_ = this;
|
|
}
|
|
|
|
QueueEntity& operator+(QueueEntity& next) {
|
|
attach(next);
|
|
|
|
//set_next(next);
|
|
|
|
return next;
|
|
}
|
|
|
|
QueueEntity* operator+(QueueEntity *next) {
|
|
attach(next);
|
|
|
|
//set_next(next);
|
|
|
|
return next;
|
|
}
|
|
|
|
private:
|
|
DataType *data_{nullptr};
|
|
|
|
QueueEntity *next_{nullptr};
|
|
QueueEntity *first_{this};
|
|
QueueEntity *last_{this};
|
|
|
|
void set_next(QueueEntity &next) {
|
|
next_ = &next;
|
|
}
|
|
|
|
QueueEntity* get_last() {
|
|
return last_;
|
|
}
|
|
|
|
void set_first(QueueEntity* first) {
|
|
first_ = first;
|
|
}
|
|
|
|
QueueEntity* attach(QueueEntity& next) {
|
|
if(this != first_) {
|
|
first_ = first_->attach(next);
|
|
}else{
|
|
next.set_first(first_);
|
|
last_->set_next(next);
|
|
//last_ = next.get_last();
|
|
last_ = &next;
|
|
}
|
|
|
|
return first_;
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_QUEUE_HPP_ */
|