Go to the documentation of this file.00001
00021 #ifndef THREADPOOL_DETAIL_LOCKING_PTR_HPP_INCLUDED
00022 #define THREADPOOL_DETAIL_LOCKING_PTR_HPP_INCLUDED
00023
00024 #include <boost/utility.hpp>
00025 #include <boost/thread/mutex.hpp>
00026
00027
00028 namespace boost { namespace threadpool { namespace detail
00029 {
00030
00036 template <typename T, typename Mutex>
00037 class locking_ptr
00038 : private noncopyable
00039 {
00040 T* m_obj;
00041 Mutex & m_mutex;
00042
00043 public:
00045 locking_ptr(volatile T& obj, const volatile Mutex& mtx)
00046 : m_obj(const_cast<T*>(&obj))
00047 , m_mutex(*const_cast<Mutex*>(&mtx))
00048 {
00049
00050 m_mutex.lock();
00051 }
00052
00053
00055 ~locking_ptr()
00056 {
00057
00058 m_mutex.unlock();
00059 }
00060
00061
00065 T& operator*() const
00066 {
00067 return *m_obj;
00068 }
00069
00070
00074 T* operator->() const
00075 {
00076 return m_obj;
00077 }
00078 };
00079
00080
00081 } } }
00082
00083
00084 #endif // THREADPOOL_DETAIL_LOCKING_PTR_HPP_INCLUDED
00085