From 099cba07f0349898938ef5a77753e65b3caa3e46 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 4 Jul 2021 15:05:08 +0200 Subject: [PATCH] Rename queue to sc_queue Add a scrcpy-specific prefix. --- app/src/recorder.c | 14 +++++++------- app/src/recorder.h | 2 +- app/src/util/queue.h | 32 ++++++++++++++++---------------- app/tests/test_queue.c | 20 ++++++++++---------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/app/src/recorder.c b/app/src/recorder.c index 0cf87934..f2775c3a 100644 --- a/app/src/recorder.c +++ b/app/src/recorder.c @@ -57,9 +57,9 @@ record_packet_delete(struct record_packet *rec) { static void recorder_queue_clear(struct recorder_queue *queue) { - while (!queue_is_empty(queue)) { + while (!sc_queue_is_empty(queue)) { struct record_packet *rec; - queue_take(queue, next, &rec); + sc_queue_take(queue, next, &rec); record_packet_delete(rec); } } @@ -135,14 +135,14 @@ run_recorder(void *data) { for (;;) { sc_mutex_lock(&recorder->mutex); - while (!recorder->stopped && queue_is_empty(&recorder->queue)) { + while (!recorder->stopped && sc_queue_is_empty(&recorder->queue)) { sc_cond_wait(&recorder->queue_cond, &recorder->mutex); } // if stopped is set, continue to process the remaining events (to // finish the recording) before actually stopping - if (recorder->stopped && queue_is_empty(&recorder->queue)) { + if (recorder->stopped && sc_queue_is_empty(&recorder->queue)) { sc_mutex_unlock(&recorder->mutex); struct record_packet *last = recorder->previous; if (last) { @@ -161,7 +161,7 @@ run_recorder(void *data) { } struct record_packet *rec; - queue_take(&recorder->queue, next, &rec); + sc_queue_take(&recorder->queue, next, &rec); sc_mutex_unlock(&recorder->mutex); @@ -235,7 +235,7 @@ recorder_open(struct recorder *recorder, const AVCodec *input_codec) { goto error_mutex_destroy; } - queue_init(&recorder->queue); + sc_queue_init(&recorder->queue); recorder->stopped = false; recorder->failed = false; recorder->header_written = false; @@ -340,7 +340,7 @@ recorder_push(struct recorder *recorder, const AVPacket *packet) { return false; } - queue_push(&recorder->queue, next, rec); + sc_queue_push(&recorder->queue, next, rec); sc_cond_signal(&recorder->queue_cond); sc_mutex_unlock(&recorder->mutex); diff --git a/app/src/recorder.h b/app/src/recorder.h index 0c376cd1..96caaf5f 100644 --- a/app/src/recorder.h +++ b/app/src/recorder.h @@ -17,7 +17,7 @@ struct record_packet { struct record_packet *next; }; -struct recorder_queue QUEUE(struct record_packet); +struct recorder_queue SC_QUEUE(struct record_packet); struct recorder { struct sc_packet_sink packet_sink; // packet sink trait diff --git a/app/src/util/queue.h b/app/src/util/queue.h index 0681070c..2233eca0 100644 --- a/app/src/util/queue.h +++ b/app/src/util/queue.h @@ -1,6 +1,6 @@ // generic intrusive FIFO queue -#ifndef QUEUE_H -#define QUEUE_H +#ifndef SC_QUEUE_H +#define SC_QUEUE_H #include "common.h" @@ -10,15 +10,15 @@ // To define a queue type of "struct foo": // struct queue_foo QUEUE(struct foo); -#define QUEUE(TYPE) { \ +#define SC_QUEUE(TYPE) { \ TYPE *first; \ TYPE *last; \ } -#define queue_init(PQ) \ +#define sc_queue_init(PQ) \ (void) ((PQ)->first = (PQ)->last = NULL) -#define queue_is_empty(PQ) \ +#define sc_queue_is_empty(PQ) \ !(PQ)->first // NEXTFIELD is the field in the ITEM type used for intrusive linked-list @@ -30,30 +30,30 @@ // }; // // // define the type "struct my_queue" -// struct my_queue QUEUE(struct foo); +// struct my_queue SC_QUEUE(struct foo); // // struct my_queue queue; -// queue_init(&queue); +// sc_queue_init(&queue); // // struct foo v1 = { .value = 42 }; // struct foo v2 = { .value = 27 }; // -// queue_push(&queue, next, v1); -// queue_push(&queue, next, v2); +// sc_queue_push(&queue, next, v1); +// sc_queue_push(&queue, next, v2); // // struct foo *foo; -// queue_take(&queue, next, &foo); +// sc_queue_take(&queue, next, &foo); // assert(foo->value == 42); -// queue_take(&queue, next, &foo); +// sc_queue_take(&queue, next, &foo); // assert(foo->value == 27); -// assert(queue_is_empty(&queue)); +// assert(sc_queue_is_empty(&queue)); // // push a new item into the queue -#define queue_push(PQ, NEXTFIELD, ITEM) \ +#define sc_queue_push(PQ, NEXTFIELD, ITEM) \ (void) ({ \ (ITEM)->NEXTFIELD = NULL; \ - if (queue_is_empty(PQ)) { \ + if (sc_queue_is_empty(PQ)) { \ (PQ)->first = (PQ)->last = (ITEM); \ } else { \ (PQ)->last->NEXTFIELD = (ITEM); \ @@ -65,9 +65,9 @@ // the result is stored in *(PITEM) // (without typeof(), we could not store a local variable having the correct // type so that we can "return" it) -#define queue_take(PQ, NEXTFIELD, PITEM) \ +#define sc_queue_take(PQ, NEXTFIELD, PITEM) \ (void) ({ \ - assert(!queue_is_empty(PQ)); \ + assert(!sc_queue_is_empty(PQ)); \ *(PITEM) = (PQ)->first; \ (PQ)->first = (PQ)->first->NEXTFIELD; \ }) diff --git a/app/tests/test_queue.c b/app/tests/test_queue.c index fcbafc62..d8b2b4ec 100644 --- a/app/tests/test_queue.c +++ b/app/tests/test_queue.c @@ -10,28 +10,28 @@ struct foo { }; static void test_queue(void) { - struct my_queue QUEUE(struct foo) queue; - queue_init(&queue); + struct my_queue SC_QUEUE(struct foo) queue; + sc_queue_init(&queue); - assert(queue_is_empty(&queue)); + assert(sc_queue_is_empty(&queue)); struct foo v1 = { .value = 42 }; struct foo v2 = { .value = 27 }; - queue_push(&queue, next, &v1); - queue_push(&queue, next, &v2); + sc_queue_push(&queue, next, &v1); + sc_queue_push(&queue, next, &v2); struct foo *foo; - assert(!queue_is_empty(&queue)); - queue_take(&queue, next, &foo); + assert(!sc_queue_is_empty(&queue)); + sc_queue_take(&queue, next, &foo); assert(foo->value == 42); - assert(!queue_is_empty(&queue)); - queue_take(&queue, next, &foo); + assert(!sc_queue_is_empty(&queue)); + sc_queue_take(&queue, next, &foo); assert(foo->value == 27); - assert(queue_is_empty(&queue)); + assert(sc_queue_is_empty(&queue)); } int main(int argc, char *argv[]) {