vsg  1.1.0
VulkanSceneGraph library
FrameBlock.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/threading/ActivityStatus.h>
16 #include <vsg/ui/ApplicationEvent.h>
17 
18 namespace vsg
19 {
20 
22  class FrameBlock : public Inherit<Object, FrameBlock>
23  {
24  public:
25  inline static const ref_ptr<FrameStamp> initial_value = {};
26 
27  explicit FrameBlock(ref_ptr<ActivityStatus> status) :
28  _value(initial_value),
29  _status(status) {}
30 
31  FrameBlock(const FrameBlock&) = delete;
32  FrameBlock& operator=(const FrameBlock&) = delete;
33 
34  void set(ref_ptr<FrameStamp> frameStamp)
35  {
36  std::scoped_lock lock(_mutex);
37  _value = frameStamp;
38  _cv.notify_all();
39  }
40 
42  {
43  std::scoped_lock lock(_mutex);
44  return _value;
45  }
46 
47  bool active() const { return _status->active(); }
48 
49  void wake()
50  {
51  std::scoped_lock lock(_mutex);
52  _cv.notify_all();
53  }
54 
55  bool wait_for_change(ref_ptr<FrameStamp>& value)
56  {
57  std::unique_lock lock(_mutex);
58  while (_value == value && _status->active())
59  {
60  _cv.wait(lock);
61  }
62 
63  value = _value;
64  return _status->active();
65  }
66 
67  protected:
68  virtual ~FrameBlock() {}
69 
70  std::mutex _mutex;
71  std::condition_variable _cv;
72  ref_ptr<FrameStamp> _value;
74  };
75  VSG_type_name(vsg::FrameBlock);
76 
77 } // namespace vsg
FrameBlock provides a mechanism for synchronizing threads that are waiting on the start of a new fram...
Definition: FrameBlock.h:23
Definition: Inherit.h:28
Definition: ref_ptr.h:22