Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Thread.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_THREAD_HPP
8 #define NAZARA_THREAD_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/Functor.hpp>
12 #include <Nazara/Core/MovablePtr.hpp>
13 #include <iosfwd>
14 
15 namespace Nz
16 {
17  class String;
18  class ThreadImpl;
19 
20  class NAZARA_CORE_API Thread
21  {
22  public:
23  class Id;
24 
25  Thread();
26  template<typename F> Thread(F function);
27  template<typename F, typename... Args> Thread(F function, Args&&... args);
28  template<typename C> Thread(void (C::*function)(), C* object);
29  Thread(const Thread&) = delete;
30  Thread(Thread&& other) noexcept = default;
31  ~Thread();
32 
33  void Detach();
34  Id GetId() const;
35  bool IsJoinable() const;
36  void Join();
37  void SetName(const String& name);
38 
39  Thread& operator=(const Thread&) = delete;
40  Thread& operator=(Thread&& thread) noexcept = default;
41 
42  static unsigned int HardwareConcurrency();
43  static void SetCurrentThreadName(const String& name);
44  static void Sleep(UInt32 milliseconds);
45 
46  private:
47  void CreateImpl(Functor* functor);
48 
50  };
51 
52  class NAZARA_CORE_API Thread::Id
53  {
54  friend Thread;
55 
56  public:
57  NAZARA_CORE_API friend bool operator==(const Id& lhs, const Id& rhs);
58  NAZARA_CORE_API friend bool operator!=(const Id& lhs, const Id& rhs);
59  NAZARA_CORE_API friend bool operator<(const Id& lhs, const Id& rhs);
60  NAZARA_CORE_API friend bool operator<=(const Id& lhs, const Id& rhs);
61  NAZARA_CORE_API friend bool operator>(const Id& lhs, const Id& rhs);
62  NAZARA_CORE_API friend bool operator>=(const Id& lhs, const Id& rhs);
63 
64  NAZARA_CORE_API friend std::ostream& operator<<(std::ostream& o, const Id& id);
65 
66  private:
67  Id(ThreadImpl* thread);
68 
69  ThreadImpl* m_id = nullptr;
70  };
71 }
72 
73 #include <Nazara/Core/Thread.inl>
74 
75 #endif // NAZARA_THREAD_HPP
Core class that represents a thread.
Definition: Thread.hpp:20
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
bool operator<(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1517
bool operator>(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1566
Core class that represents a string.
Definition: String.hpp:22
bool operator!=(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1503
bool operator==(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1469
bool operator>=(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1580
bool operator<=(const Bitset< Block, Allocator > &lhs, const Nz::Bitset< Block, Allocator > &rhs)
Compares two bitsets.
Definition: Bitset.inl:1552