diff options
author | tezeb <tezeb+github@outoftheblue.pl> | 2017-01-10 00:18:23 +0100 |
---|---|---|
committer | tezeb <tezeb+github@outoftheblue.pl> | 2017-01-10 00:18:23 +0100 |
commit | 56b5674af3e59e95888774925f92f1ea0dc8e0f2 (patch) | |
tree | d23fb02609fb582623492e4a8b94ce281c09efa4 /src/simpletransaction.cpp | |
parent | c3f44c2cd1adb36013cc54638e1fd507d5121ad5 (diff) |
creation of transaction entity for better process-mgmt
Diffstat (limited to 'src/simpletransaction.cpp')
-rw-r--r-- | src/simpletransaction.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/simpletransaction.cpp b/src/simpletransaction.cpp new file mode 100644 index 00000000..ca36d570 --- /dev/null +++ b/src/simpletransaction.cpp @@ -0,0 +1,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; +} |