EtherLib/gen_queue.h
Wiesner András 51696f7341 - MemoryPool allocation-deallocation bug fixed
- generic Queue implemented
- PacketRegistry allocation bug fixed
- TCP implementation initials
- ALIGN to type macros added
2023-01-17 08:19:29 +01:00

66 lines
1.4 KiB
C

#ifndef ETHERLIB_TEST_QUEUE_H
#define ETHERLIB_TEST_QUEUE_H
#include <stdint.h>
#include <stdbool.h>
/**
* Generic Queue.
*/
typedef struct {
uint32_t writeIdx; ///< Next block to write
uint32_t readIdx; ///< Next block to read
uint32_t length; ///< Size of circular buffer
uint32_t elemSize; ///< Element size
uint8_t elements[]; ///< Array of packets
} Queue;
/**
* Create Queue.
* @param length length of circular buffer
* @param elemSize element size
* @return pointer to Queue instance OR NULL on failure
*/
Queue * q_create(uint32_t length, uint32_t elemSize);
/**
* Create Queue based on storage type.
*/
#define Q_CREATE_T(length,T) q_create((length), sizeof(T))
/**
* Clear circular buffer.
* @param q pointer to Queue
*/
void q_clear(Queue * q);
/**
* Get number of available elements.
* @param q pointer to Queue
* @return number of available elements
*/
uint32_t q_avail(const Queue * q);
/**
* Push element to the Queue.
* @param q pointer to Queue
* @param raw pointer to raw packet
* @return true on success, false on failure (e.g.: queue full)
*/
bool q_push(Queue * q, const void * src);
/**
* Get top element.
* @param q pointer to Queue
* @return top element (COPY, NOT POINTER!)
*/
void q_top(Queue * q, void * dest);
/**
* Pop top element.
* @param q pointer to Queue
*/
void q_pop(Queue * q);
#endif //ETHERLIB_TEST_QUEUE_H