Argentum Online - Servidor
thread.h
1 #ifndef __THREAD_H__
2 #define __THREAD_H__
3 
4 #include <unistd.h>
5 
6 #include <chrono>
7 #include <thread>
8 
9 class Thread {
10  private:
11  bool runing;
12  std::thread thread;
13 
14  public:
19  Thread();
20 
21  Thread(const Thread&) = delete;
22  Thread& operator=(const Thread&) = delete;
23 
29  Thread(Thread&& other);
30  virtual Thread& operator=(Thread&& other);
31 
36  void operator()();
37 
42  void start();
43 
48  virtual void join();
49 
55  void usleep(unsigned int us);
56 
64  template <class Rep, class Period>
65  void sleep(const std::chrono::duration<Rep, Period>& duration) {
66  std::this_thread::sleep_for(duration);
67  }
68 
73  virtual void run() = 0;
74 
79  virtual ~Thread();
80 };
81 
82 #endif //__THREAD_H__
Thread::run
virtual void run()=0
Function to be called by the thread.
Thread::join
virtual void join()
Join the thread.
Definition: thread.cpp:23
Thread::start
void start()
Start the thread.
Definition: thread.cpp:16
Thread::~Thread
virtual ~Thread()
Deletes safely the thread, if it not joined, join()
Definition: thread.cpp:45
Thread::usleep
void usleep(unsigned int us)
Sleeps for value in micro-seconds.
Definition: thread.cpp:28
Thread::operator()
void operator()()
Thread as a functor, same as start().
Definition: thread.cpp:12
Thread::sleep
void sleep(const std::chrono::duration< Rep, Period > &duration)
Wrapper of std::this_thread::sleep_for.
Definition: thread.h:65
Thread::Thread
Thread()
Construct a new Thread object.
Definition: thread.cpp:10
Thread
Definition: thread.h:9