hw/arm/virt: Consolidate GIC finalize logic
[qemu.git] / include / qemu / transactions.h
blob2f2060acd902d57597c457f8464647bcde6466cd
1 /*
2 * Simple transactions API
4 * Copyright (c) 2021 Virtuozzo International GmbH.
6 * Author:
7 * Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * = Generic transaction API =
25 * The intended usage is the following: you create "prepare" functions, which
26 * represents the actions. They will usually have Transaction* argument, and
27 * call tran_add() to register finalization callbacks. For finalization
28 * callbacks, prepare corresponding TransactionActionDrv structures.
30 * Then, when you need to make a transaction, create an empty Transaction by
31 * tran_create(), call your "prepare" functions on it, and finally call
32 * tran_abort() or tran_commit() to finalize the transaction by corresponding
33 * finalization actions in reverse order.
35 * The clean() functions registered by the drivers in a transaction are called
36 * last, after all abort() or commit() functions have been called.
39 #ifndef QEMU_TRANSACTIONS_H
40 #define QEMU_TRANSACTIONS_H
42 #include <gmodule.h>
44 typedef struct TransactionActionDrv {
45 void (*abort)(void *opaque);
46 void (*commit)(void *opaque);
47 void (*clean)(void *opaque);
48 } TransactionActionDrv;
50 typedef struct Transaction Transaction;
52 Transaction *tran_new(void);
53 void tran_add(Transaction *tran, TransactionActionDrv *drv, void *opaque);
54 void tran_abort(Transaction *tran);
55 void tran_commit(Transaction *tran);
57 static inline void tran_finalize(Transaction *tran, int ret)
59 if (ret < 0) {
60 tran_abort(tran);
61 } else {
62 tran_commit(tran);
66 #endif /* QEMU_TRANSACTIONS_H */