[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 03/34] block/throttle-groups: Use lock guard macros
From: |
Kevin Wolf |
Subject: |
[PULL 03/34] block/throttle-groups: Use lock guard macros |
Date: |
Fri, 11 Dec 2020 18:07:41 +0100 |
From: Gan Qixin <ganqixin@huawei.com>
Replace manual lock()/unlock() calls with lock guard macros
(QEMU_LOCK_GUARD/WITH_QEMU_LOCK_GUARD) in block/throttle-groups.
Signed-off-by: Gan Qixin <ganqixin@huawei.com>
Message-Id: <20201203075055.127773-4-ganqixin@huawei.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/throttle-groups.c | 48 ++++++++++++++++++++---------------------
1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/block/throttle-groups.c b/block/throttle-groups.c
index e2f2813c0f..abd16ed9db 100644
--- a/block/throttle-groups.c
+++ b/block/throttle-groups.c
@@ -546,7 +546,7 @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm,
tgm->aio_context = ctx;
qatomic_set(&tgm->restart_pending, 0);
- qemu_mutex_lock(&tg->lock);
+ QEMU_LOCK_GUARD(&tg->lock);
/* If the ThrottleGroup is new set this ThrottleGroupMember as the token */
for (i = 0; i < 2; i++) {
if (!tg->tokens[i]) {
@@ -565,8 +565,6 @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm,
qemu_co_mutex_init(&tgm->throttled_reqs_lock);
qemu_co_queue_init(&tgm->throttled_reqs[0]);
qemu_co_queue_init(&tgm->throttled_reqs[1]);
-
- qemu_mutex_unlock(&tg->lock);
}
/* Unregister a ThrottleGroupMember from its group, removing it from the list,
@@ -594,25 +592,25 @@ void throttle_group_unregister_tgm(ThrottleGroupMember
*tgm)
/* Wait for throttle_group_restart_queue_entry() coroutines to finish */
AIO_WAIT_WHILE(tgm->aio_context, qatomic_read(&tgm->restart_pending) > 0);
- qemu_mutex_lock(&tg->lock);
- for (i = 0; i < 2; i++) {
- assert(tgm->pending_reqs[i] == 0);
- assert(qemu_co_queue_empty(&tgm->throttled_reqs[i]));
- assert(!timer_pending(tgm->throttle_timers.timers[i]));
- if (tg->tokens[i] == tgm) {
- token = throttle_group_next_tgm(tgm);
- /* Take care of the case where this is the last tgm in the group */
- if (token == tgm) {
- token = NULL;
+ WITH_QEMU_LOCK_GUARD(&tg->lock) {
+ for (i = 0; i < 2; i++) {
+ assert(tgm->pending_reqs[i] == 0);
+ assert(qemu_co_queue_empty(&tgm->throttled_reqs[i]));
+ assert(!timer_pending(tgm->throttle_timers.timers[i]));
+ if (tg->tokens[i] == tgm) {
+ token = throttle_group_next_tgm(tgm);
+ /* Take care of the case where this is the last tgm in the
group */
+ if (token == tgm) {
+ token = NULL;
+ }
+ tg->tokens[i] = token;
}
- tg->tokens[i] = token;
}
- }
- /* remove the current tgm from the list */
- QLIST_REMOVE(tgm, round_robin);
- throttle_timers_destroy(&tgm->throttle_timers);
- qemu_mutex_unlock(&tg->lock);
+ /* remove the current tgm from the list */
+ QLIST_REMOVE(tgm, round_robin);
+ throttle_timers_destroy(&tgm->throttle_timers);
+ }
throttle_group_unref(&tg->ts);
tgm->throttle_state = NULL;
@@ -638,14 +636,14 @@ void
throttle_group_detach_aio_context(ThrottleGroupMember *tgm)
assert(qemu_co_queue_empty(&tgm->throttled_reqs[1]));
/* Kick off next ThrottleGroupMember, if necessary */
- qemu_mutex_lock(&tg->lock);
- for (i = 0; i < 2; i++) {
- if (timer_pending(tt->timers[i])) {
- tg->any_timer_armed[i] = false;
- schedule_next_request(tgm, i);
+ WITH_QEMU_LOCK_GUARD(&tg->lock) {
+ for (i = 0; i < 2; i++) {
+ if (timer_pending(tt->timers[i])) {
+ tg->any_timer_armed[i] = false;
+ schedule_next_request(tgm, i);
+ }
}
}
- qemu_mutex_unlock(&tg->lock);
throttle_timers_detach_aio_context(tt);
tgm->aio_context = NULL;
--
2.29.2
- [PULL 00/34] Block layer patches, Kevin Wolf, 2020/12/11
- [PULL 02/34] block/curl: Use lock guard macros, Kevin Wolf, 2020/12/11
- [PULL 01/34] block/accounting: Use lock guard macros, Kevin Wolf, 2020/12/11
- [PULL 04/34] block/iscsi: Use lock guard macros, Kevin Wolf, 2020/12/11
- [PULL 03/34] block/throttle-groups: Use lock guard macros,
Kevin Wolf <=
- [PULL 06/34] fuse: Allow exporting BDSs via FUSE, Kevin Wolf, 2020/12/11
- [PULL 08/34] fuse: Allow growable exports, Kevin Wolf, 2020/12/11
- [PULL 07/34] fuse: Implement standard FUSE operations, Kevin Wolf, 2020/12/11
- [PULL 05/34] meson: Detect libfuse, Kevin Wolf, 2020/12/11
- [PULL 09/34] fuse: (Partially) implement fallocate(), Kevin Wolf, 2020/12/11
- [PULL 10/34] fuse: Implement hole detection through lseek, Kevin Wolf, 2020/12/11
- [PULL 12/34] iotests: Do not pipe _make_test_img, Kevin Wolf, 2020/12/11
- [PULL 11/34] iotests: Do not needlessly filter _make_test_img, Kevin Wolf, 2020/12/11
- [PULL 13/34] iotests: Use convert -n in some cases, Kevin Wolf, 2020/12/11
- [PULL 15/34] iotests: Derive image names from $TEST_IMG, Kevin Wolf, 2020/12/11