glibmm 2.66.5
Public Member Functions | List of all members
Glib::Threads::Mutex::Lock Class Reference

Utility class for exception-safe mutex locking. More...

#include <glibmm/threads.h>

Public Member Functions

 Lock (Mutex & mutex)
 
 Lock (Mutex & mutex, NotLock)
 
 Lock (Mutex & mutex, TryLock)
 
 Lock (const Mutex::Lock &)=delete
 
Mutex::Lockoperator= (const Mutex::Lock &)=delete
 
 ~Lock ()
 
void acquire ()
 
bool try_acquire ()
 
void release ()
 
bool locked () const
 

Detailed Description

Utility class for exception-safe mutex locking.

Usage example:
{
Glib::Threads::Mutex::Lock lock(mutex); // calls mutex.lock()
do_something();
} // the destructor calls mutex.unlock()
Utility class for exception-safe mutex locking.
Definition: threads.h:298
void lock()
Locks the mutex.
As you can see, the compiler takes care of the unlocking. This is not only exception-safe but also much less error-prone. You could even return while still holding the lock and it will be released properly.
Deprecated:
Please use std::lock_guard or std::unique_lock instead.

Constructor & Destructor Documentation

◆ Lock() [1/4]

Glib::Threads::Mutex::Lock::Lock ( Mutex mutex)
inlineexplicit

◆ Lock() [2/4]

Glib::Threads::Mutex::Lock::Lock ( Mutex mutex,
NotLock   
)
inline

◆ Lock() [3/4]

Glib::Threads::Mutex::Lock::Lock ( Mutex mutex,
TryLock   
)
inline

◆ Lock() [4/4]

Glib::Threads::Mutex::Lock::Lock ( const Mutex::Lock )
delete

◆ ~Lock()

Glib::Threads::Mutex::Lock::~Lock ( )
inline

Member Function Documentation

◆ acquire()

void Glib::Threads::Mutex::Lock::acquire ( )
inline

◆ locked()

bool Glib::Threads::Mutex::Lock::locked ( ) const
inline

◆ operator=()

Mutex::Lock & Glib::Threads::Mutex::Lock::operator= ( const Mutex::Lock )
delete

◆ release()

void Glib::Threads::Mutex::Lock::release ( )
inline

◆ try_acquire()

bool Glib::Threads::Mutex::Lock::try_acquire ( )
inline