ONPOSIX
2.0
|
Worker thread to perform asynchronous operations. More...
Public Member Functions | |
Worker (shared_queue *q, PosixDescriptor *des) | |
Constructor. | |
~Worker () | |
void | startAsyncOperation (bool read_operation, void(*handler)(Buffer *b, size_t size), Buffer *buff, size_t size) |
Function to start an asynchronous operation. | |
void | startAsyncOperation (bool read_operation, void(*handler)(void *b, size_t size), void *buff, size_t size) |
Function so start an asynchronous operation. | |
Public Member Functions inherited from AbstractThread | |
AbstractThread () | |
Constructor. Initialize the class attributes. | |
virtual | ~AbstractThread () |
Destructor. | |
bool | start () |
Starts execution of the thread by calling run(). | |
bool | stop () |
Stops the running thread. | |
bool | waitForTermination () |
Blocks the calling thread until the thread is finished. | |
bool | sendSignal (int sig) |
Sends a signal to the thread. | |
bool | setSchedParam (int policy, int priority) |
Set scheduling policy and priority. | |
bool | getSchedParam (int *policy, int *priority) |
Get current scheduling policy and priority. |
Private Member Functions | |
Worker () | |
Disable the default constructor. | |
void | run () |
Method automatically called by start() |
Private Attributes | |
PosixDescriptor * | des_ |
File descriptor. | |
shared_queue * | queue_ |
Pointer to the shared queue. |
Additional Inherited Members | |
Static Public Member Functions inherited from AbstractThread | |
static bool | blockSignal (int sig) |
Masks a specific signal on this thread. | |
static bool | unblockSignal (int sig) |
Unmasks a signal previously masked. | |
static bool | setSignalHandler (int sig, void(*handler)(int)) |
Set a handler for a specific signal. | |
Protected Member Functions inherited from AbstractThread | |
virtual void | run ()=0 |
This function must be reimplemented in a derived class to define the specific function run by the thread. | |
Static Protected Member Functions inherited from AbstractThread | |
static void | checkTermination () |
Function to know if the thread has finished computation. | |
Protected Attributes inherited from AbstractThread | |
pthread_t | handle_ |
Worker thread to perform asynchronous operations.
This class is used to run asynchronous operations (i.e., read and write). These operations are run on a different thread.
Definition at line 262 of file PosixDescriptor.hpp.
|
private |
Disable the default constructor.
|
inline |
Constructor.
It just initializes the variables.
q | Pointer to the shared_queue for synchronization and pending jobs |
des | Pointer to the PosixDescriptor that "owns" this worker |
Definition at line 305 of file PosixDescriptor.hpp.
|
inline |
Definition at line 308 of file PosixDescriptor.hpp.
|
private |
Method automatically called by start()
Function run on the separate thread.
This method is automatically called by start() which, in turn, is called by startAsyncOperation()
This is the function automatically called by start() which, in turn, is called by startAsyncOperation(). The function is run by the worker thread. It performs the read/write operation and invokes the handler.
It | throws runtime_error in case no operation has been scheduled |
Definition at line 96 of file PosixDescriptor.cpp.
void startAsyncOperation | ( | bool | read_operation, |
void(*)(Buffer *b, size_t size) | handler, | ||
Buffer * | buff, | ||
size_t | size | ||
) |
Function to start an asynchronous operation.
This method allows to start an asynchronous operation, either read or write.
read_operation | Specifies if it is a read (true) or write (false) operation |
handler | Function to be run at the end of the operation. This function will have as arguments a Buffer* where data is stored and the number of bytes actually transferred. |
buff | Buffer where data must be copied to (for a read operation) or where data is contained (for a write operation) |
size | Amount of bytes to be transferred |
Definition at line 37 of file PosixDescriptor.cpp.
void startAsyncOperation | ( | bool | read_operation, |
void(*)(void *b, size_t size) | handler, | ||
void * | buff, | ||
size_t | size | ||
) |
Function so start an asynchronous operation.
This method allows to start an asynchronous operation, either read or write.
read_operation | Specifies if it is a read (true) or write (false) operation |
handler | Function to be run at the end of the operation. This function will have as arguments a void* where data is stored and the number of bytes actually transferred. |
buff | void* where data must be copied to (for a read operation) or where data is contained (for a write operation) |
size | Amount of bytes to be transferred |
Definition at line 69 of file PosixDescriptor.cpp.
|
private |
File descriptor.
This is a pointer to the same PosixDescriptor that "owns" this instance of Worker. The pointer is needed to perform the operation (i.e., read or write).
Definition at line 283 of file PosixDescriptor.hpp.
|
private |
Pointer to the shared queue.
This variable points the shared_queue used for asynchronous operations and synchronization between the main thread and the worker thread.
Definition at line 292 of file PosixDescriptor.hpp.