Skip to content

Commit 079bff6

Browse files
committed
transactions: Invoke clean() after everything else
Invoke the transaction drivers' .clean() methods only after all .commit() or .abort() handlers are done. This makes it easier to have nested transactions where the top-level transactions pass objects to lower transactions that the latter can still use throughout their commit/abort phases, while the top-level transaction keeps a reference that is released in its .clean() method. (Before this commit, that is also possible, but the top-level transaction would need to take care to invoke tran_add() before the lower-level transaction does. This commit makes the ordering irrelevant, which is just a bit nicer.) Signed-off-by: Hanna Reitz <[email protected]> Message-Id: <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]> Signed-off-by: Kevin Wolf <[email protected]> Message-Id: <[email protected]> Signed-off-by: Hanna Reitz <[email protected]>
1 parent 562bda8 commit 079bff6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

include/qemu/transactions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* tran_create(), call your "prepare" functions on it, and finally call
3232
* tran_abort() or tran_commit() to finalize the transaction by corresponding
3333
* finalization actions in reverse order.
34+
*
35+
* The clean() functions registered by the drivers in a transaction are called
36+
* last, after all abort() or commit() functions have been called.
3437
*/
3538

3639
#ifndef QEMU_TRANSACTIONS_H

util/transactions.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ void tran_abort(Transaction *tran)
6161
{
6262
TransactionAction *act, *next;
6363

64-
QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) {
64+
QSLIST_FOREACH(act, &tran->actions, entry) {
6565
if (act->drv->abort) {
6666
act->drv->abort(act->opaque);
6767
}
68+
}
6869

70+
QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) {
6971
if (act->drv->clean) {
7072
act->drv->clean(act->opaque);
7173
}
@@ -80,11 +82,13 @@ void tran_commit(Transaction *tran)
8082
{
8183
TransactionAction *act, *next;
8284

83-
QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) {
85+
QSLIST_FOREACH(act, &tran->actions, entry) {
8486
if (act->drv->commit) {
8587
act->drv->commit(act->opaque);
8688
}
89+
}
8790

91+
QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) {
8892
if (act->drv->clean) {
8993
act->drv->clean(act->opaque);
9094
}

0 commit comments

Comments
 (0)