Skip to content

Commit

Permalink
Locked<T>: optimistically use SpinMutex to consume less RAM
Browse files Browse the repository at this point in the history
std::mutex is 5 pointers large on x64, whereas std::atomic_flag at most one.
  • Loading branch information
Al2Klimov committed Aug 26, 2024
1 parent b4c4202 commit b7611ed
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/base/atomic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,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;
};

Expand Down

0 comments on commit b7611ed

Please sign in to comment.