Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::testable_mutex< Lockable > Class Template Reference

Based on Associate Mutexes with Data to Prevent Races, By Herb Sutter, May 13, 2010 http://www.drdobbs.com/windows/associate-mutexes-with-data-to-prevent-r/224701827?pgno=3. More...

#include <testable_mutex.hpp>

Public Types

typedef Lockable lockable_type
 the type of the wrapped lockable More...
 

Public Member Functions

 testable_mutex ()
 Non copyable. More...
 
void lock ()
 
void unlock ()
 
bool try_lock ()
 
bool is_locked_by_this_thread () const
 
bool is_locked () const
 
thread::id get_id () const
 

Detailed Description

template<typename Lockable>
class boost::testable_mutex< Lockable >

Based on Associate Mutexes with Data to Prevent Races, By Herb Sutter, May 13, 2010 http://www.drdobbs.com/windows/associate-mutexes-with-data-to-prevent-r/224701827?pgno=3.

Make our mutex testable if it isn't already.

Many mutex services (including boost::mutex) don't provide a way to ask, "Do I already hold a lock on this mutex?" Sometimes it is needed to know if a method like is_locked to be available. This wrapper associates an arbitrary lockable type with a thread id that stores the ID of the thread that currently holds the lockable. The thread id initially holds an invalid value that means no threads own the mutex. When we acquire a lock, we set the thread id; and when we release a lock, we reset it back to its default no id state.

Member Typedef Documentation

template<typename Lockable>
typedef Lockable boost::testable_mutex< Lockable >::lockable_type

the type of the wrapped lockable

Constructor & Destructor Documentation

template<typename Lockable>
boost::testable_mutex< Lockable >::testable_mutex ( )
inline

Non copyable.

Member Function Documentation

template<typename Lockable>
thread::id boost::testable_mutex< Lockable >::get_id ( ) const
inline
template<typename Lockable>
bool boost::testable_mutex< Lockable >::is_locked ( ) const
inline
template<typename Lockable>
void boost::testable_mutex< Lockable >::lock ( void  )
inline
template<typename Lockable>
bool boost::testable_mutex< Lockable >::try_lock ( void  )
inline
template<typename Lockable>
void boost::testable_mutex< Lockable >::unlock ( void  )
inline

The documentation for this class was generated from the following files: