efl::eina::thread 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 | Static Public Member Functions
efl::eina::thread Struct Reference
Eina C++ » Tools » Thread

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

## Public Types
typedef thread_id | id
| Type for the thread identifier. More...
typedef Eina_Thread | native_handle_type
| Type for the native Eina_Thread handle. More...

## Public Member Functions
| thread () noexcept
| Creates a thread object that does not represent any thread of execution.
template<typename F , class... Args>
| thread (F &&f, Args &&...args)
| Creates a thread of execution. More...
| thread (thread &&other)
| Move constructor. More...
thread & | operator= (thread &&other)
| Transfer the thread of execution. More...
| ~thread ()
| Destroys the thread object.
void | swap (thread &other) noexcept
| Exchanges the underlying handles of two thread objects. More...
bool | joinable () const noexcept
| Check if the thread object identifies an active thread of execution. More...
void | join ()
| Wait for the thread to finish its execution. More...
void | detach ()
| Detaches the thread from its handle, making it runs independently. More...
id | get_id () const noexcept
| Returns the identifier of the thread associated with this thread object. More...
native_handle_type | native_handle () const
| Get a handle for the wrapped `Eina_Thread`. More...

## Static Public Member Functions
static unsigned | hardware_concurrency () noexcept
| Get the number of hardware concurrent threads. More...

## Detailed Description

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

This class implements threads in a way that strongly resembles the STL `std::thread`.

## Member Typedef Documentation

typedef thread_id efl::eina::thread::id

Type for the thread identifier.

typedef Eina_Thread efl::eina::thread::native_handle_type

Type for the native Eina_Thread handle.

## Constructor & Destructor Documentation

template<typename F , class... Args>

efl::eina::thread::thread | ( | F && | f,
|  | Args &&... | args
| ) |  |
| inlineexplicit

Creates a thread of execution.

Parameters

  f | Pointer to function or callable object to execute in the new thread. The return value (if any) is ignored.
  args | Arguments to pass to the `f`.

This constructor creates a thread object that represents a thread of execution. The new thread of execution calls `f` passing `args` as arguments (all arguments are copied/moved to thread-accessible storage).

Any exceptions thrown during evaluation and copying/moving of the arguments are thrown in the current thread, not the new thread.

References eina_condition_free(), eina_condition_new(), eina_condition_wait(), eina_lock_free(), eina_lock_new(), eina_lock_release(), EINA_LOCK_SUCCEED, eina_lock_take(), eina_thread_create(), and efl::eina::get_error_code().

efl::eina::thread::thread | ( | thread && | other | ) |
| inline

Move constructor.

Transfer the thread of execution to the new object.

Parameters

  other | Another thread object to construct this thread object with.

This constructor creates a thread object that acquires the thread of execution represented by `other`. This operation does not affect the execution of the moved thread, it simply transfers its handler.

Note
  After this call `other` no longer represents a thread of execution.

## Member Function Documentation

thread& efl::eina::thread::operator= | ( | thread && | other | ) |
| inline

Transfer the thread of execution.

Parameters

  other | Another thread object to assign to this thread object.

Note
  After this call `other` no longer represents a thread of execution.

void efl::eina::thread::swap | ( | thread & | other | ) |
| inlinenoexcept

Exchanges the underlying handles of two thread objects.

Parameters

  other | Another thread object.

References efl::eina::swap().

Referenced by efl::eina::swap().

bool efl::eina::thread::joinable | ( |  | ) | const
| inlinenoexcept

Check if the thread object identifies an active thread of execution.

Returns
  `true` if the thread object identifies an active thread of execution, `false` otherwise.

This member function checks if the thread object identifies an active thread of execution. A default constructed thread is not joinable, as well as a thread that its members join or detach has been called.

A thread that has finished executing code, but has not yet been joined is still considered an active thread of execution and is therefore joinable.

void efl::eina::thread::join | ( |  | ) |
| inline

Wait for the thread to finish its execution.

This member function blocks the calling thread until the thread identified by this object finishes its execution.

Note
  A joinable thread becomes not joinable after a call to this function.

References eina_thread_join().

void efl::eina::thread::detach | ( |  | ) |
| inline

Detaches the thread from its handle, making it runs independently.

This member function separates the thread of execution from the thread object, allowing execution to continue independently.

Note
  After a call to this function, the thread object becomes non-joinable.

id efl::eina::thread::get_id | ( |  | ) | const
| inlinenoexcept

Returns the identifier of the thread associated with this thread object.

Returns
  `thread::id` identifying the thread associated with this thread object.

native_handle_type efl::eina::thread::native_handle | ( |  | ) | const
| inline

Get a handle for the wrapped `Eina_Thread`.

Returns
  Handle for the native `Eina_Thread`.

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

static unsigned efl::eina::thread::hardware_concurrency | ( |  | ) |
| inlinestaticnoexcept

Get the number of hardware concurrent threads.

Returns
  A hint on the number of hardware concurrent threads, or `0` if the value is not well defined or not computable.

This static member function returns the number of hardware concurrent threads.

Note
  The interpretation of this value is implementation-specific, and may be just an approximation.

References eina_cpu_count().