summaryrefslogtreecommitdiffstats
path: root/common/messagequeue.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-08-12 01:03:21 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-08-12 01:03:21 +0200
commit7c9ae062101b5dc8f963c70fb753f8346a9b5c48 (patch)
treecede184b10a9817e416f89a50fcf9588b4686fa2 /common/messagequeue.cpp
parentde860ce15b0921a37c0f3a21dbebe4311b9414a8 (diff)
downloadsink-7c9ae062101b5dc8f963c70fb753f8346a9b5c48.tar.gz
sink-7c9ae062101b5dc8f963c70fb753f8346a9b5c48.zip
Use nested transactions in the messagequeue
Diffstat (limited to 'common/messagequeue.cpp')
-rw-r--r--common/messagequeue.cpp8
1 files changed, 2 insertions, 6 deletions
diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp
index d2e285a..84385ca 100644
--- a/common/messagequeue.cpp
+++ b/common/messagequeue.cpp
@@ -29,18 +29,14 @@ void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::fu
29 const std::function<void(const Error &error)> &errorHandler) 29 const std::function<void(const Error &error)> &errorHandler)
30{ 30{
31 bool readValue = false; 31 bool readValue = false;
32 auto readTransaction = std::move(mStorage.createTransaction(Akonadi2::Storage::ReadOnly)); 32 mStorage.createTransaction(Akonadi2::Storage::ReadOnly).scan("", [this, resultHandler, errorHandler, &readValue](const QByteArray &key, const QByteArray &value) -> bool {
33 readTransaction.scan("", [this, resultHandler, errorHandler, &readValue, &readTransaction](const QByteArray &key, const QByteArray &value) -> bool {
34 if (Akonadi2::Storage::isInternalKey(key)) { 33 if (Akonadi2::Storage::isInternalKey(key)) {
35 return true; 34 return true;
36 } 35 }
37 readValue = true; 36 readValue = true;
38 //We need a copy of the key here, otherwise we can't store it in the lambda (the pointers will become invalid) 37 //We need a copy of the key here, otherwise we can't store it in the lambda (the pointers will become invalid)
39 const auto keyCopy = QByteArray(key.constData(), key.size()); 38 const auto keyCopy = QByteArray(key.constData(), key.size());
40 //TODO The value copy and the early transaction abort is necessary because we don't support parallel read-transactions yet (in case of a synchronous callback) 39 resultHandler(const_cast<void*>(static_cast<const void*>(value.data())), value.size(), [this, keyCopy, errorHandler](bool success) {
41 const auto valueCopy = QByteArray(value.constData(), value.size());
42 readTransaction.abort();
43 resultHandler(const_cast<void*>(static_cast<const void*>(valueCopy.data())), valueCopy.size(), [this, keyCopy, errorHandler](bool success) {
44 if (success) { 40 if (success) {
45 mStorage.createTransaction(Akonadi2::Storage::ReadWrite).remove(keyCopy, [errorHandler, keyCopy](const Akonadi2::Storage::Error &error) { 41 mStorage.createTransaction(Akonadi2::Storage::ReadWrite).remove(keyCopy, [errorHandler, keyCopy](const Akonadi2::Storage::Error &error) {
46 ErrorMsg() << "Error while removing value" << error.message << keyCopy; 42 ErrorMsg() << "Error while removing value" << error.message << keyCopy;