diff --git a/native/cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingleton.h b/native/cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingleton.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/InternalModules/GlobalDBSingleton.h @@ -0,0 +1,33 @@ +#pragma once + +#include "../../Tools/WorkerThread.h" + +#include + +namespace comm { +class GlobalDBSingleton { + std::atomic multithreadingEnabled; + std::unique_ptr databaseThread; + + void scheduleOrRunCommonImpl(const taskType task) { + if (this->databaseThread != nullptr) { + this->databaseThread->scheduleTask(task); + return; + } + task(); + } + + void enableMultithreadingCommonImpl() { + if (this->databaseThread == nullptr) { + this->databaseThread = std::make_unique("database"); + this->multithreadingEnabled.store(true); + } + } + +public: + static GlobalDBSingleton instance; + GlobalDBSingleton(); + void scheduleOrRun(const taskType task); + void enableMultithreading(); +}; +} // namespace comm diff --git a/native/ios/Comm.xcodeproj/project.pbxproj b/native/ios/Comm.xcodeproj/project.pbxproj --- a/native/ios/Comm.xcodeproj/project.pbxproj +++ b/native/ios/Comm.xcodeproj/project.pbxproj @@ -222,6 +222,7 @@ CB38F2BE286C6C980010535C /* DeleteEntryMessageSpec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DeleteEntryMessageSpec.h; path = PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/DeleteEntryMessageSpec.h; sourceTree = ""; }; CB38F2BF286C6C980010535C /* UpdateRelationshipMessageSpec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UpdateRelationshipMessageSpec.h; path = PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/UpdateRelationshipMessageSpec.h; sourceTree = ""; }; CB3C621327CE66540054F24C /* libEXSecureStore.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libEXSecureStore.a; sourceTree = BUILT_PRODUCTS_DIR; }; + CBDEC69928ED859600C17588 /* GlobalDBSingleton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GlobalDBSingleton.h; sourceTree = ""; }; CBFE58272885852B003B94C9 /* ThreadOperations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ThreadOperations.h; path = PersistentStorageUtilities/ThreadOperationsUtilities/ThreadOperations.h; sourceTree = ""; }; CBFE58282885852B003B94C9 /* ThreadOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadOperations.cpp; path = PersistentStorageUtilities/ThreadOperationsUtilities/ThreadOperations.cpp; sourceTree = ""; }; F53DA7B3F26C2798DCE74A94 /* Pods-Comm.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Comm.debug.xcconfig"; path = "Target Support Files/Pods-Comm/Pods-Comm.debug.xcconfig"; sourceTree = ""; }; @@ -467,6 +468,7 @@ 726E5D722731A4240032361D /* InternalModules */ = { isa = PBXGroup; children = ( + CBDEC69928ED859600C17588 /* GlobalDBSingleton.h */, 726E5D732731A4790032361D /* NetworkModule.cpp */, 726E5D742731A4790032361D /* NetworkModule.h */, 726E5D762731A5E10032361D /* GlobalNetworkSingleton.cpp */,