opensurgsim
Clock.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_FRAMEWORK_CLOCK_H
17 #define SURGSIM_FRAMEWORK_CLOCK_H
18 
19 #include <boost/chrono.hpp>
20 #include <boost/thread.hpp>
21 
24 
25 
26 namespace SurgSim
27 {
28 namespace Framework
29 {
30 
32 typedef boost::chrono::high_resolution_clock Clock;
33 
38 template <class C, class D>
39 void sleep_until(const boost::chrono::time_point<C, D>& time)
40 {
41  // 2ms gives good results on windows and linux
42  static const boost::chrono::duration<double> schedulerError(0.002);
43 
44  boost::chrono::time_point<C, D> earlierTime = time - schedulerError;
45  if (earlierTime > C::now())
46  {
47  boost::this_thread::sleep_until(earlierTime);
48  }
49 
50  while (C::now() < time)
51  {
52  boost::this_thread::yield();
53  }
54 }
55 
56 }; // Framework
57 }; // SurgSim
58 
59 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
void sleep_until(const boost::chrono::time_point< C, D > &time)
A more accurate sleep_until that accounts for scheduler errors.
Definition: Clock.h:39
boost::chrono::high_resolution_clock Clock
Wraps around the actual clock we are using.
Definition: Clock.h:32