mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-12-24 08:56:42 -05:00
initial commit
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@3 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
b1c00dcd0a
commit
9cb0b933e2
47 changed files with 3425 additions and 0 deletions
77
src/queue.c
Normal file
77
src/queue.c
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
struct queue_entry {
|
||||
struct queue_entry *next;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct queue {
|
||||
struct queue_entry *front, *back;
|
||||
unsigned length;
|
||||
};
|
||||
|
||||
struct queue* queue_new(void) {
|
||||
struct queue *q = malloc(sizeof(struct queue));
|
||||
assert(q);
|
||||
q->front = q->back = NULL;
|
||||
q->length = 0;
|
||||
return q;
|
||||
}
|
||||
|
||||
void queue_free(struct queue* q, void (*destroy)(void *p, void *userdata), void *userdata) {
|
||||
struct queue_entry *e;
|
||||
assert(q);
|
||||
|
||||
e = q->front;
|
||||
while (e) {
|
||||
struct queue_entry *n = e->next;
|
||||
|
||||
if (destroy)
|
||||
destroy(e->data, userdata);
|
||||
|
||||
free(e);
|
||||
e = n;
|
||||
}
|
||||
|
||||
free(q);
|
||||
}
|
||||
|
||||
void queue_push(struct queue *q, void *p) {
|
||||
struct queue_entry *e;
|
||||
|
||||
e = malloc(sizeof(struct queue_entry));
|
||||
|
||||
e->data = p;
|
||||
e->next = NULL;
|
||||
|
||||
if (q->back)
|
||||
q->back->next = e;
|
||||
else {
|
||||
assert(!q->front);
|
||||
q->front = e;
|
||||
}
|
||||
|
||||
q->back = e;
|
||||
q->length++;
|
||||
}
|
||||
|
||||
void* queue_pop(struct queue *q) {
|
||||
void *p;
|
||||
struct queue_entry *e;
|
||||
assert(q);
|
||||
|
||||
if (!(e = q->front))
|
||||
return NULL;
|
||||
|
||||
q->front = e->next;
|
||||
if (q->back == e)
|
||||
q->back = NULL;
|
||||
|
||||
p = e->data;
|
||||
free(e);
|
||||
|
||||
return p;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue