apr_queue.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. 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 sometimes 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 an 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 successful 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 successful pop
  68. */
  69. APU_DECLARE(apr_status_t) apr_queue_pop(apr_queue_t *queue, void **data);
  70. /**
  71. * push/add an object to the queue, returning immediately if the queue is full
  72. *
  73. * @param queue the queue
  74. * @param data the data
  75. * @returns APR_EINTR the blocking operation was interrupted (try again)
  76. * @returns APR_EAGAIN the queue is full
  77. * @returns APR_EOF the queue has been terminated
  78. * @returns APR_SUCCESS on a successful push
  79. */
  80. APU_DECLARE(apr_status_t) apr_queue_trypush(apr_queue_t *queue, void *data);
  81. /**
  82. * pop/get an object to the queue, returning immediately if the queue is empty
  83. *
  84. * @param queue the queue
  85. * @param data the data
  86. * @returns APR_EINTR the blocking operation was interrupted (try again)
  87. * @returns APR_EAGAIN the queue is empty
  88. * @returns APR_EOF the queue has been terminated
  89. * @returns APR_SUCCESS on a successful pop
  90. */
  91. APU_DECLARE(apr_status_t) apr_queue_trypop(apr_queue_t *queue, void **data);
  92. /**
  93. * returns the size of the queue.
  94. *
  95. * @warning this is not threadsafe, and is intended for reporting/monitoring
  96. * of the queue.
  97. * @param queue the queue
  98. * @returns the size of the queue
  99. */
  100. APU_DECLARE(unsigned int) apr_queue_size(apr_queue_t *queue);
  101. /**
  102. * interrupt all the threads blocking on this queue.
  103. *
  104. * @param queue the queue
  105. */
  106. APU_DECLARE(apr_status_t) apr_queue_interrupt_all(apr_queue_t *queue);
  107. /**
  108. * terminate the queue, sending an interrupt to all the
  109. * blocking threads
  110. *
  111. * @param queue the queue
  112. */
  113. APU_DECLARE(apr_status_t) apr_queue_term(apr_queue_t *queue);
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. /** @} */
  118. #endif /* APR_HAS_THREADS */
  119. #endif /* APRQUEUE_H */