Process in parallel based on indices.
More...
◆ idx_terminate()
Query the termination state
- Parameters
-
- Return values
-
◆ idx_next_to_process_get()
Get the next index to process
- Parameters
-
| [in,out] | wctx | Working context |
- Return values
-
| Positive | Index to process [0…n] |
| -ENODATA | No more indices to process |
Called by all worker threads
This index works like a lock. As long the thread works on this index, it owns it and its corresponding status info
- Note
- The first call must return the index '0'
- Postcondition
- On error (including the -ENODATA) the thread just terminates immediately
◆ idx_mark_done()
Signal another index is now processed
- Parameters
-
| [in,out] | wctx | Working context |
Called by the worker thread when it has processed an index
◆ idx_already_done_get()
Retrieve if at least one index is available (e.g. already processed and ready to print)
- Parameters
-
| [in,out] | wctx | Working context |
- Return values
-
| 1 | Yes, an already done index is available |
| 0 | No, no index is available |
Called by the main worker thread. This call never sleeps
- Note
- On a semaphore error this routine will terminate the worker
◆ idx_already_done_get_with_wait()
Retrieve if at least one index is available (e.g. already processed and ready to print)
- Parameters
-
| [in,out] | wctx | Working context |
Called by the main worker thread. This call sleeps if the semaphore is still '0'
- Note
- On a semaphore error this routine will terminate the worker
◆ worker_thread()
| static void * worker_thread |
( |
void * |
p | ) |
|
|
static |
Index processing worker thread
- Parameters
-
This worker thread loops until there are no more indices to process.
Since this thread should only work on plain data, it should not be involved into signal processing. This should be limited to the main worker thread only.
I have no idea how to setup this in a race free manner. This thread inherits the signal mask from the main worker thread. So we can't mask the signals in the main worker thread because that would interfere with the programmer's settings. So, change the signal's mask here, prior starting to work on real data.
TODO The solution could be to create a separate thread only for receiving the signals. Refer sigwaitinfo() for details. The manual page for pthread_sigmask() contains an example.
◆ create_worker_thread()
| static pthread_t create_worker_thread |
( |
void * |
param | ) |
|
|
static |
Create one thread to process indecs according to our local requirements
- Parameters
-
| [in] | param | Must be a pointer to the current context |
- Returns
- The ID of this worker thread
- Todo:
- Fix exit() usage in create_worker_thread()
◆ idx_done_check()
Check if the next index to print is already processed
- Parameters
-
| [in,out] | wctx | Working context |
- Return values
-
| true | User's callback reports processing done |
| false | User's callback reports processing is ongoing |
Its up to the user to decide if an index is already done.
◆ idx_left_to_print_check()
Check, if there are still indices left to print
- Parameters
-
| [in,out] | wctx | Working context |
- Return values
-
| false | If there are not more indices left to print |
| true | If there are still more indices left to print |
◆ worker_idx_print()
Call the printing callback as often as possible
- Parameters
-
| [in,out] | wctx | Working context |
Print as much already done consecutive indices as possible. This is required to avoid a dead-lock, because the corresponding semaphore events for the indices following the current one may be already consumed: we must make up for them.