DSPatch  v.6.01
CircuitThread.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/Component.h>
28 
29 #include <condition_variable>
30 #include <thread>
31 
32 namespace DSPatch
33 {
34 namespace internal
35 {
36 
38 
57 class CircuitThread final
58 {
59 public:
60  NONCOPYABLE( CircuitThread );
61  DEFINE_PTRS( CircuitThread );
62 
63  CircuitThread();
64  ~CircuitThread();
65 
66  void Start( std::vector<DSPatch::Component::SPtr>* components, int threadNo );
67  void Stop();
68  void Sync();
69  void SyncAndResume( DSPatch::Component::TickMode mode );
70 
71 private:
72  void _Run();
73 
74 private:
75  DSPatch::Component::TickMode _mode;
76  std::thread _thread;
77  std::vector<DSPatch::Component::SPtr>* _components = nullptr;
78  int _threadNo = 0;
79  bool _stop = false;
80  bool _stopped = true;
81  bool _gotResume = false;
82  bool _gotSync = true;
83  std::mutex _resumeMutex;
84  std::condition_variable _resumeCondt, _syncCondt;
85 };
86 
87 } // namespace internal
88 } // namespace DSPatch
Thread class for asynchronously ticking circuit components.
Definition: CircuitThread.h:57