Public Types | Public Member Functions | Static Public Member Functions
efl::eina::thread Struct Reference

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...
 
threadoperator= (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

◆ id

Type for the thread identifier.

◆ native_handle_type

Type for the native Eina_Thread handle.

Constructor & Destructor Documentation

◆ thread() [1/2]

template<typename F , class ... Args>
efl::eina::thread::thread ( F &&  f,
Args &&...  args 
)
inlineexplicit

Creates a thread of execution.

Parameters
fPointer to function or callable object to execute in the new thread. The return value (if any) is ignored.
argsArguments 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_new(), eina_lock_new(), eina_thread_create(), and efl::eina::get_error_code().

◆ thread() [2/2]

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

Move constructor.

Transfer the thread of execution to the new object.

Parameters
otherAnother 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

◆ operator=()

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

Transfer the thread of execution.

Parameters
otherAnother thread object to assign to this thread object.
Note
After this call other no longer represents a thread of execution.

◆ swap()

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

Exchanges the underlying handles of two thread objects.

Parameters
otherAnother thread object.

References efl::eina::swap().

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

◆ joinable()

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.

◆ join()

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().

◆ detach()

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.

◆ get_id()

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()

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.

◆ hardware_concurrency()

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().