Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "PacketQueue.h"
- PacketQueue *QueueCreate ()
- {
- PacketQueue *q = calloc(1,sizeof(*q));
- q->first = q->last = NULL;
- return q;
- }
- void QueueDestroy (PacketQueue *pq)
- {
- while (!QueueIsEmpty(pq))
- QueueDelete(pq);
- pq->first = pq->last = NULL;
- free( pq );
- }
- void AddPacket (PacketQueue *pq, dAmnPacket *p)
- {
- PacketNode *node = calloc (1, sizeof(*node));
- node->p = *p;
- node->next = NULL;
- if (pq->first == NULL){
- pq->first = pq->last = node;
- } else {
- pq->last->next = node;
- pq->last = node;
- }
- }
- PacketQueue *QueueDelete (PacketQueue *pq)
- {
- if (!QueueIsEmpty(pq)){
- PacketNode *h = NULL;
- PacketNode *p = NULL;
- h = pq->first;
- p = h->next;
- free (h);
- pq->first = p;
- if (pq->first == NULL) pq->last = pq->first;
- return pq;
- }
- return NULL;
- }
- int QueueIsEmpty (PacketQueue *pq)
- {
- return (pq->first == NULL);
- }
Add Comment
Please, Sign In to add comment