/usr/include/vtk-7.1/vtkdiy/critical-resource.hpp is in libvtk7-dev 7.1.1+dfsg1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #ifndef DIY_CRITICAL_RESOURCE_HPP
#define DIY_CRITICAL_RESOURCE_HPP
namespace diy
{
// TODO: when not running under C++11, i.e., when lock_guard is TinyThread's
// lock_guard, and not C++11's unique_lock, this implementation might
// be buggy since the copy constructor is invoked when
// critical_resource::access() returns an instance of this class. Once
// the temporary is destroyed the mutex is unlocked. I'm not 100%
// certain of this because I'd expect a deadlock on copy constructor,
// but it's clearly not happening -- so I may be missing something.
// (This issue will take care of itself in DIY3 once we switch to C++11 completely.)
template<class T, class Mutex>
class resource_accessor
{
public:
resource_accessor(T& x, Mutex& m):
x_(x), lock_(m) {}
T& operator*() { return x_; }
T* operator->() { return &x_; }
const T& operator*() const { return x_; }
const T* operator->() const { return &x_; }
private:
T& x_;
lock_guard<Mutex> lock_;
};
template<class T, class Mutex = fast_mutex>
class critical_resource
{
public:
typedef resource_accessor<T, Mutex> accessor;
typedef resource_accessor<const T, Mutex> const_accessor; // eventually, try shared locking
public:
critical_resource() {}
critical_resource(const T& x):
x_(x) {}
accessor access() { return accessor(x_, m_); }
const_accessor const_access() const { return const_accessor(x_, m_); }
private:
T x_;
mutable Mutex m_;
};
}
#endif
|