libfuncs is collection of code (list, queue, circular buffer, io, logging, etc.). https://georgi.unixsol.org/programs/libfuncs/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

queue.h 743B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Queue header file
  3. * Copyright (C) 2006 Unix Solutions Ltd.
  4. *
  5. * Released under MIT license.
  6. * See LICENSE-MIT.txt for license terms.
  7. */
  8. #ifndef QUEUE_H
  9. # define QUEUE_H
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #include <pthread.h>
  14. typedef struct QNODE {
  15. struct QNODE *next;
  16. void *data;
  17. } QNODE;
  18. typedef struct QUEUE {
  19. QNODE *head;
  20. QNODE *tail;
  21. pthread_mutex_t mutex; // queue's mutex.
  22. pthread_cond_t cond; // queue's condition variable.
  23. int items; // number of messages in queue
  24. } QUEUE;
  25. QUEUE *queue_new (void);
  26. void queue_free (QUEUE **q);
  27. void queue_add (QUEUE *q, void *data);
  28. void *queue_get (QUEUE *q);
  29. void *queue_get_nowait (QUEUE *q);
  30. void queue_wakeup (QUEUE *q);
  31. #ifdef __cplusplus
  32. }
  33. #endif
  34. #endif