Core: Made Mutex and ConditionVariable moveable
Former-commit-id: 891fbb35d050f3df572cbbecd0191b75f556e59d
This commit is contained in:
parent
790275da8f
commit
f9a95ce054
|
|
@ -19,7 +19,7 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
ConditionVariable();
|
ConditionVariable();
|
||||||
ConditionVariable(const ConditionVariable&) = delete;
|
ConditionVariable(const ConditionVariable&) = delete;
|
||||||
ConditionVariable(ConditionVariable&&) = delete; ///TODO
|
inline ConditionVariable(ConditionVariable&& condition) noexcept;
|
||||||
~ConditionVariable();
|
~ConditionVariable();
|
||||||
|
|
||||||
void Signal();
|
void Signal();
|
||||||
|
|
@ -29,11 +29,13 @@ namespace Nz
|
||||||
bool Wait(Mutex* mutex, UInt32 timeout);
|
bool Wait(Mutex* mutex, UInt32 timeout);
|
||||||
|
|
||||||
ConditionVariable& operator=(const ConditionVariable&) = delete;
|
ConditionVariable& operator=(const ConditionVariable&) = delete;
|
||||||
ConditionVariable& operator=(ConditionVariable&&) = delete; ///TODO
|
inline ConditionVariable& operator=(ConditionVariable&& condition) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConditionVariableImpl* m_impl;
|
ConditionVariableImpl* m_impl;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/ConditionVariable.inl>
|
||||||
|
|
||||||
#endif // NAZARA_CONDITIONVARIABLE_HPP
|
#endif // NAZARA_CONDITIONVARIABLE_HPP
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Core/ConditionVariable.hpp>
|
||||||
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* \class Nz::ConditionVariable
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Constructs a ConditionVariable object by moving another one
|
||||||
|
*/
|
||||||
|
inline ConditionVariable::ConditionVariable(ConditionVariable&& condition) noexcept :
|
||||||
|
m_impl(condition.m_impl)
|
||||||
|
{
|
||||||
|
condition.m_impl = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/DebugOff.hpp>
|
||||||
|
|
@ -20,7 +20,7 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
Mutex();
|
Mutex();
|
||||||
Mutex(const Mutex&) = delete;
|
Mutex(const Mutex&) = delete;
|
||||||
Mutex(Mutex&&) = delete; ///TODO
|
inline Mutex(Mutex&& mutex) noexcept;
|
||||||
~Mutex();
|
~Mutex();
|
||||||
|
|
||||||
void Lock();
|
void Lock();
|
||||||
|
|
@ -28,11 +28,13 @@ namespace Nz
|
||||||
void Unlock();
|
void Unlock();
|
||||||
|
|
||||||
Mutex& operator=(const Mutex&) = delete;
|
Mutex& operator=(const Mutex&) = delete;
|
||||||
Mutex& operator=(Mutex&&) = delete; ///TODO
|
Mutex& operator=(Mutex&& mutex) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MutexImpl* m_impl;
|
MutexImpl* m_impl;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/Mutex.inl>
|
||||||
|
|
||||||
#endif // NAZARA_MUTEX_HPP
|
#endif // NAZARA_MUTEX_HPP
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Core/Mutex.hpp>
|
||||||
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* \class Nz::Mutex
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Constructs a Mutex object by moving another one
|
||||||
|
*/
|
||||||
|
inline Mutex::Mutex(Mutex&& mutex) noexcept :
|
||||||
|
m_impl(mutex.m_impl)
|
||||||
|
{
|
||||||
|
mutex.m_impl = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/DebugOff.hpp>
|
||||||
|
|
@ -101,4 +101,18 @@ namespace Nz
|
||||||
NazaraAssert(mutex != nullptr, "Mutex must be valid");
|
NazaraAssert(mutex != nullptr, "Mutex must be valid");
|
||||||
return m_impl->Wait(mutex->m_impl, timeout);
|
return m_impl->Wait(mutex->m_impl, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Moves a condition to another ConditionVariable object
|
||||||
|
* \return A reference to the object
|
||||||
|
*/
|
||||||
|
ConditionVariable& ConditionVariable::operator=(ConditionVariable&& condition) noexcept
|
||||||
|
{
|
||||||
|
delete m_impl;
|
||||||
|
|
||||||
|
m_impl = condition.m_impl;
|
||||||
|
condition.m_impl = nullptr;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Core/Mutex.hpp>
|
#include <Nazara/Core/Mutex.hpp>
|
||||||
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
|
||||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||||
#include <Nazara/Core/Win32/MutexImpl.hpp>
|
#include <Nazara/Core/Win32/MutexImpl.hpp>
|
||||||
|
|
@ -49,6 +50,7 @@ namespace Nz
|
||||||
|
|
||||||
void Mutex::Lock()
|
void Mutex::Lock()
|
||||||
{
|
{
|
||||||
|
NazaraAssert(m_impl, "Cannot lock a moved mutex");
|
||||||
m_impl->Lock();
|
m_impl->Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,6 +61,7 @@ namespace Nz
|
||||||
|
|
||||||
bool Mutex::TryLock()
|
bool Mutex::TryLock()
|
||||||
{
|
{
|
||||||
|
NazaraAssert(m_impl, "Cannot lock a moved mutex");
|
||||||
return m_impl->TryLock();
|
return m_impl->TryLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,6 +73,21 @@ namespace Nz
|
||||||
|
|
||||||
void Mutex::Unlock()
|
void Mutex::Unlock()
|
||||||
{
|
{
|
||||||
|
NazaraAssert(m_impl, "Cannot unlock a moved mutex");
|
||||||
m_impl->Unlock();
|
m_impl->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Moves a mutex to another mutex object
|
||||||
|
* \return A reference to the object
|
||||||
|
*/
|
||||||
|
Mutex& Mutex::operator=(Mutex&& mutex) noexcept
|
||||||
|
{
|
||||||
|
delete m_impl;
|
||||||
|
|
||||||
|
m_impl = mutex.m_impl;
|
||||||
|
mutex.m_impl = nullptr;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue