| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

locking_ptr.hpp
Go to the documentation of this file.
1
21 #ifndef THREADPOOL_DETAIL_LOCKING_PTR_HPP_INCLUDED
22 #define THREADPOOL_DETAIL_LOCKING_PTR_HPP_INCLUDED
23
24 #include <boost/utility.hpp>
25 #include <boost/thread/mutex.hpp>
26
27
28 namespace boost { namespace threadpool { namespace detail
29 {
30
36 template <typename T, typename Mutex>
37 class locking_ptr
38 : private noncopyable
39 {
40 T* m_obj;
41 Mutex & m_mutex;
42
43 public:
45 locking_ptr(volatile T& obj, const volatile Mutex& mtx)
46 : m_obj(const_cast<T*>(&obj))
47 , m_mutex(*const_cast<Mutex*>(&mtx))
48 {
49 // Lock mutex
50 m_mutex.lock();
51 }
52
53
55 ~locking_ptr()
56 {
57 // Unlock mutex
58 m_mutex.unlock();
59 }
60
61
65 T& operator*() const
66 {
67 return *m_obj;
68 }
69
70
74 T* operator->() const
75 {
76 return m_obj;
77 }
78 };
79
80
81 } } } // namespace boost::threadpool::detail
82
83
84 #endif // THREADPOOL_DETAIL_LOCKING_PTR_HPP_INCLUDED
85
boost
The namespace threadpool contains a thread pool and related utility classes.
Definition: iter_pos.hpp:13
boost::threadpool::detail::locking_ptr
Smart pointer with a scoped locking mechanism.
Definition: locking_ptr.hpp:37
detail
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
boost::threadpool::detail::locking_ptr::~locking_ptr
~locking_ptr()
Destructor.
Definition: locking_ptr.hpp:55
boost::threadpool::detail::locking_ptr::operator->
T * operator->() const
Returns a pointer to the stored instance.
Definition: locking_ptr.hpp:74
boost::threadpool::detail::locking_ptr::m_mutex
Mutex & m_mutex
Mutex is used for scoped locking.
Definition: locking_ptr.hpp:41
boost::threadpool::detail::locking_ptr::locking_ptr
locking_ptr(volatile T &obj, const volatile Mutex &mtx)
Constructor.
Definition: locking_ptr.hpp:45
boost::threadpool::detail::locking_ptr::operator*
T & operator*() const
Returns a reference to the stored instance.
Definition: locking_ptr.hpp:65
boost::threadpool::detail::locking_ptr::m_obj
T * m_obj
The instance pointer.
Definition: locking_ptr.hpp:40