Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
LockGuard.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Core module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_LOCKGUARD_HPP
8 #define NAZARA_LOCKGUARD_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 
12 namespace Nz
13 {
14  class Mutex;
15 
16  class LockGuard
17  {
18  public:
19  inline LockGuard(Mutex& mutex, bool lock = true);
20  inline ~LockGuard();
21 
22  inline void Lock();
23  inline bool TryLock();
24  inline void Unlock();
25 
26  private:
27  Mutex& m_mutex;
28  bool m_locked;
29  };
30 }
31 
32 #include <Nazara/Core/LockGuard.inl>
33 
34 #endif // NAZARA_LOCKGUARD_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
~LockGuard()
Destructs a LockGuard object and unlocks the mutex if it was previously locked.
Definition: LockGuard.inl:38
LockGuard(Mutex &mutex, bool lock=true)
Constructs a LockGuard object with a mutex.
Definition: LockGuard.inl:24
void Lock()
Locks the underlying mutex.
Definition: LockGuard.inl:49
bool TryLock()
Tries to lock the underlying mutex.
Definition: LockGuard.inl:63
Core class that represents a binary semaphore, a mutex.
Definition: Mutex.hpp:17
void Unlock()
Unlocks the underlying mutex.
Definition: LockGuard.inl:75
Core class that represents a mutex wrapper that provides a convenient RAII-style mechanism.
Definition: LockGuard.hpp:16