summaryrefslogtreecommitdiffstats
path: root/src/simpletransaction.cpp
blob: ca36d57022cf0cd40b935a49b0d3ec6bb4057395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "simpletransaction.h"
#include "debughelper.h"
#include <utility>

using std::pair;
using namespace Enums;

void simpleTransaction::transactionStart() {
  dbg() << "START" << transactionDepth;
  transactionDepth++;
}

void simpleTransaction::transactionAdd(PROCESS id) {
  dbg() << "ADD" << transactionDepth << id;
  if (transactionDepth > 0) {
    lastInTransaction = id;
  } else {
    transactionQueue.push(pair<PROCESS, PROCESS>(id, id));
  }
}

void simpleTransaction::transactionEnd(PROCESS pid) {
  dbg() << "END" << transactionDepth;
  if (transactionDepth > 0) {
    transactionDepth--;
    if (transactionDepth == 0 && lastInTransaction != INVALID) {
      transactionQueue.push(pair<PROCESS, PROCESS>(lastInTransaction, pid));
      lastInTransaction = INVALID;
    }
  }
}

PROCESS simpleTransaction::transactionIsOver(PROCESS id) {
  dbg() << "OVER" << transactionDepth << id;
  if (!transactionQueue.empty() && id == transactionQueue.front().first) {
    PROCESS ret = transactionQueue.front().second;
    transactionQueue.pop();
    return ret;
  }
  return INVALID;
}