diff options
author | Aleksi Lindeman <dec05eba@protonmail.com> | 2018-11-01 07:15:28 +0100 |
---|---|---|
committer | Aleksi Lindeman <dec05eba@protonmail.com> | 2018-11-01 07:15:28 +0100 |
commit | 88149764207c7719b6a979c5eb4dea3269bdd3e5 (patch) | |
tree | 94a92edbdbc6c502d7ec0755f7f6a0555ee93800 /src | |
parent | e2eb4f72050a297668850deed91cc88860b6ad45 (diff) |
Make operation callback funcs synchronous
Diffstat (limited to 'src')
-rw-r--r-- | src/DatabaseStorage.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp index 34dd09a..9611993 100644 --- a/src/DatabaseStorage.cpp +++ b/src/DatabaseStorage.cpp @@ -213,6 +213,7 @@ namespace odhtdb void DatabaseStorage::loadNode(const Hash &nodeHash, DatabaseLoadOrder loadOrder) { + std::lock_guard<std::recursive_mutex> lock(databaseOperationCallbackMutex); string orderByString; if(loadOrder == DatabaseLoadOrder::OLDEST_FIRST) orderByString = " ORDER BY timestamp ASC"; @@ -1053,7 +1054,10 @@ namespace odhtdb { const DatabaseCreateNodeRequest createNodeRequest(&nodeHash, timestamp, creatorPublicKey, adminGroupId, database); if(database->onCreateNodeCallbackFunc) + { + std::lock_guard<std::recursive_mutex> lock(databaseOperationCallbackMutex); database->onCreateNodeCallbackFunc(createNodeRequest); + } sqlite3_reset(selectNodeAddDataByNodeStmt); sqlite3_clear_bindings(selectNodeAddDataByNodeStmt); @@ -1211,7 +1215,10 @@ namespace odhtdb Log::debug("Got add object, timestamp: %zu, data: %.*s", timestamp, decryptedBody.getDecryptedText().size, decryptedBody.getDecryptedText().data); const DatabaseAddNodeRequest addNodeRequest(&nodeHash, &dataHash, timestamp, creatorPublicKey, decryptedBody.getDecryptedText(), database); if(database->onAddNodeCallbackFunc) + { + std::lock_guard<std::recursive_mutex> lock(databaseOperationCallbackMutex); database->onAddNodeCallbackFunc(addNodeRequest); + } } catch(DecryptionException &e) { @@ -1244,7 +1251,10 @@ namespace odhtdb Log::debug("Got add user object, timestamp: %zu, user added: %s", timestamp, userToAddPublicKey->toString().c_str()); DatabaseAddUserRequest addUserRequest(&nodeHash, &dataHash, timestamp, creatorPublicKey, userToAddPublicKey, groupToAddUserTo, database); if(database->onAddUserCallbackFunc) + { + std::lock_guard<std::recursive_mutex> lock(databaseOperationCallbackMutex); database->onAddUserCallbackFunc(addUserRequest); + } return true; } |