Thread pool
future.h
Go to the documentation of this file.
1 
9 #ifndef __FUTURE_H__
10 #define __FUTURE_H__
11 
12 #include "../threadpool/threadpool.h"
13 
17 typedef struct callable {
18  void *(*function)(void*, size_t, size_t*);
19  void* arg;
20  size_t argsz;
21 } callable_t;
22 
27 typedef struct future {
29  sem_t finished;
30  void* result;
31  size_t result_size;
32 } future_t;
33 
45 
57 int map(thread_pool_t* pool, future_t* future, future_t* from,
58  void* (*function)(void*, size_t, size_t*));
59 
64 void *await(future_t *future);
65 
66 #endif // __FUTURE_H__
async
int async(thread_pool_t *pool, future_t *future, callable_t callable)
Create a future variable that will store the result of callable.
Definition: future.c:50
fun_with_wait
static void fun_with_wait(void *arg, size_t size __attribute__((unused)))
Helper function for map.
Definition: future.c:38
runnable
Runnable function.
Definition: threadpool.h:20
future.h
callable::function
void *(* function)(void *, size_t, size_t *)
f(arg, argsz, result_size);
Definition: future.h:18
future::finished
sem_t finished
status of the future(pending/finished);
Definition: future.h:29
map
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.
Definition: future.c:68
pair_future::second
future_t * second
pointer to second future;
Definition: future.c:20
thread_pool
Thread-pool.
Definition: threadpool.h:46
callable::arg
void * arg
array of arguments;
Definition: future.h:19
callable
Callable function.
Definition: future.h:17
pair_future_t
struct pair_future pair_future_t
Pair of future variables.
await
void * await(future_t *future)
Wait for future to finish.
Definition: future.c:100
__attribute__
__attribute__((constructor))
Constructor of the exception handler.
Definition: threadpool.c:115
future::result
void * result
pointer to the result of the function;
Definition: future.h:30
runnable::function
void(* function)(void *, size_t)
f(arg, argsz);
Definition: threadpool.h:21
map
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.
Definition: future.c:68
async
int async(thread_pool_t *pool, future_t *future, callable_t callable)
Create a future variable that will store the result of callable.
Definition: future.c:50
fun
static void fun(void *arg, size_t size __attribute__((unused)))
Wrap callable function in runnable.
Definition: future.c:28
future_t
struct future future_t
Future that will get the value asynchronously (similar to C++ std::future).
await
void * await(future_t *future)
Wait for future to finish.
Definition: future.c:100
callable::argsz
size_t argsz
number of arguments;
Definition: future.h:20
future::callable
callable_t callable
callable function;
Definition: future.h:28
pair_future::first
future_t * first
pointer to first future;
Definition: future.c:19
runnable::argsz
size_t argsz
number of arguments;
Definition: threadpool.h:23
future
Future that will get the value asynchronously (similar to C++ std::future).
Definition: future.h:27
runnable::arg
void * arg
array of arguments;
Definition: threadpool.h:22
future::result_size
size_t result_size
size of the result;
Definition: future.h:31
pair_future
Pair of future variables.
Definition: future.c:18
callable_t
struct callable callable_t
Callable function.
defer
int defer(struct thread_pool *pool, runnable_t runnable)
Add a new task to the pool.
Definition: threadpool.c:318