diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-17 19:00:08 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-18 15:08:56 +0200 |
commit | 060a7df1c44af33bd3b924a1e3a9e4a281c6f480 (patch) | |
tree | 049c2bb8cbb6eade263f7c45f7db23c175f7c5cf | |
parent | selftest/mpmc_ring: switch back to our own ring (diff) | |
download | wireguard-monolithic-historical-060a7df1c44af33bd3b924a1e3a9e4a281c6f480.tar.xz wireguard-monolithic-historical-060a7df1c44af33bd3b924a1e3a9e4a281c6f480.zip |
selftest/mpmc_ring: use rwsem instead of multiple completions
-rw-r--r-- | src/selftest/mpmc_ring.h | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/selftest/mpmc_ring.h b/src/selftest/mpmc_ring.h index d78a6c3..35145e7 100644 --- a/src/selftest/mpmc_ring.h +++ b/src/selftest/mpmc_ring.h @@ -21,13 +21,13 @@ struct worker_producer { struct mpmc_ptr_ring *ring; - struct completion completion; + struct rw_semaphore *sem; int thread_num; }; struct worker_consumer { struct mpmc_ptr_ring *ring; - struct completion completion; + struct rw_semaphore *sem; uint64_t total; uint64_t count; }; @@ -43,7 +43,7 @@ static __init int producer_function(void *data) schedule(); } } - complete_all(&td->completion); + up_read(td->sem); return 0; } @@ -62,7 +62,7 @@ static __init int consumer_function(void *data) td->total += value; ++td->count; } - complete_all(&td->completion); + up_read(td->sem); return 0; } @@ -71,6 +71,7 @@ bool __init mpmc_ring_selftest(void) struct worker_producer *producers; struct worker_consumer *consumers; struct mpmc_ptr_ring ring; + DECLARE_RWSEM(threads_done); int64_t total = 0, count = 0; int i; @@ -83,7 +84,8 @@ bool __init mpmc_ring_selftest(void) for (i = 0; i < THREADS_PRODUCER; ++i) { producers[i].ring = ˚ producers[i].thread_num = i; - init_completion(&producers[i].completion); + producers[i].sem = &threads_done; + down_read(producers[i].sem); kthread_run(producer_function, &producers[i], "producer %d", i); } @@ -91,14 +93,12 @@ bool __init mpmc_ring_selftest(void) consumers[i].ring = ˚ consumers[i].total = 0; consumers[i].count = 0; - init_completion(&consumers[i].completion); + consumers[i].sem = &threads_done; + down_read(consumers[i].sem); kthread_run(consumer_function, &consumers[i], "consumer %d", i); } - for (i = 0; i < THREADS_PRODUCER; ++i) - wait_for_completion(&producers[i].completion); - for (i = 0; i < THREADS_CONSUMER; ++i) - wait_for_completion(&consumers[i].completion); + down_write(&threads_done); BUG_ON(!mpmc_ptr_ring_empty(&ring)); mpmc_ptr_ring_cleanup(&ring, NULL); |