rmw_fastrtps_shared_cpp  master
Code shared on static and dynamic type support of rmw_fastrtps_cpp.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
locked_object.hpp
Go to the documentation of this file.
1 // Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RMW_FASTRTPS_SHARED_CPP__LOCKED_OBJECT_HPP_
16 #define RMW_FASTRTPS_SHARED_CPP__LOCKED_OBJECT_HPP_
17 
18 #include <mutex>
19 
21 
22 template<class T>
24 {
25 private:
26  mutable std::mutex mutex_;
27  T object_ RCPPUTILS_TSA_GUARDED_BY(mutex_);
28 
29 public:
33  std::mutex & getMutex() const RCPPUTILS_TSA_RETURN_CAPABILITY(mutex_)
34  {
35  return mutex_;
36  }
37 
38  T & operator()()
39  {
40  return object_;
41  }
42 
43  const T & operator()() const
44  {
45  return object_;
46  }
47 };
48 
49 #endif // RMW_FASTRTPS_SHARED_CPP__LOCKED_OBJECT_HPP_
LockedObject::getMutex
std::mutex & getMutex() const RCPPUTILS_TSA_RETURN_CAPABILITY(mutex_)
Definition: locked_object.hpp:33
LockedObject::operator()
const T & operator()() const
Definition: locked_object.hpp:43
LockedObject::operator()
T & operator()()
Definition: locked_object.hpp:38
LockedObject
Definition: locked_object.hpp:23
thread_safety_annotations.hpp
std::mutex