Lines Matching refs:queue
68 void fixed_queue_free(fixed_queue_t* queue, fixed_queue_free_cb free_cb) { in fixed_queue_free() argument
69 if (!queue) return; in fixed_queue_free()
71 fixed_queue_unregister_dequeue(queue); in fixed_queue_free()
74 for (const list_node_t* node = list_begin(queue->list); in fixed_queue_free()
75 node != list_end(queue->list); node = list_next(node)) in fixed_queue_free()
78 list_free(queue->list); in fixed_queue_free()
79 semaphore_free(queue->enqueue_sem); in fixed_queue_free()
80 semaphore_free(queue->dequeue_sem); in fixed_queue_free()
81 delete queue->mutex; in fixed_queue_free()
82 osi_free(queue); in fixed_queue_free()
85 void fixed_queue_flush(fixed_queue_t* queue, fixed_queue_free_cb free_cb) { in fixed_queue_flush() argument
86 if (!queue) return; in fixed_queue_flush()
88 while (!fixed_queue_is_empty(queue)) { in fixed_queue_flush()
89 void* data = fixed_queue_try_dequeue(queue); in fixed_queue_flush()
96 bool fixed_queue_is_empty(fixed_queue_t* queue) { in fixed_queue_is_empty() argument
97 if (queue == NULL) return true; in fixed_queue_is_empty()
99 std::lock_guard<std::mutex> lock(*queue->mutex); in fixed_queue_is_empty()
100 return list_is_empty(queue->list); in fixed_queue_is_empty()
103 size_t fixed_queue_length(fixed_queue_t* queue) { in fixed_queue_length() argument
104 if (queue == NULL) return 0; in fixed_queue_length()
106 std::lock_guard<std::mutex> lock(*queue->mutex); in fixed_queue_length()
107 return list_length(queue->list); in fixed_queue_length()
110 size_t fixed_queue_capacity(fixed_queue_t* queue) { in fixed_queue_capacity() argument
111 CHECK(queue != NULL); in fixed_queue_capacity()
113 return queue->capacity; in fixed_queue_capacity()
116 void fixed_queue_enqueue(fixed_queue_t* queue, void* data) { in fixed_queue_enqueue() argument
117 CHECK(queue != NULL); in fixed_queue_enqueue()
120 semaphore_wait(queue->enqueue_sem); in fixed_queue_enqueue()
123 std::lock_guard<std::mutex> lock(*queue->mutex); in fixed_queue_enqueue()
124 list_append(queue->list, data); in fixed_queue_enqueue()
127 semaphore_post(queue->dequeue_sem); in fixed_queue_enqueue()
130 void* fixed_queue_dequeue(fixed_queue_t* queue) { in fixed_queue_dequeue() argument
131 CHECK(queue != NULL); in fixed_queue_dequeue()
133 semaphore_wait(queue->dequeue_sem); in fixed_queue_dequeue()
137 std::lock_guard<std::mutex> lock(*queue->mutex); in fixed_queue_dequeue()
138 ret = list_front(queue->list); in fixed_queue_dequeue()
139 list_remove(queue->list, ret); in fixed_queue_dequeue()
142 semaphore_post(queue->enqueue_sem); in fixed_queue_dequeue()
147 bool fixed_queue_try_enqueue(fixed_queue_t* queue, void* data) { in fixed_queue_try_enqueue() argument
148 CHECK(queue != NULL); in fixed_queue_try_enqueue()
151 if (!semaphore_try_wait(queue->enqueue_sem)) return false; in fixed_queue_try_enqueue()
154 std::lock_guard<std::mutex> lock(*queue->mutex); in fixed_queue_try_enqueue()
155 list_append(queue->list, data); in fixed_queue_try_enqueue()
158 semaphore_post(queue->dequeue_sem); in fixed_queue_try_enqueue()
162 void* fixed_queue_try_dequeue(fixed_queue_t* queue) { in fixed_queue_try_dequeue() argument
163 if (queue == NULL) return NULL; in fixed_queue_try_dequeue()
165 if (!semaphore_try_wait(queue->dequeue_sem)) return NULL; in fixed_queue_try_dequeue()
169 std::lock_guard<std::mutex> lock(*queue->mutex); in fixed_queue_try_dequeue()
170 ret = list_front(queue->list); in fixed_queue_try_dequeue()
171 list_remove(queue->list, ret); in fixed_queue_try_dequeue()
174 semaphore_post(queue->enqueue_sem); in fixed_queue_try_dequeue()
179 void* fixed_queue_try_peek_first(fixed_queue_t* queue) { in fixed_queue_try_peek_first() argument
180 if (queue == NULL) return NULL; in fixed_queue_try_peek_first()
182 std::lock_guard<std::mutex> lock(*queue->mutex); in fixed_queue_try_peek_first()
183 return list_is_empty(queue->list) ? NULL : list_front(queue->list); in fixed_queue_try_peek_first()
186 void* fixed_queue_try_peek_last(fixed_queue_t* queue) { in fixed_queue_try_peek_last() argument
187 if (queue == NULL) return NULL; in fixed_queue_try_peek_last()
189 std::lock_guard<std::mutex> lock(*queue->mutex); in fixed_queue_try_peek_last()
190 return list_is_empty(queue->list) ? NULL : list_back(queue->list); in fixed_queue_try_peek_last()
193 void* fixed_queue_try_remove_from_queue(fixed_queue_t* queue, void* data) { in fixed_queue_try_remove_from_queue() argument
194 if (queue == NULL) return NULL; in fixed_queue_try_remove_from_queue()
198 std::lock_guard<std::mutex> lock(*queue->mutex); in fixed_queue_try_remove_from_queue()
199 if (list_contains(queue->list, data) && in fixed_queue_try_remove_from_queue()
200 semaphore_try_wait(queue->dequeue_sem)) { in fixed_queue_try_remove_from_queue()
201 removed = list_remove(queue->list, data); in fixed_queue_try_remove_from_queue()
207 semaphore_post(queue->enqueue_sem); in fixed_queue_try_remove_from_queue()
213 list_t* fixed_queue_get_list(fixed_queue_t* queue) { in fixed_queue_get_list() argument
214 CHECK(queue != NULL); in fixed_queue_get_list()
219 return queue->list; in fixed_queue_get_list()
222 int fixed_queue_get_dequeue_fd(const fixed_queue_t* queue) { in fixed_queue_get_dequeue_fd() argument
223 CHECK(queue != NULL); in fixed_queue_get_dequeue_fd()
224 return semaphore_get_fd(queue->dequeue_sem); in fixed_queue_get_dequeue_fd()
227 int fixed_queue_get_enqueue_fd(const fixed_queue_t* queue) { in fixed_queue_get_enqueue_fd() argument
228 CHECK(queue != NULL); in fixed_queue_get_enqueue_fd()
229 return semaphore_get_fd(queue->enqueue_sem); in fixed_queue_get_enqueue_fd()
232 void fixed_queue_register_dequeue(fixed_queue_t* queue, reactor_t* reactor, in fixed_queue_register_dequeue() argument
234 CHECK(queue != NULL); in fixed_queue_register_dequeue()
239 fixed_queue_unregister_dequeue(queue); in fixed_queue_register_dequeue()
241 queue->dequeue_ready = ready_cb; in fixed_queue_register_dequeue()
242 queue->dequeue_context = context; in fixed_queue_register_dequeue()
243 queue->dequeue_object = in fixed_queue_register_dequeue()
244 reactor_register(reactor, fixed_queue_get_dequeue_fd(queue), queue, in fixed_queue_register_dequeue()
248 void fixed_queue_unregister_dequeue(fixed_queue_t* queue) { in fixed_queue_unregister_dequeue() argument
249 CHECK(queue != NULL); in fixed_queue_unregister_dequeue()
251 if (queue->dequeue_object) { in fixed_queue_unregister_dequeue()
252 reactor_unregister(queue->dequeue_object); in fixed_queue_unregister_dequeue()
253 queue->dequeue_object = NULL; in fixed_queue_unregister_dequeue()
260 fixed_queue_t* queue = static_cast<fixed_queue_t*>(context); in internal_dequeue_ready() local
261 queue->dequeue_ready(queue, queue->dequeue_context); in internal_dequeue_ready()