SPAOP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Thread.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Martin Hansen
3  *
4  * This file is part of SPAOP (Spatial Audio Object Positioner).
5  *
6  * SPAOP is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * SPAOP is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with SPAOP. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 #ifndef THREAD_H_INCLUDED
22 #define THREAD_H_INCLUDED
23 
24 #include <thread>
25 #include <mutex>
26 
32 namespace thread {
33 
39 class Thread
40 {
41 public:
42 
44  Thread();
45 
47  virtual ~Thread();
48 
55  void start();
56 
58  void stop();
59 
61  void join();
62 
63 protected:
64 
70  virtual void run()=0;
71 
75  bool isStopped() const;
76 
77 private:
78 
84  static void threadFunction(Thread* thisThread);
85 
86  Thread(const Thread& other); // copying not allowed
87 
88  std::thread thread_; // the thread
89  bool running_; // flag: is running
90  bool stopped_; // flag: is stopped
91  mutable std::mutex runningMutex_; // guards the running_ flag
92 };
93 
94 }
95 
96 #endif // THREAD_H_INCLUDED
virtual void run()=0
This is the method that will be executed by the thread.
bool isStopped() const
Returns true if the thread was stopped.
Definition: Thread.cpp:61
void join()
Joins the thread.
Definition: Thread.cpp:56
Thread()
Constructor.
Definition: Thread.cpp:25
void start()
Starts the Thread.
Definition: Thread.cpp:37
virtual ~Thread()
Destructor.
Definition: Thread.cpp:33
A wrapper for the std::thread wrapping it into a Java-style thread object.
Definition: Thread.h:39
void stop()
Sets the internal flag stopped_ to true.
Definition: Thread.cpp:51