aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cubeb_array_queue.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/cubeb_array_queue.h')
-rw-r--r--src/cubeb_array_queue.h28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/cubeb_array_queue.h b/src/cubeb_array_queue.h
index a8ea4cd..d6d9581 100644
--- a/src/cubeb_array_queue.h
+++ b/src/cubeb_array_queue.h
@@ -16,8 +16,7 @@
extern "C" {
#endif
-typedef struct
-{
+typedef struct {
void ** buf;
size_t num;
size_t writePos;
@@ -25,10 +24,11 @@ typedef struct
pthread_mutex_t mutex;
} array_queue;
-array_queue * array_queue_create(size_t num)
+array_queue *
+array_queue_create(size_t num)
{
assert(num != 0);
- array_queue * new_queue = (array_queue*)calloc(1, sizeof(array_queue));
+ array_queue * new_queue = (array_queue *)calloc(1, sizeof(array_queue));
new_queue->buf = (void **)calloc(1, sizeof(void *) * num);
new_queue->readPos = 0;
new_queue->writePos = 0;
@@ -39,7 +39,8 @@ array_queue * array_queue_create(size_t num)
return new_queue;
}
-void array_queue_destroy(array_queue * aq)
+void
+array_queue_destroy(array_queue * aq)
{
assert(aq);
@@ -48,14 +49,14 @@ void array_queue_destroy(array_queue * aq)
free(aq);
}
-int array_queue_push(array_queue * aq, void * item)
+int
+array_queue_push(array_queue * aq, void * item)
{
assert(item);
pthread_mutex_lock(&aq->mutex);
int ret = -1;
- if(aq->buf[aq->writePos % aq->num] == NULL)
- {
+ if (aq->buf[aq->writePos % aq->num] == NULL) {
aq->buf[aq->writePos % aq->num] = item;
aq->writePos = (aq->writePos + 1) % aq->num;
ret = 0;
@@ -65,12 +66,12 @@ int array_queue_push(array_queue * aq, void * item)
return ret;
}
-void* array_queue_pop(array_queue * aq)
+void *
+array_queue_pop(array_queue * aq)
{
pthread_mutex_lock(&aq->mutex);
void * value = aq->buf[aq->readPos % aq->num];
- if(value)
- {
+ if (value) {
aq->buf[aq->readPos % aq->num] = NULL;
aq->readPos = (aq->readPos + 1) % aq->num;
}
@@ -78,7 +79,8 @@ void* array_queue_pop(array_queue * aq)
return value;
}
-size_t array_queue_get_size(array_queue * aq)
+size_t
+array_queue_get_size(array_queue * aq)
{
pthread_mutex_lock(&aq->mutex);
ssize_t r = aq->writePos - aq->readPos;
@@ -94,4 +96,4 @@ size_t array_queue_get_size(array_queue * aq)
}
#endif
-#endif //CUBE_ARRAY_QUEUE_H
+#endif // CUBE_ARRAY_QUEUE_H