efl::eina::condition_variable Struct Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files
- Examples

- Data Structures
- Data Structure Index
- Class Hierarchy
- Data Fields

Public Types | Public Member Functions
efl::eina::condition_variable Struct Reference
Eina C++ » Tools » Condition Variable

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

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

## Public Member Functions
| condition_variable ()
| Create a new condition variable. More...
| ~condition_variable ()
| Release the condition variable resources. More...
void | notify_one ()
| Unblock a thread waiting for this condition. More...
void | notify_all ()
| Unblock all threads waiting for this condition. More...
template<typename Lock >
void | wait (Lock &lock)
| Causes a thread to wait until notified. More...
template<typename Lock , typename Predicate >
void | wait (Lock &lock, Predicate p)
| Causes a thread to wait until notified. More...
native_handle_type | native_handle ()
| Get a handle for the wrapped `Eina_Condition`. More...

## Detailed Description

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

This class implements condition variables in a way that strongly resembles the STL `std::condition_variable`.

## Member Typedef Documentation

typedef Eina_Condition* efl::eina::condition_variable::native_handle_type

Type for the native Eina_Lock pointer.

## Constructor & Destructor Documentation

efl::eina::condition_variable::condition_variable | ( |  | ) |
| inline

Create a new condition variable.

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

References eina_condition_new().

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

Release the condition variable resources.

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

References eina_condition_free().

## Member Function Documentation

void efl::eina::condition_variable::notify_one | ( |  | ) |
| inline

Unblock a thread waiting for this condition.

Exceptions

  <tt>eina::system_error</tt> | on fail.

This member function unblock a thread waiting on this condition variable. If there is more than one thread waiting on this condition, one of them will be unblocked, but which one is undefined. If you do not know for sure that there is only one thread waiting, use notify_all() instead.

References eina_condition_signal(), and efl::eina::get_error_code().

void efl::eina::condition_variable::notify_all | ( |  | ) |
| inline

Unblock all threads waiting for this condition.

Exceptions

  <tt>eina::system_error</tt> | on fail.

This member function unblocks all the threads waiting on the this condition. If you know for sure that there is only one thread waiting, use notify_one instead to gain a little optimization.

References eina_condition_broadcast(), and efl::eina::get_error_code().

template<typename Lock >

void efl::eina::condition_variable::wait | ( | Lock & | lock | ) |
| inline

Causes a thread to wait until notified.

Parameters

  lock | A lockable object (`mutex`, `unique_lock`, etc) that is currently locked by this thread. All concurrent calls to wait member functions of this object shall use the same lockable object.

This member function makes a thread block until notified.

References eina_condition_wait().

template<typename Lock , typename Predicate >

void efl::eina::condition_variable::wait | ( | Lock & | lock,
|  | Predicate | p
| ) |  |
| inline

Causes a thread to wait until notified.

Parameters

  lock | A lockable object (`mutex`, `unique_lock`, etc) that is currently locked by this thread. All concurrent calls to wait member functions of this object shall use the same lockable object.
  p | A callable object or function that takes no arguments and returns a value that can be evaluated as a bool. This is called repeatedly until it evaluates to true.

This member function only blocks the thread if `p` is evaluated to `false`. In this case the thread remains blocked until notified and the result of `p` evaluates to `true`.

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

Get a handle for the wrapped `Eina_Condition`.

Returns
  Handle for the native `Eina_Condition`.

This member function returns the native `Eina_Condition` 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.