apr_queue.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef APR_QUEUE_H
  17. #define APR_QUEUE_H
  18. /**
  19. * @file apr_queue.h
  20. * @brief Thread Safe FIFO bounded queue
  21. * @note Since most implementations of the queue are backed by a condition
  22. * variable implementation, it isn't available on systems without threads.
  23. * Although condition variables are some times available without threads.
  24. */
  25. #include "apu.h"
  26. #include "apr_errno.h"
  27. #include "apr_pools.h"
  28. #if APR_HAS_THREADS
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif /* __cplusplus */
  32. /**
  33. * @defgroup APR_Util_FIFO Thread Safe FIFO bounded queue
  34. * @ingroup APR_Util
  35. * @{
  36. */
  37. /**
  38. * opaque structure
  39. */
  40. typedef struct apr_queue_t apr_queue_t;
  41. /**
  42. * create a FIFO queue
  43. * @param queue The new queue
  44. * @param queue_capacity maximum size of the queue
  45. * @param a pool to allocate queue from
  46. */
  47. APU_DECLARE(apr_status_t) apr_queue_create(apr_queue_t **queue,
  48. unsigned int queue_capacity,
  49. apr_pool_t *a);
  50. /**
  51. * push/add a object to the queue, blocking if the queue is already full
  52. *
  53. * @param queue the queue
  54. * @param data the data
  55. * @returns APR_EINTR the blocking was interrupted (try again)
  56. * @returns APR_EOF the queue has been terminated
  57. * @returns APR_SUCCESS on a successfull push
  58. */
  59. APU_DECLARE(apr_status_t) apr_queue_push(apr_queue_t *queue, void *data);
  60. /**
  61. * pop/get an object from the queue, blocking if the queue is already empty
  62. *
  63. * @param queue the queue
  64. * @param data the data
  65. * @returns APR_EINTR the blocking was interrupted (try again)
  66. * @returns APR_EOF if the queue has been terminated
  67. * @returns APR_SUCCESS on a successfull pop
  68. */
  69. APU_DECLARE(apr_status_t) apr_queue_pop(apr_queue_t *queue, void **data);
  70. /**
  71. * pop/get an object from the queue, blocking if the queue is already empty
  72. *
  73. * @param queue the queue
  74. * @param data the data
  75. * @param timeout The amount of time in microseconds to wait. This is
  76. * a maximum, not a minimum. If the condition is signaled, we
  77. * will wake up before this time, otherwise the error APR_TIMEUP
  78. * is returned.
  79. * @returns APR_TIMEUP the request timed out
  80. * @returns APR_EINTR the blocking was interrupted (try again)
  81. * @returns APR_EOF if the queue has been terminated
  82. * @returns APR_SUCCESS on a successfull pop
  83. */
  84. APU_DECLARE(apr_status_t) apr_queue_pop_timeout(apr_queue_t *queue, void **data, apr_interval_time_t timeout);
  85. /**
  86. * push/add a object to the queue, returning immediatly if the queue is full
  87. *
  88. * @param queue the queue
  89. * @param data the data
  90. * @returns APR_EINTR the blocking operation was interrupted (try again)
  91. * @returns APR_EAGAIN the queue is full
  92. * @returns APR_EOF the queue has been terminated
  93. * @returns APR_SUCCESS on a successfull push
  94. */
  95. APU_DECLARE(apr_status_t) apr_queue_trypush(apr_queue_t *queue, void *data);
  96. /**
  97. * pop/get an object to the queue, returning immediatly if the queue is empty
  98. *
  99. * @param queue the queue
  100. * @param data the data
  101. * @returns APR_EINTR the blocking operation was interrupted (try again)
  102. * @returns APR_EAGAIN the queue is empty
  103. * @returns APR_EOF the queue has been terminated
  104. * @returns APR_SUCCESS on a successfull push
  105. */
  106. APU_DECLARE(apr_status_t) apr_queue_trypop(apr_queue_t *queue, void **data);
  107. /**
  108. * returns the size of the queue.
  109. *
  110. * @warning this is not threadsafe, and is intended for reporting/monitoring
  111. * of the queue.
  112. * @param queue the queue
  113. * @returns the size of the queue
  114. */
  115. APU_DECLARE(unsigned int) apr_queue_size(apr_queue_t *queue);
  116. /**
  117. * interrupt all the threads blocking on this queue.
  118. *
  119. * @param queue the queue
  120. */
  121. APU_DECLARE(apr_status_t) apr_queue_interrupt_all(apr_queue_t *queue);
  122. /**
  123. * terminate all queue, sendinging a interupt to all the
  124. * blocking threads
  125. *
  126. * @param queue the queue
  127. */
  128. APU_DECLARE(apr_status_t) apr_queue_term(apr_queue_t *queue);
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. /** @} */
  133. #endif /* APR_HAS_THREADS */
  134. #endif /* APRQUEUE_H */