queue.h 723 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef ZMAP_QUEUE_H
  2. #define ZMAP_QUEUE_H
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <pthread.h>
  7. typedef struct zqueue_node {
  8. char* data;
  9. struct zqueue_node *prev;
  10. struct zqueue_node *next;
  11. } znode_t;
  12. typedef struct zqueue {
  13. struct zqueue_node *front;
  14. struct zqueue_node *back;
  15. size_t size;
  16. // Threading utilities
  17. pthread_mutex_t lock;
  18. pthread_cond_t empty;
  19. } zqueue_t;
  20. zqueue_t* queue_init();
  21. int is_empty(zqueue_t *queue);
  22. void push_back(char* data, zqueue_t *queue);
  23. znode_t* pop_front(zqueue_t *queue);
  24. znode_t* pop_front_unsafe(zqueue_t *queue);
  25. znode_t* get_front(zqueue_t *queue);
  26. znode_t* get_back(zqueue_t *queue);
  27. size_t get_size(zqueue_t *queue);
  28. #endif /* ZMAP_QUEUE_H */