Documentation Home >> Headers >> <jss/guards.hpp> Header >> jss::generic_lock_guard class

The jss::generic_lock_guard class provides a basic lock ownership wrapper that will lock any type of mutex that meets the Lockable requirements. The specified mutex is locked in the constructor and unlocked in the destructor. This provides a simple means of locking a mutex for a block of code and ensuring that the mutex is unlocked when the block is left, whether that is by running off the end, by the use of a control flow statement such as break or return, or by throwing an exception.

Instances of jss::generic_lock_guard are neither MoveConstructible, CopyConstructible or CopyAssignable.

class generic_lock_guard
{
public:
    template<typename Mutex>
    explicit generic_lock_guard(Mutex& m);

    template<typename Mutex>
    generic_lock_guard(Mutex& m, adopt_lock_t);

    ~generic_lock_guard();

    generic_lock_guard(generic_lock_guard const& ) = delete;
    generic_lock_guard& operator=(
        generic_lock_guard const& ) = delete;
};
Header

#include <jss/guards.hpp>

See Also