efl::eina::mutex Struct Reference

Public Types | Public Member Functions
efl::eina::mutex Struct Reference
Eina C++ » Tools » Mutex

Provides an OOP interface to the `Eina_Lock` and automatic resource allocation and deallocation using the RAII programming idiom. More...

## Public Types
typedef Eina_Lock * | native_handle_type
| Type for the native Eina_Lock pointer. More...

## Public Member Functions
| mutex ()
| Create a new mutex. More...
| ~mutex ()
| Release mutex resources. More...
void | lock ()
| Lock the mutex. More...
bool | try_lock ()
| Attempts to lock the mutex. More...
void | unlock ()
| Unlock the lock. More...
void | debug ()
| Print debug information about the mutex. More...
native_handle_type | native_handle ()
| Get a handle for the wrapped `Eina_Lock`. More...

## Detailed Description

Provides an OOP interface to the `Eina_Lock` and automatic resource allocation and deallocation using the RAII programming idiom.

This class implements mutual exclusion variables (mutexes) in a way that strongly resembles the STL `std::mutex`.

## Member Typedef Documentation

## ◆ native_handle_type

typedef Eina_Lock* efl::eina::mutex::native_handle_type

Type for the native Eina_Lock pointer.

## Constructor & Destructor Documentation

## ◆ mutex()

efl::eina::mutex::mutex | ( |  | ) |
| inline

Create a new mutex.

Automatically allocates a new mutex and does any platform dependent initialization that is required.

References eina_lock_new().

Referenced by native_handle().

## ◆ ~mutex()

efl::eina::mutex::~mutex | ( |  | ) |
| inline

Release mutex resources.

Automatically deallocates the mutex and does any platform dependent cleanup that is required.

References eina_lock_free().

## Member Function Documentation

## ◆ lock()

void efl::eina::mutex::lock | ( |  | ) |
| inline

Lock the mutex.

Exceptions

  <tt>eina::system_error</tt> | with the code `eina::errc::resource_deadlock_would_occur` if the operation fails because a deadlock condition exists. If some other condition causes the lock to fail (other than the mutex being already locked) the error code will be an internal Eina error code.

This member function locks the mutex. If the mutex is locked already, this call will block until the lock is released. This is appropriate in many cases, but consider using try_lock() if you don't need to block.

References EINA_LOCK_DEADLOCK, EINA_LOCK_SUCCEED, and eina_lock_take().

## ◆ try_lock()

bool efl::eina::mutex::try_lock | ( |  | ) |
| inline

Attempts to lock the mutex.

Returns
  `true` if it succeed in locking the mutex, `false` otherwise.

Exceptions

  <tt>eina::system_error</tt> | with the code `eina::errc::resource_deadlock_would_occur` if the operation fails because a deadlock condition exists. If some other condition causes the lock to fail (other than the mutex being already locked) the error code will be an internal Eina error code.

This member function attempts to lock the mutex, identical to lock(), but returns immediately if the mutex is already locked.

References EINA_LOCK_DEADLOCK, EINA_LOCK_FAIL, EINA_LOCK_SUCCEED, and eina_lock_take_try().

## ◆ unlock()

void efl::eina::mutex::unlock | ( |  | ) |
| inline

Unlock the lock.

Exceptions

  <tt>eina::system_error</tt> | with the code `eina::errc::resource_deadlock_would_occur` if the operation fails because a deadlock condition exists. If some other condition causes the lock to fail the error code will be an internal Eina error code.

This member function will unlock the mutex.

Note
  If successful, and EINA_HAVE_DEBUG_THREADS is defined, the mutex is updated and information about the locking process is removed (e.g. thread number and backtrace for POSIX).

References EINA_LOCK_DEADLOCK, eina_lock_release(), and EINA_LOCK_SUCCEED.

## ◆ debug()

void efl::eina::mutex::debug | ( |  | ) |
| inline

Print debug information about the mutex.

This member function prints debug information for the mutex. The information is platform dependent. On POSIX systems it will print the address of mutex, lock state, thread number and a backtrace.

References eina_lock_debug().

## ◆ native_handle()

native_handle_type efl::eina::mutex::native_handle | ( |  | ) |
| inline

Get a handle for the wrapped `Eina_Lock`.

Returns
  Handle for the native `Eina_Lock`.

This member function returns the native `Eina_Lock` handle that is wrapped inside this object.

Warning
  It is important to take care when using it, since the handle will be automatically released upon object destruction.

References mutex().