Thread pool
Data Structures | Typedefs | Functions
future.h File Reference
#include "../threadpool/threadpool.h"
Include dependency graph for future.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  callable
 Callable function. More...
 
struct  future
 Future that will get the value asynchronously (similar to C++ std::future). More...
 

Typedefs

typedef struct callable callable_t
 Callable function.
 
typedef struct future future_t
 Future that will get the value asynchronously (similar to C++ std::future).
 

Functions

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

Detailed Description

Future header file.

Author
Michał Niedziółka micha.nosp@m.l.ni.nosp@m.edzio.nosp@m.lka@.nosp@m.stude.nosp@m.nts..nosp@m.mimuw.nosp@m..edu.nosp@m..pl
Date
11.02.2020

Function Documentation

◆ async()

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.

Parameters
[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;
Returns
0, if future was created correctly and callable function has been added to thread-pool. Non-zero value, if errors occurred.
Here is the call graph for this function:

◆ await()

void* await ( future_t future)

Wait for future to finish.

Sleep on semaphore until the future is calculated.

Parameters
[in,out]future– pointer to a variable that will store the callable result;

◆ map()

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.

Parameters
[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;
Returns
0, if future variables were mapped correctly. Non-zero value, if errors occurred.
Here is the call graph for this function: