Thread pool
|
Data Structures | |
struct | pair_future |
Pair of future variables. More... | |
Typedefs | |
typedef void *(* | function_t) (void *) |
typedef struct pair_future | pair_future_t |
Pair of future variables. | |
Functions | |
static void | fun (void *arg, size_t size __attribute__((unused))) |
Wrap callable function in runnable. More... | |
static void | fun_with_wait (void *arg, size_t size __attribute__((unused))) |
Helper function for map. More... | |
int | async (thread_pool_t *pool, future_t *future, callable_t callable) |
Create a future variable that will store the result of callable. More... | |
int | map (thread_pool_t *pool, future_t *future, future_t *from, void *(*function)(void *, size_t, size_t *)) |
Create a future variable that will store the result of callable. More... | |
void * | await (future_t *future) |
Wait for future to finish. More... | |
Future implementation.
int async | ( | thread_pool_t * | pool, |
future_t * | future, | ||
callable_t | callable | ||
) |
Create a future variable that will store the result of callable.
Create a future variable. Create runnable function that will run callable function and add it to the thread-pool.
[in,out] | pool | – pointer to the thread-pool; |
[in,out] | future | – pointer to a variable that will store the callable result; |
[in] | callable | – function that will be run by thread-pool; |
0
, if future was created correctly and callable function has been added to thread-pool. Non-zero value, if errors occurred. void* await | ( | future_t * | future | ) |
Wait for future to finish.
Sleep on semaphore until the future is calculated.
[in,out] | future | – pointer to a variable that will store the callable result; |
|
static |
Wrap callable function in runnable.
Write the result of the function to variable. Unlock the semaphore to let user know that the task is finished.
[in,out] | arg | – array of arguments; |
|
static |
Helper function for map.
Wait until from is finished, then run the function and write the result to future.
[in,out] | arg | – array of arguments; |
int map | ( | thread_pool_t * | pool, |
future_t * | future, | ||
future_t * | from, | ||
void *(*)(void *, size_t, size_t *) | function | ||
) |
Create a future variable that will store the result of callable.
Create runnable function that will run callable function and add a new task to the thread-pool.
[in,out] | pool | – pointer to the thread-pool; |
[in,out] | future | – pointer to the future variable that stores the arguments to the function; |
[in,out] | from | – pointer to a variable that will store the callable result; |
[in,out] | function | – function that will be run by thread-pool; |
0
, if future variables were mapped correctly. Non-zero value, if errors occurred.