The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
MHA_TCP::Thread Class Reference

A very simple class for portable threads. More...

Public Types

enum  { PREPARED , RUNNING , FINISHED }
 The current state of the thread. More...
 
typedef void *(* thr_f) (void *)
 The thread function signature to use with this class. More...
 

Public Member Functions

 Thread (thr_f func, void *arg=0)
 Constructor starts a new thread. More...
 
virtual ~Thread ()
 The destructor should only be called when the Thread is finished. More...
 
virtual void run ()
 The internal method that delegated the new thread to the registered Thread function. More...
 

Public Attributes

Async_Notify thread_finish_event
 Event will be triggered when the thread exits. More...
 
enum MHA_TCP::Thread:: { ... }  state
 The current state of the thread. More...
 
thr_f thread_func
 The thread function that the client has registered. More...
 
void * thread_arg
 The argument that the client wants to be handed through to the thread function. More...
 
MHA_Errorerror
 The MHA_Error that caused the thread to abort, if any. More...
 

Protected Member Functions

 Thread ()
 Default constructor may only be used by derived classes that want to start the thread themselves. More...
 

Protected Attributes

void * arg
 The argument for the client's thread function. More...
 
void * return_value
 The return value from the client's thread function is stored here When that function returns. More...
 

Private Attributes

pthread_t thread_handle
 The posix thread handle. More...
 
pthread_attr_t thread_attr
 The posix thread attribute structure. More...
 

Detailed Description

A very simple class for portable threads.

Member Typedef Documentation

◆ thr_f

typedef void*(* MHA_TCP::Thread::thr_f) (void *)

The thread function signature to use with this class.

Derive from this class and call protected standard constructor to start threads differently.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

The current state of the thread.

Enumerator
PREPARED 
RUNNING 
FINISHED 

Constructor & Destructor Documentation

◆ Thread() [1/2]

MHA_TCP::Thread::Thread ( )
protected

Default constructor may only be used by derived classes that want to start the thread themselves.

◆ Thread() [2/2]

Thread::Thread ( Thread::thr_f  func,
void *  arg = 0 
)

Constructor starts a new thread.

Parameters
funcThe function to be executed by the thread.
argThe argument given to pass to the thread function.

◆ ~Thread()

Thread::~Thread ( )
virtual

The destructor should only be called when the Thread is finished.

There is preliminary support for forceful thread cancellation in the destructor, but probably not very robust or portable..

Member Function Documentation

◆ run()

void Thread::run ( )
virtual

The internal method that delegated the new thread to the registered Thread function.

Member Data Documentation

◆ thread_handle

pthread_t MHA_TCP::Thread::thread_handle
private

The posix thread handle.

◆ thread_attr

pthread_attr_t MHA_TCP::Thread::thread_attr
private

The posix thread attribute structure.

Required for starting a thread in detached state. Detachment is required to eliminate the need for joining this thread.

◆ arg

void* MHA_TCP::Thread::arg
protected

The argument for the client's thread function.

◆ return_value

void* MHA_TCP::Thread::return_value
protected

The return value from the client's thread function is stored here When that function returns.

◆ thread_finish_event

Async_Notify MHA_TCP::Thread::thread_finish_event

Event will be triggered when the thread exits.

◆ 

enum { ... } MHA_TCP::Thread::state

The current state of the thread.

◆ thread_func

thr_f MHA_TCP::Thread::thread_func

The thread function that the client has registered.

◆ thread_arg

void* MHA_TCP::Thread::thread_arg

The argument that the client wants to be handed through to the thread function.

◆ error

MHA_Error* MHA_TCP::Thread::error

The MHA_Error that caused the thread to abort, if any.


The documentation for this class was generated from the following files: