mirror of
https://github.com/Genymobile/scrcpy
synced 2024-12-25 16:42:14 +00:00
Rename queue to sc_queue
Add a scrcpy-specific prefix.
This commit is contained in:
parent
af8a21ed7c
commit
099cba07f0
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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; \
|
||||
})
|
||||
|
@ -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[]) {
|
||||
|
Loading…
Reference in New Issue
Block a user