SceneSwitcher/lib/utils/sync-helpers.hpp
WarmUpTill 7a0e08b0d8
Some checks are pending
debian-build / build (push) Waiting to run
Push to master / Check Formatting 🔍 (push) Waiting to run
Push to master / Build Project 🧱 (push) Waiting to run
Push to master / Create Release 🛫 (push) Blocked by required conditions
Adapt to enable testing and add more tests
2026-03-14 13:34:50 +01:00

57 lines
1.2 KiB
C++

#pragma once
#include "export-symbol-helper.hpp"
#include <functional>
#include <mutex>
namespace advss {
// Helper used in macro segment edit widgets
#define GUARD_LOADING_AND_LOCK() \
if (_loading || !_entryData) { \
return; \
} \
auto lock = _entryData->Lock();
[[nodiscard]] EXPORT std::mutex *GetMutex();
[[nodiscard]] EXPORT std::lock_guard<std::mutex> LockContext();
[[nodiscard]] EXPORT std::unique_lock<std::mutex> *GetLoopLock();
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4251)
#endif
// std::mutex wrapper with no-op copy constructor and assignment operator
class EXPORT PerInstanceMutex {
public:
PerInstanceMutex();
~PerInstanceMutex();
PerInstanceMutex(const PerInstanceMutex &);
PerInstanceMutex &operator=(const PerInstanceMutex &);
operator std::mutex &();
operator const std::mutex &() const;
private:
std::mutex _mtx;
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif
class EXPORT Lockable {
public:
Lockable() = default;
virtual ~Lockable() = default;
[[nodiscard]] std::lock_guard<std::mutex> Lock();
void WithLock(const std::function<void()> &func);
private:
PerInstanceMutex _mtx;
};
} // namespace advss