The Gaudi Framework  v29r0 (ff2e7097)
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 
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 
The namespace threadpool contains a thread pool and related utility classes.
Definition: iter_pos.hpp:13
Smart pointer with a scoped locking mechanism.
Definition: locking_ptr.hpp:37
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
T * operator->() const
Returns a pointer to the stored instance.
Definition: locking_ptr.hpp:74
Mutex & m_mutex
Mutex is used for scoped locking.
Definition: locking_ptr.hpp:41
locking_ptr(volatile T &obj, const volatile Mutex &mtx)
Constructor.
Definition: locking_ptr.hpp:45
T & operator*() const
Returns a reference to the stored instance.
Definition: locking_ptr.hpp:65
T * m_obj
The instance pointer.
Definition: locking_ptr.hpp:40