opensurgsim
BufferedValue-inl.h
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_DATASTRUCTURES_BUFFEREDVALUE_INL_H
17 #define SURGSIM_DATASTRUCTURES_BUFFEREDVALUE_INL_H
18 
19 namespace SurgSim
20 {
21 namespace DataStructures
22 {
23 
24 template <class T>
25 BufferedValue<T>::BufferedValue()
26 {
27  m_safeValue = std::make_shared<const T>();
28 }
29 
30 template <class T>
32  m_value(value)
33 {
34  m_safeValue = std::make_shared<const T>(m_value);
35 }
36 
37 template <class T>
39 {
40 }
41 
42 template <class T>
44 {
45  auto newSafeValue = std::make_shared<const T>(m_value);
46  {
47  UniqueLock lock(m_mutex);
48  std::swap(newSafeValue, m_safeValue);
49  }
50 }
51 
52 template <class T>
54 {
55  return m_value;
56 }
57 
58 template <class T>
59 std::shared_ptr<const T> BufferedValue<T>::safeGet() const
60 {
61  SharedLock lock(m_mutex);
62  return m_safeValue;
63 }
64 
65 } // DataStructures
66 } // SurgSim
67 
68 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
BufferedValue is a class to enable a representation of two values for one variable, where both values need to be accessible at the same time, one in a thread safe, single threaded context, the other in a thread unsafe context.
Definition: BufferedValue.h:33