diff options
author | saturneric <[email protected]> | 2023-12-03 20:25:21 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2023-12-03 20:25:21 +0000 |
commit | 054e6e28cca2517dda2319ef683314b3318c39a6 (patch) | |
tree | ae9ff4a9fe280f3640ca249bad45ab250cfd1610 /src/core/function/basic | |
parent | fix: slove issues in key/subkey generation (diff) | |
download | GpgFrontend-054e6e28cca2517dda2319ef683314b3318c39a6.tar.gz GpgFrontend-054e6e28cca2517dda2319ef683314b3318c39a6.zip |
feat: standarized and speed up app env loading process
Diffstat (limited to 'src/core/function/basic')
-rw-r--r-- | src/core/function/basic/GpgFunctionObject.h | 4 | ||||
-rw-r--r-- | src/core/function/basic/SingletonStorageCollection.cpp | 37 | ||||
-rw-r--r-- | src/core/function/basic/SingletonStorageCollection.h | 32 |
3 files changed, 45 insertions, 28 deletions
diff --git a/src/core/function/basic/GpgFunctionObject.h b/src/core/function/basic/GpgFunctionObject.h index ec0cebac..619cad04 100644 --- a/src/core/function/basic/GpgFunctionObject.h +++ b/src/core/function/basic/GpgFunctionObject.h @@ -79,7 +79,7 @@ class SingletonFunctionObject : public ChannelObject { } } - static_assert(std::is_base_of<SingletonFunctionObject<T>, T>::value, + static_assert(std::is_base_of_v<SingletonFunctionObject<T>, T>, "T not derived from SingletonFunctionObject<T>"); auto* p_storage = @@ -123,7 +123,7 @@ class SingletonFunctionObject : public ChannelObject { */ static auto CreateInstance( int channel, const std::function<ChannelObjectPtr(void)>& factory) -> T& { - static_assert(std::is_base_of<SingletonFunctionObject<T>, T>::value, + static_assert(std::is_base_of_v<SingletonFunctionObject<T>, T>, "T not derived from SingletonFunctionObject<T>"); auto* p_storage = diff --git a/src/core/function/basic/SingletonStorageCollection.cpp b/src/core/function/basic/SingletonStorageCollection.cpp index 144b69e2..e69c1279 100644 --- a/src/core/function/basic/SingletonStorageCollection.cpp +++ b/src/core/function/basic/SingletonStorageCollection.cpp @@ -28,6 +28,7 @@ #include "SingletonStorageCollection.h" +#include <memory> #include <shared_mutex> #include "core/function/basic/SingletonStorage.h" @@ -35,6 +36,10 @@ namespace GpgFrontend { +std::unique_ptr<SingletonStorageCollection, + SecureObjectDeleter<SingletonStorageCollection>> + instance = nullptr; + class SingletonStorageCollection::Impl { public: /** @@ -43,18 +48,22 @@ class SingletonStorageCollection::Impl { * @return SingletonStorageCollection* */ static auto GetInstance(bool force_refresh) -> SingletonStorageCollection* { - static SingletonStorageCollection* instance = nullptr; - if (force_refresh || instance == nullptr) { - instance = new SingletonStorageCollection(); - SPDLOG_TRACE("new single storage collection created: {}", - static_cast<void*>(instance)); + instance = SecureCreateUniqueObject<SingletonStorageCollection>(); + SPDLOG_TRACE("a new single storage collection created, address: {}", + static_cast<void*>(instance.get())); } - - return instance; + return instance.get(); } /** + * @brief Get the Instance object + * + * @return SingletonStorageCollection* + */ + static void Destroy() { instance = nullptr; } + + /** * @brief Get the Singleton Storage object * * @param singleton_function_object @@ -95,14 +104,18 @@ SingletonStorageCollection::SingletonStorageCollection() noexcept SingletonStorageCollection::~SingletonStorageCollection() = default; +auto GpgFrontend::SingletonStorageCollection::GetInstance(bool force_refresh) + -> GpgFrontend::SingletonStorageCollection* { + return Impl::GetInstance(force_refresh); +} + +void SingletonStorageCollection::Destroy() { + return SingletonStorageCollection::Impl::Destroy(); +} + auto SingletonStorageCollection::GetSingletonStorage( const std::type_info& type_id) -> GpgFrontend::SingletonStorage* { return p_->GetSingletonStorage(type_id); } -auto GpgFrontend::SingletonStorageCollection::GetInstance( - bool force_refresh = false) -> GpgFrontend::SingletonStorageCollection* { - return Impl::GetInstance(force_refresh); -} - } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/function/basic/SingletonStorageCollection.h b/src/core/function/basic/SingletonStorageCollection.h index b96bff3d..70b91cb9 100644 --- a/src/core/function/basic/SingletonStorageCollection.h +++ b/src/core/function/basic/SingletonStorageCollection.h @@ -28,8 +28,6 @@ #pragma once -#include <core/function/SecureMemoryAllocator.h> - #include "core/function/SecureMemoryAllocator.h" namespace GpgFrontend { @@ -41,6 +39,18 @@ using SingletonStoragePtr = class GPGFRONTEND_CORE_EXPORT SingletonStorageCollection { public: /** + * @brief + * + */ + SingletonStorageCollection() noexcept; + + /** + * @brief + * + */ + ~SingletonStorageCollection(); + + /** * @brief Get the Instance object * * @return SingletonStorageCollection* @@ -48,6 +58,12 @@ class GPGFRONTEND_CORE_EXPORT SingletonStorageCollection { static auto GetInstance(bool force_refresh) -> SingletonStorageCollection*; /** + * @brief + * + */ + static void Destroy(); + + /** * @brief Get the Singleton Storage object * * @param singleton_function_object @@ -58,18 +74,6 @@ class GPGFRONTEND_CORE_EXPORT SingletonStorageCollection { private: class Impl; std::unique_ptr<Impl> p_; - - /** - * @brief - * - */ - SingletonStorageCollection() noexcept; - - /** - * @brief - * - */ - ~SingletonStorageCollection(); }; } // namespace GpgFrontend
\ No newline at end of file |