summaryrefslogtreecommitdiff
path: root/thirdparty/wslay/wslay_queue.c
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/wslay/wslay_queue.c')
-rw-r--r--thirdparty/wslay/wslay_queue.c98
1 files changed, 29 insertions, 69 deletions
diff --git a/thirdparty/wslay/wslay_queue.c b/thirdparty/wslay/wslay_queue.c
index 8d2669687d..ebde3ba83d 100644
--- a/thirdparty/wslay/wslay_queue.c
+++ b/thirdparty/wslay/wslay_queue.c
@@ -27,91 +27,51 @@
#include <string.h>
#include <assert.h>
-struct wslay_queue* wslay_queue_new(void)
-{
- struct wslay_queue *queue = (struct wslay_queue*)malloc
- (sizeof(struct wslay_queue));
- if(!queue) {
- return NULL;
- }
- queue->top = queue->tail = NULL;
- return queue;
-}
+#include "wslay_macro.h"
-void wslay_queue_free(struct wslay_queue *queue)
-{
- if(!queue) {
- return;
- } else {
- struct wslay_queue_cell *p = queue->top;
- while(p) {
- struct wslay_queue_cell *next = p->next;
- free(p);
- p = next;
- }
- free(queue);
- }
+void wslay_queue_init(struct wslay_queue *queue) {
+ queue->top = NULL;
+ queue->tail = &queue->top;
}
-int wslay_queue_push(struct wslay_queue *queue, void *data)
-{
- struct wslay_queue_cell *new_cell = (struct wslay_queue_cell*)malloc
- (sizeof(struct wslay_queue_cell));
- if(!new_cell) {
- return WSLAY_ERR_NOMEM;
- }
- new_cell->data = data;
- new_cell->next = NULL;
- if(queue->tail) {
- queue->tail->next = new_cell;
- queue->tail = new_cell;
+void wslay_queue_deinit(struct wslay_queue *queue) { (void)queue; }
- } else {
- queue->top = queue->tail = new_cell;
- }
- return 0;
+void wslay_queue_push(struct wslay_queue *queue,
+ struct wslay_queue_entry *ent) {
+ ent->next = NULL;
+ *queue->tail = ent;
+ queue->tail = &ent->next;
}
-int wslay_queue_push_front(struct wslay_queue *queue, void *data)
-{
- struct wslay_queue_cell *new_cell = (struct wslay_queue_cell*)malloc
- (sizeof(struct wslay_queue_cell));
- if(!new_cell) {
- return WSLAY_ERR_NOMEM;
- }
- new_cell->data = data;
- new_cell->next = queue->top;
- queue->top = new_cell;
- if(!queue->tail) {
- queue->tail = queue->top;
+void wslay_queue_push_front(struct wslay_queue *queue,
+ struct wslay_queue_entry *ent) {
+ ent->next = queue->top;
+ queue->top = ent;
+
+ if (ent->next == NULL) {
+ queue->tail = &ent->next;
}
- return 0;
}
-void wslay_queue_pop(struct wslay_queue *queue)
-{
- struct wslay_queue_cell *top = queue->top;
- assert(top);
- queue->top = top->next;
- if(top == queue->tail) {
- queue->tail = NULL;
+void wslay_queue_pop(struct wslay_queue *queue) {
+ assert(queue->top);
+ queue->top = queue->top->next;
+ if (queue->top == NULL) {
+ queue->tail = &queue->top;
}
- free(top);
}
-void* wslay_queue_top(struct wslay_queue *queue)
-{
+struct wslay_queue_entry *wslay_queue_top(struct wslay_queue *queue) {
assert(queue->top);
- return queue->top->data;
+ return queue->top;
}
-void* wslay_queue_tail(struct wslay_queue *queue)
-{
- assert(queue->tail);
- return queue->tail->data;
+struct wslay_queue_entry *wslay_queue_tail(struct wslay_queue *queue) {
+ assert(queue->top);
+ return wslay_struct_of(queue->tail, struct wslay_queue_entry, next);
}
-int wslay_queue_empty(struct wslay_queue *queue)
-{
+int wslay_queue_empty(struct wslay_queue *queue) {
+ assert(queue->top || queue->tail == &queue->top);
return queue->top == NULL;
}