/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/Foundation/Threading/ConditionalLock.h
42 строки
1 KB
Jan Krassnigg
Fixes for including public ez headers (#1755)
04 янв 2026, 10:57
Не верифицирован
04 янв 2026, 10:57
5feb7ef
Код
Авторство
О чём код?
#pragma once #include <Foundation/Basics.h> /// \brief RAII lock guard that conditionally acquires and releases locks based on runtime conditions /// /// Provides the same automatic lock management as ezLock but only performs the actual locking /// when a boolean condition is met. Useful in scenarios where locking is only required under /// certain circumstances, avoiding unnecessary synchronization overhead when protection is not needed. /// /// The condition is evaluated once at construction time. If false, no locking occurs throughout /// the object's lifetime, making this essentially a no-op with zero runtime cost. template <typename T> class ezConditionalLock { public: EZ_ALWAYS_INLINE explicit ezConditionalLock(T& lock, bool bCondition) : m_lock(lock) , m_bCondition(bCondition) { if (m_bCondition) { m_lock.Lock(); } } EZ_ALWAYS_INLINE ~ezConditionalLock() { if (m_bCondition) { m_lock.Unlock(); } } private: ezConditionalLock(); ezConditionalLock(const ezConditionalLock<T>& rhs); void operator=(const ezConditionalLock<T>& rhs); T& m_lock; bool m_bCondition; };