OSVR-Core
RunLoopManagerBoost.h
Go to the documentation of this file.
1 
25 // Copyright Iowa State University 2013.
26 // Distributed under the Boost Software License, Version 1.0.
27 // (See accompanying file LICENSE_1_0.txt or copy at
28 // http://www.boost.org/LICENSE_1_0.txt)
29 
30 #ifndef INCLUDED_RunLoopManagerBoost_h_GUID_50f7b2f1_493e_4395_25ca_df2f010a34bd
31 #define INCLUDED_RunLoopManagerBoost_h_GUID_50f7b2f1_493e_4395_25ca_df2f010a34bd
32 
33 // Internal Includes
34 #include "RunLoopManager.h"
35 
36 // Library/third-party includes
37 #include <boost/thread.hpp>
38 
39 // Standard includes
40 // - none
41 
42 namespace util {
43 
45  public:
46  RunLoopManagerBoost() : currentState_(STATE_STOPPED) {}
47 
50  void signalStart();
51  void signalAndWaitForStart();
53 
56  void signalShutdown();
59 
60  private:
61  void reportStateChange_(RunningState s);
62  boost::mutex mut_;
63  boost::condition_variable stateCond_;
64 
65  typedef boost::unique_lock<boost::mutex> Lock;
66 
68  volatile RunningState currentState_;
69  };
70 
71  inline void RunLoopManagerBoost::signalStart() {
72  Lock condGuard(mut_);
73  setShouldStop_(false);
74  }
75 
77  signalStart();
78  {
79  Lock condGuard(mut_);
80  while (currentState_ != STATE_RUNNING) {
81  stateCond_.wait(condGuard);
82  }
83  }
84  }
85 
86  inline void RunLoopManagerBoost::signalShutdown() {
87  Lock condGuard(mut_);
88  setShouldStop_(true);
89  }
90 
92  Lock condGuard(mut_);
93  setShouldStop_(true);
94 
95  while (currentState_ != STATE_STOPPED) {
96  stateCond_.wait(condGuard);
97  }
98  }
99 
100  inline void
101  RunLoopManagerBoost::reportStateChange_(RunLoopManagerBase::RunningState s) {
102  {
103  Lock condGuard(mut_);
104  currentState_ = s;
105  }
106  stateCond_.notify_all();
107  }
108 
109 } // end of namespace util
110 
111 #endif // INCLUDED_RunLoopManagerBoost_h_GUID_50f7b2f1_493e_4395_25ca_df2f010a34bd
Definition: RunLoopManager.h:42
Base class for implementations of a RunLoopManager that use various synchronization libraries...
Definition: RunLoopManager.h:65
void signalAndWaitForShutdown()
Send a message to the run loop that it should stop, and wait until it does.
Definition: RunLoopManagerBoost.h:91
void signalAndWaitForStart()
Set up for run loop to start, then block until we have confirmation that the run loop is running...
Definition: RunLoopManagerBoost.h:76
void setShouldStop_(bool value)
internal utility function.
Definition: RunLoopManager.h:143
Definition: RunLoopManagerBoost.h:44