57 lines
1.2 KiB
C
57 lines
1.2 KiB
C
#ifndef ETHERLIB_MSG_QUEUE_H
|
|
#define ETHERLIB_MSG_QUEUE_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include "packet.h"
|
|
|
|
typedef struct MsgQueue_ {
|
|
uint32_t writeIdx; ///< Next block to write
|
|
uint32_t readIdx; ///< Next block to read
|
|
uint32_t size; ///< Size of circular buffer
|
|
RawPckt pckts[]; ///< Array of packets
|
|
} MsgQueue;
|
|
|
|
/**
|
|
* Create Message Queue.
|
|
* @param size size of circular buffer
|
|
* @return pointer to MQ instance OR NULL on failure
|
|
*/
|
|
MsgQueue * mq_create(uint32_t size);
|
|
|
|
/**
|
|
* Clear circular buffer.
|
|
* @param mq pointer to Message Queue
|
|
*/
|
|
void mq_clear(MsgQueue * mq);
|
|
|
|
/**
|
|
* Get number of available elements.
|
|
* @param mq pointer to Message Queue
|
|
* @return number of available elements
|
|
*/
|
|
uint32_t mq_avail(const MsgQueue * mq);
|
|
|
|
/**
|
|
* Push element to the Message Queue.
|
|
* @param mq pointer to MQ
|
|
* @param raw pointer to raw packet
|
|
* @return true on success, false on failure (e.g.: queue full)
|
|
*/
|
|
bool mq_push(MsgQueue * mq, const RawPckt * raw);
|
|
|
|
/**
|
|
* Get top element.
|
|
* @param mq pointer to MQ
|
|
* @return top element (COPY, NOT POINTER!)
|
|
*/
|
|
RawPckt mq_top(MsgQueue * mq);
|
|
|
|
/**
|
|
* Pop top element.
|
|
* @param mq pointer to MQ
|
|
*/
|
|
void mq_pop(MsgQueue * mq);
|
|
|
|
#endif //ETHERLIB_MSG_QUEUE_H
|