1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-03 17:37:18 +00:00
OpenMW/components/detournavigator/updateguard.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
615 B
C++
Raw Normal View History

#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_UPDATEGUARD_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_UPDATEGUARD_H
#include <memory>
#include <mutex>
namespace DetourNavigator
{
class UpdateGuard
{
public:
explicit UpdateGuard(std::mutex& mutex)
: mMutex(mutex)
{
}
private:
std::mutex& mMutex;
friend struct UnlockUpdateGuard;
};
struct UnlockUpdateGuard
{
void operator()(UpdateGuard* value) const { value->mMutex.unlock(); }
};
using ScopedUpdateGuard = std::unique_ptr<UpdateGuard, UnlockUpdateGuard>;
}
#endif