summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--coccinelle/swap-two.cocci7
-rw-r--r--src/basic/prioq.c11
-rw-r--r--src/shared/barrier.c6
3 files changed, 10 insertions, 14 deletions
diff --git a/coccinelle/swap-two.cocci b/coccinelle/swap-two.cocci
new file mode 100644
index 0000000000..edf7d32403
--- /dev/null
+++ b/coccinelle/swap-two.cocci
@@ -0,0 +1,7 @@
+@@
+expression x, y, z;
+@@
+- z = x;
+- x = y;
+- y = z;
++ SWAP_TWO(x, y);
diff --git a/src/basic/prioq.c b/src/basic/prioq.c
index 4ef4eaf0cd..cfd08d5d23 100644
--- a/src/basic/prioq.c
+++ b/src/basic/prioq.c
@@ -65,9 +65,6 @@ int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func) {
}
static void swap(Prioq *q, unsigned j, unsigned k) {
- void *saved_data;
- unsigned *saved_idx;
-
assert(q);
assert(j < q->n_items);
assert(k < q->n_items);
@@ -75,12 +72,8 @@ static void swap(Prioq *q, unsigned j, unsigned k) {
assert(!q->items[j].idx || *(q->items[j].idx) == j);
assert(!q->items[k].idx || *(q->items[k].idx) == k);
- saved_data = q->items[j].data;
- saved_idx = q->items[j].idx;
- q->items[j].data = q->items[k].data;
- q->items[j].idx = q->items[k].idx;
- q->items[k].data = saved_data;
- q->items[k].idx = saved_idx;
+ SWAP_TWO(q->items[j].data, q->items[k].data);
+ SWAP_TWO(q->items[j].idx, q->items[k].idx);
if (q->items[j].idx)
*q->items[j].idx = j;
diff --git a/src/shared/barrier.c b/src/shared/barrier.c
index 79316dd4c2..bb5869dad4 100644
--- a/src/shared/barrier.c
+++ b/src/shared/barrier.c
@@ -151,8 +151,6 @@ void barrier_destroy(Barrier *b) {
* this is currently not needed so it hasn't been implemented.
*/
void barrier_set_role(Barrier *b, unsigned role) {
- int fd;
-
assert(b);
assert(IN_SET(role, BARRIER_PARENT, BARRIER_CHILD));
/* make sure this is only called once */
@@ -164,9 +162,7 @@ void barrier_set_role(Barrier *b, unsigned role) {
b->pipe[0] = safe_close(b->pipe[0]);
/* swap me/them for children */
- fd = b->me;
- b->me = b->them;
- b->them = fd;
+ SWAP_TWO(b->me, b->them);
}
}