Sha256: 11cb2c6e4bce336cf94a9c754bbf3ce1678879633ed3e8e97b159ef6d3025268

Contents?: true

Size: 1.65 KB

Versions: 86

Compression:

Stored size: 1.65 KB

Contents

// Copyright (C) 2000 Stephen Cleary
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org for updates, documentation, and revision history.

#ifndef BOOST_POOL_GUARD_HPP
#define BOOST_POOL_GUARD_HPP

/*!
  \file
  \brief Extremely Light-Weight guard class.
  \details Auto-lock/unlock-er
  detail/guard.hpp provides a type guard<Mutex>
  that allows scoped access to the Mutex's locking and unlocking operations.
  It is used to ensure that a Mutex is unlocked, even if an exception is thrown.
*/

namespace boost {

namespace details {
namespace pool {

template <typename Mutex> //!< \tparam Mutex (platform-specific) mutex class.
class guard
{ //! Locks the mutex, binding guard<Mutex> to Mutex.
	/*! Example:
	Given a (platform-specific) mutex class, we can wrap code as follows:

	extern mutex global_lock;

	static void f()
	{
		boost::details::pool::guard<mutex> g(global_lock);
		// g's constructor locks "global_lock"

		... // do anything:
				//   throw exceptions
				//   return
				//   or just fall through
	} // g's destructor unlocks "global_lock"
	*/
  private:
    Mutex & mtx;

    guard(const guard &); //!< Guards the mutex, ensuring unlocked on destruction, even if exception is thrown.
    void operator=(const guard &);

  public:
    explicit guard(Mutex & nmtx)
    :mtx(nmtx)
    { //! Locks the mutex of the guard class.
			mtx.lock();
		}

    ~guard()
    { //! destructor unlocks the mutex of the guard class.
			mtx.unlock();
		}
}; // class guard

} // namespace pool
} // namespace details

} // namespace boost

#endif

Version data entries

86 entries across 86 versions & 3 rubygems

Version Path
passenger-6.0.26 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.25 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.24 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.23 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.20 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.19 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.18 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.17 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.16 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.15 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.14 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.13 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.12 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.11 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.10 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.9 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.8 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.7 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.6 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp
passenger-6.0.5 src/cxx_supportlib/vendor-modified/boost/pool/detail/guard.hpp