mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-22 02:45:07 -04:00
ams: deduplicate static initialization logic
This commit is contained in:
parent
78f7218c4f
commit
30fac905af
24 changed files with 202 additions and 262 deletions
|
@ -25,27 +25,9 @@ namespace ams::settings::impl {
|
|||
StaticObject();
|
||||
public:
|
||||
static T &Get() {
|
||||
/* Declare static instance variables. */
|
||||
static constinit util::TypedStorage<T> s_storage = {};
|
||||
static constinit bool s_initialized = false;
|
||||
static constinit os::SdkMutex s_mutex;
|
||||
AMS_FUNCTION_LOCAL_STATIC(T, s_object);
|
||||
|
||||
/* If we haven't already done so, construct the instance. */
|
||||
if (AMS_UNLIKELY(!s_initialized)) {
|
||||
std::scoped_lock lk(s_mutex);
|
||||
|
||||
/* Check that we didn't concurrently construct the instance. */
|
||||
if (AMS_LIKELY(!s_initialized)) {
|
||||
/* Construct the instance. */
|
||||
util::ConstructAt(s_storage);
|
||||
|
||||
/* Note that we constructed. */
|
||||
s_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the constructed instance. */
|
||||
return util::GetReference(s_storage);
|
||||
return s_object;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue