Branch data Line data Source code
1 : : // SPDX-FileCopyrightText: 2017 Anne Jan Brouwer
2 : : // SPDX-License-Identifier: GPL-3.0-or-later
3 : : /**
4 : : * @file
5 : : * @brief Implements SimpleTransaction as a queue of (last process, result)
6 : : * pairs.
7 : : */
8 : : #include "simpletransaction.h"
9 : : #include <utility>
10 : :
11 : : #include "qtpasslogging.h"
12 : :
13 : : using Enums::INVALID;
14 : : using Enums::PROCESS;
15 : :
16 : 132 : void SimpleTransaction::transactionStart() {
17 : 132 : qCDebug(lcQtPass) << "START" << transactionDepth;
18 : 132 : transactionDepth++;
19 : 132 : }
20 : :
21 : 336 : void SimpleTransaction::transactionAdd(PROCESS id) {
22 : 336 : qCDebug(lcQtPass) << "ADD" << transactionDepth << id;
23 [ + + ]: 336 : if (transactionDepth > 0) {
24 : 196 : lastInTransaction = id;
25 : : } else {
26 : : transactionQueue.emplace(id, id);
27 : : }
28 : 336 : }
29 : :
30 : 133 : void SimpleTransaction::transactionEnd(PROCESS pid) {
31 : 133 : qCDebug(lcQtPass) << "END" << transactionDepth;
32 [ + + ]: 133 : if (transactionDepth > 0) {
33 : 132 : transactionDepth--;
34 [ + + + + ]: 132 : if (transactionDepth == 0 && lastInTransaction != INVALID) {
35 : 130 : transactionQueue.emplace(lastInTransaction, pid);
36 : 130 : lastInTransaction = INVALID;
37 : : }
38 : : }
39 : 133 : }
40 : :
41 : 334 : auto SimpleTransaction::transactionIsOver(PROCESS id) -> PROCESS {
42 : 334 : qCDebug(lcQtPass) << "OVER" << transactionDepth << id;
43 [ + + + + ]: 334 : if (!transactionQueue.empty() && id == transactionQueue.front().first) {
44 : 265 : PROCESS ret = transactionQueue.front().second;
45 : : transactionQueue.pop();
46 : 265 : return ret;
47 : : }
48 : : return INVALID;
49 : : }
|