mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
615 B
C++
32 lines
615 B
C++
2 years ago
|
#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
|