summaryrefslogtreecommitdiffstats
path: root/04_exercise/threadpool.h
diff options
context:
space:
mode:
Diffstat (limited to '04_exercise/threadpool.h')
-rw-r--r--04_exercise/threadpool.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/04_exercise/threadpool.h b/04_exercise/threadpool.h
index 745c4dd..413f996 100644
--- a/04_exercise/threadpool.h
+++ b/04_exercise/threadpool.h
@@ -118,4 +118,31 @@ extern void tpAwait(Future *future);
return tpAwait(&future->fut), future->res; \
}
+#define TASK_QS(TYPE, NAME) \
+ TYPE NAME(int *arg1, size_t arg2); \
+ \
+ typedef struct { \
+ Future fut; \
+ int* arg1; \
+ size_t arg2; \
+ } NAME ## _fut; \
+ \
+ static void NAME ## Thunk(void *args) { \
+ NAME ## _fut *data = args; \
+ NAME(data->arg1, data->arg2); \
+ } \
+ static inline NAME ## _fut NAME ## Future(int *arg1, size_t arg2) { \
+ return (NAME ## _fut) { \
+ .fut = { .fn = &NAME ## Thunk, .status=FUT_WAITING}, \
+ .arg1 = arg1, \
+ .arg2 = arg2 \
+ }; \
+ } \
+ static inline NAME ## _fut* NAME ## Async(NAME ## _fut *future) { \
+ return tpAsync(&future->fut), future; \
+ } \
+ static inline TYPE NAME ## Await(NAME ## _fut *future) { \
+ tpAwait(&future->fut); \
+ }
+
#endif