mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-04 07:09:06 +00:00
remove compound statements
This commit is contained in:
parent
7343b233e4
commit
de58dc21e5
2 changed files with 39 additions and 43 deletions
|
@ -2,11 +2,6 @@
|
||||||
#ifndef CBUF_H
|
#ifndef CBUF_H
|
||||||
#define CBUF_H
|
#define CBUF_H
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
// To define a circular buffer type of 20 ints:
|
// To define a circular buffer type of 20 ints:
|
||||||
// struct cbuf_int CBUF(int, 20);
|
// struct cbuf_int CBUF(int, 20);
|
||||||
//
|
//
|
||||||
|
@ -30,23 +25,25 @@
|
||||||
(void) ((PCBUF)->head = (PCBUF)->tail = 0)
|
(void) ((PCBUF)->head = (PCBUF)->tail = 0)
|
||||||
|
|
||||||
#define cbuf_push(PCBUF, ITEM) \
|
#define cbuf_push(PCBUF, ITEM) \
|
||||||
({ \
|
( \
|
||||||
bool ok = !cbuf_is_full(PCBUF); \
|
(!cbuf_is_full(PCBUF)) \
|
||||||
if (ok) { \
|
? ( \
|
||||||
(PCBUF)->data[(PCBUF)->head] = (ITEM); \
|
(PCBUF)->data[(PCBUF)->head] = (ITEM), \
|
||||||
(PCBUF)->head = ((PCBUF)->head + 1) % cbuf_size_(PCBUF); \
|
(PCBUF)->head = ((PCBUF)->head + 1) % cbuf_size_(PCBUF), \
|
||||||
} \
|
1 \
|
||||||
ok; \
|
) \
|
||||||
})
|
: 0 \
|
||||||
|
)
|
||||||
|
|
||||||
#define cbuf_take(PCBUF, PITEM) \
|
#define cbuf_take(PCBUF, PITEM) \
|
||||||
({ \
|
( \
|
||||||
bool ok = !cbuf_is_empty(PCBUF); \
|
(!cbuf_is_empty(PCBUF)) \
|
||||||
if (ok) { \
|
? ( \
|
||||||
*(PITEM) = (PCBUF)->data[(PCBUF)->tail]; \
|
*(PITEM) = (PCBUF)->data[(PCBUF)->tail], \
|
||||||
(PCBUF)->tail = ((PCBUF)->tail + 1) % cbuf_size_(PCBUF); \
|
(PCBUF)->tail = ((PCBUF)->tail + 1) % cbuf_size_(PCBUF), \
|
||||||
} \
|
1 \
|
||||||
ok; \
|
) \
|
||||||
})
|
: 0 \
|
||||||
|
)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
#ifndef QUEUE_H
|
#ifndef QUEUE_H
|
||||||
#define QUEUE_H
|
#define QUEUE_H
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
@ -51,27 +49,28 @@
|
||||||
|
|
||||||
// push a new item into the queue
|
// push a new item into the queue
|
||||||
#define queue_push(PQ, NEXTFIELD, ITEM) \
|
#define queue_push(PQ, NEXTFIELD, ITEM) \
|
||||||
(void) ({ \
|
(void) ( \
|
||||||
(ITEM)->NEXTFIELD = NULL; \
|
(ITEM)->NEXTFIELD = NULL, \
|
||||||
if (queue_is_empty(PQ)) { \
|
(queue_is_empty(PQ)) \
|
||||||
(PQ)->first = (PQ)->last = (ITEM); \
|
? (PQ)->first = (PQ)->last = (ITEM) \
|
||||||
} else { \
|
: ( \
|
||||||
(PQ)->last->NEXTFIELD = (ITEM); \
|
(PQ)->last->NEXTFIELD = (ITEM), \
|
||||||
(PQ)->last = (ITEM); \
|
(PQ)->last = (ITEM) \
|
||||||
} \
|
) \
|
||||||
})
|
\
|
||||||
|
)
|
||||||
|
|
||||||
// take the next item and remove it from the queue (the queue must not be empty)
|
// take the next item and remove it from the queue (the queue must not be empty)
|
||||||
// the result is stored in *(PITEM)
|
// the result is stored in *(PITEM)
|
||||||
// (without typeof(), we could not store a local variable having the correct
|
// (without typeof(), we could not store a local variable having the correct
|
||||||
// type so that we can "return" it)
|
// type so that we can "return" it)
|
||||||
#define queue_take(PQ, NEXTFIELD, PITEM) \
|
#define queue_take(PQ, NEXTFIELD, PITEM) \
|
||||||
(void) ({ \
|
(void) ( \
|
||||||
assert(!queue_is_empty(PQ)); \
|
assert(!queue_is_empty(PQ)), \
|
||||||
*(PITEM) = (PQ)->first; \
|
*(PITEM) = (PQ)->first, \
|
||||||
(PQ)->first = (PQ)->first->NEXTFIELD; \
|
(PQ)->first = (PQ)->first->NEXTFIELD \
|
||||||
})
|
)
|
||||||
// no need to update (PQ)->last if the queue is left empty:
|
// no need to update (PQ)->last if the queue is left empty:
|
||||||
// (PQ)->last is undefined if !(PQ)->first anyway
|
// (PQ)->last is undefined if !(PQ)->first anyway
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue