mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-28 02:21:25 +00:00
code: Migrate configuration to new dynamic loader
This commit is contained in:
parent
5ed2010015
commit
2f362efa38
3 changed files with 23 additions and 22 deletions
|
@ -92,20 +92,27 @@ bool streamfx::configuration::is_different_version()
|
|||
return (version() & STREAMFX_MASK_COMPAT) != (STREAMFX_VERSION & STREAMFX_MASK_COMPAT);
|
||||
}
|
||||
|
||||
static std::shared_ptr<streamfx::configuration> _instance = nullptr;
|
||||
|
||||
void streamfx::configuration::initialize()
|
||||
{
|
||||
if (!_instance)
|
||||
_instance = std::make_shared<streamfx::configuration>();
|
||||
}
|
||||
|
||||
void streamfx::configuration::finalize()
|
||||
{
|
||||
_instance.reset();
|
||||
}
|
||||
|
||||
std::shared_ptr<streamfx::configuration> streamfx::configuration::instance()
|
||||
{
|
||||
return _instance;
|
||||
static std::weak_ptr<streamfx::configuration> winst;
|
||||
static std::mutex mtx;
|
||||
|
||||
std::unique_lock<decltype(mtx)> lock(mtx);
|
||||
auto instance = winst.lock();
|
||||
if (!instance) {
|
||||
instance = std::shared_ptr<streamfx::configuration>(new streamfx::configuration());
|
||||
winst = instance;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
static std::shared_ptr<streamfx::configuration> loader_instance;
|
||||
|
||||
static auto loader = streamfx::loader(
|
||||
[]() { // Initalizer
|
||||
loader_instance = streamfx::configuration::instance();
|
||||
},
|
||||
[]() { // Finalizer
|
||||
loader_instance.reset();
|
||||
},
|
||||
streamfx::loader_priority::HIGHER); // Attempt to load after critical functionality.
|
||||
|
|
|
@ -26,6 +26,8 @@ namespace streamfx {
|
|||
|
||||
public:
|
||||
~configuration();
|
||||
|
||||
private:
|
||||
configuration();
|
||||
|
||||
public:
|
||||
|
@ -39,8 +41,6 @@ namespace streamfx {
|
|||
bool is_different_version();
|
||||
|
||||
public /* Singleton */:
|
||||
static void initialize();
|
||||
static void finalize();
|
||||
static std::shared_ptr<streamfx::configuration> instance();
|
||||
};
|
||||
} // namespace streamfx
|
||||
|
|
|
@ -138,9 +138,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize global configuration.
|
||||
streamfx::configuration::initialize();
|
||||
|
||||
// Initialize Source Tracker
|
||||
_source_tracker = streamfx::obs::source_tracker::get();
|
||||
|
||||
|
@ -331,9 +328,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
|||
// _updater.reset();
|
||||
//#endif
|
||||
|
||||
// Finalize Configuration
|
||||
streamfx::configuration::finalize();
|
||||
|
||||
// Run all finalizers.
|
||||
for (auto kv : streamfx::get_finalizers()) {
|
||||
for (auto init : kv.second) {
|
||||
|
|
Loading…
Reference in a new issue