DSPatch  v.6.01
AutoTickThread.h
1 /************************************************************************
2 DSPatch - The Refreshingly Simple C++ Dataflow Framework
3 Copyright (c) 2012-2019 Marcus Tomlinson
4 
5 This file is part of DSPatch.
6 
7 GNU Lesser General Public License Usage
8 This file may be used under the terms of the GNU Lesser General Public
9 License version 3.0 as published by the Free Software Foundation and
10 appearing in the file LICENSE included in the packaging of this file.
11 Please review the following information to ensure the GNU Lesser
12 General Public License version 3.0 requirements will be met:
13 http://www.gnu.org/copyleft/lgpl.html.
14 
15 Other Usage
16 Alternatively, this file may be used in accordance with the terms and
17 conditions contained in a signed written agreement between you and
18 Marcus Tomlinson.
19 
20 DSPatch is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 ************************************************************************/
24 
25 #pragma once
26 
27 #include <dspatch/Circuit.h>
28 #include <dspatch/Common.h>
29 
30 #include <condition_variable>
31 #include <thread>
32 
33 namespace DSPatch
34 {
35 namespace internal
36 {
37 
39 
47 class AutoTickThread final
48 {
49 public:
50  NONCOPYABLE( AutoTickThread );
51  DEFINE_PTRS( AutoTickThread );
52 
54  ~AutoTickThread();
55 
56  DSPatch::Component::TickMode Mode();
57 
58  bool IsStopped() const;
59  bool IsPaused() const;
60 
61  void Start( DSPatch::Circuit* circuit, DSPatch::Component::TickMode mode );
62  void Stop();
63  void Pause();
64  void Resume();
65 
66 private:
67  void _Run();
68 
69 private:
70  DSPatch::Component::TickMode _mode;
71  std::thread _thread;
72  DSPatch::Circuit* _circuit = nullptr;
73  bool _stop = false;
74  bool _pause = false;
75  bool _stopped = true;
76  std::mutex _resumeMutex;
77  std::condition_variable _resumeCondt, _pauseCondt;
78 };
79 
80 } // namespace internal
81 } // namespace DSPatch
Workspace for adding and routing components.
Definition: Circuit.h:56
Thread class for auto-ticking a circuit.