Guest User

Untitled

a guest
Nov 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include "PacketQueue.h"
  2.  
  3.  
  4. PacketQueue *QueueCreate ()
  5. {
  6. PacketQueue *q = calloc(1,sizeof(*q));
  7. q->first = q->last = NULL;
  8.  
  9. return q;
  10.  
  11. }
  12.  
  13. void QueueDestroy (PacketQueue *pq)
  14. {
  15. while (!QueueIsEmpty(pq))
  16. QueueDelete(pq);
  17.  
  18. pq->first = pq->last = NULL;
  19.  
  20. free( pq );
  21. }
  22.  
  23. void AddPacket (PacketQueue *pq, dAmnPacket *p)
  24. {
  25. PacketNode *node = calloc (1, sizeof(*node));
  26.  
  27. node->p = *p;
  28. node->next = NULL;
  29.  
  30. if (pq->first == NULL){
  31. pq->first = pq->last = node;
  32. } else {
  33. pq->last->next = node;
  34. pq->last = node;
  35. }
  36. }
  37.  
  38. PacketQueue *QueueDelete (PacketQueue *pq)
  39. {
  40. if (!QueueIsEmpty(pq)){
  41.  
  42. PacketNode *h = NULL;
  43. PacketNode *p = NULL;
  44.  
  45. h = pq->first;
  46. p = h->next;
  47.  
  48. free (h);
  49.  
  50. pq->first = p;
  51. if (pq->first == NULL) pq->last = pq->first;
  52.  
  53. return pq;
  54. }
  55. return NULL;
  56. }
  57.  
  58. int QueueIsEmpty (PacketQueue *pq)
  59. {
  60. return (pq->first == NULL);
  61. }
Add Comment
Please, Sign In to add comment