1 // Copyright (C) 2000 Stephen Cleary
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org for updates, documentation, and revision history.
9 #ifndef BOOST_POOL_GUARD_HPP
10 #define BOOST_POOL_GUARD_HPP
14 \brief Extremely Light-Weight guard class.
15 \details Auto-lock/unlock-er
16 detail/guard.hpp provides a type guard<Mutex>
17 that allows scoped access to the Mutex's locking and unlocking operations.
18 It is used to ensure that a Mutex is unlocked, even if an exception is thrown.
26 template <typename Mutex> //!< \tparam Mutex (platform-specific) mutex class.
28 { //! Locks the mutex, binding guard<Mutex> to Mutex.
30 Given a (platform-specific) mutex class, we can wrap code as follows:
32 extern mutex global_lock;
36 boost::details::pool::guard<mutex> g(global_lock);
37 // g's constructor locks "global_lock"
42 // or just fall through
43 } // g's destructor unlocks "global_lock"
48 guard(const guard &); //!< Guards the mutex, ensuring unlocked on destruction, even if exception is thrown.
49 void operator=(const guard &);
52 explicit guard(Mutex & nmtx)
54 { //! Locks the mutex of the guard class.
59 { //! destructor unlocks the mutex of the guard class.
65 } // namespace details