Made NzThread interface mimic std::thread one
Hopefully fixed the threaded window bug Former-commit-id: 6dc3ca2a8bee1da591a9b97d202d4b73b10be8eb
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// Inspiré du code de la SFML par Laurent Gomila
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_THREAD_HPP
|
||||
@@ -12,53 +10,56 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Functor.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <ostream>
|
||||
|
||||
class NzThreadImpl;
|
||||
|
||||
class NAZARA_API NzThread : NzNonCopyable
|
||||
{
|
||||
friend NzThreadImpl;
|
||||
|
||||
public:
|
||||
class NAZARA_API Id
|
||||
{
|
||||
friend NzThread;
|
||||
friend NzThreadImpl;
|
||||
|
||||
public:
|
||||
Id() = default;
|
||||
Id(Id&& rhs) = default;
|
||||
~Id();
|
||||
|
||||
Id& operator=(Id&& rhs) = default;
|
||||
bool operator==(const Id& rhs) const;
|
||||
bool operator!=(const Id& rhs) const;
|
||||
NAZARA_API friend bool operator==(const Id& lhs, const Id& rhs);
|
||||
NAZARA_API friend bool operator!=(const Id& lhs, const Id& rhs);
|
||||
NAZARA_API friend bool operator<(const Id& lhs, const Id& rhs);
|
||||
NAZARA_API friend bool operator<=(const Id& lhs, const Id& rhs);
|
||||
NAZARA_API friend bool operator>(const Id& lhs, const Id& rhs);
|
||||
NAZARA_API friend bool operator>=(const Id& lhs, const Id& rhs);
|
||||
|
||||
NAZARA_API friend bool operator<<(std::ostream& o, const Id& id);
|
||||
|
||||
private:
|
||||
Id(void* handle) : m_handle(handle) {}
|
||||
Id(const NzThreadImpl* thread);
|
||||
Id(NzThreadImpl* thread);
|
||||
|
||||
void* m_handle = nullptr;
|
||||
NzThreadImpl* m_id = nullptr;
|
||||
};
|
||||
|
||||
NzThread() = default;
|
||||
NzThread(NzThread&& other);
|
||||
template<typename F> NzThread(F function);
|
||||
template<typename F, typename... Args> NzThread(F function, Args... args);
|
||||
template<typename C> NzThread(void (C::*function)(), C* object);
|
||||
~NzThread();
|
||||
|
||||
void Detach();
|
||||
Id GetId() const;
|
||||
bool IsCurrent() const;
|
||||
void Launch(bool independent = false);
|
||||
bool IsJoinable() const;
|
||||
void Join();
|
||||
void Terminate();
|
||||
|
||||
static Id GetCurrentId();
|
||||
static void Sleep(nzUInt32 time);
|
||||
NzThread& operator=(NzThread&& thread);
|
||||
|
||||
static unsigned int HardwareConcurrency();
|
||||
static void Sleep(nzUInt32 milliseconds);
|
||||
|
||||
private:
|
||||
NzFunctor* m_func;
|
||||
void CreateImpl(NzFunctor* functor);
|
||||
|
||||
NzThreadImpl* m_impl = nullptr;
|
||||
bool m_independent;
|
||||
};
|
||||
|
||||
#include <Nazara/Core/Thread.inl>
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
template<typename F>
|
||||
NzThread::NzThread(F function) :
|
||||
m_func(new NzFunctorWithoutArgs<F>(function))
|
||||
NzThread::NzThread(F function)
|
||||
{
|
||||
CreateImpl(new NzFunctorWithoutArgs<F>(function));
|
||||
}
|
||||
|
||||
template<typename F, typename... Args>
|
||||
NzThread::NzThread(F function, Args... args) :
|
||||
m_func(new NzFunctorWithArgs<F, Args...>(function, args...))
|
||||
NzThread::NzThread(F function, Args... args)
|
||||
{
|
||||
CreateImpl(new NzFunctorWithArgs<F, Args...>(function, args...));
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
NzThread::NzThread(void (C::*function)(), C* object) :
|
||||
m_func(new NzMemberWithoutArgs<C>(function, object))
|
||||
NzThread::NzThread(void (C::*function)(), C* object)
|
||||
{
|
||||
CreateImpl(new NzMemberWithoutArgs<C>(function, object));
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#define NAZARA_UTILITY_STRICT_RESOURCE_PARSING 1
|
||||
|
||||
// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte
|
||||
#define NAZARA_UTILITY_THREADED_WINDOW 0 ///FIXME: Buggé depuis GCC 4.7 avec certains ordinateurs
|
||||
#define NAZARA_UTILITY_THREADED_WINDOW 0
|
||||
|
||||
// Protège les classes des accès concurrentiels
|
||||
#define NAZARA_UTILITY_THREADSAFE 1
|
||||
|
||||
Reference in New Issue
Block a user