Locked<T>: optimistically use SpinMutex to consume less RAM

std::mutex is 5 pointers large on x64, whereas std::atomic_flag at most one.
This commit is contained in:
Alexander A. Klimov 2024-08-26 17:18:58 +02:00
parent efc8266aa7
commit 37b4d107d9
1 changed files with 3 additions and 3 deletions

View File

@ -80,20 +80,20 @@ class Locked
public:
inline T load() const
{
std::unique_lock<std::mutex> lock(m_Mutex);
std::unique_lock lock (m_Mutex);
return m_Value;
}
inline void store(T desired)
{
std::unique_lock<std::mutex> lock(m_Mutex);
std::unique_lock lock (m_Mutex);
m_Value = std::move(desired);
}
private:
mutable std::mutex m_Mutex;
mutable SpinMutex m_Mutex;
T m_Value;
};