-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paththread_util.h
39 lines (31 loc) · 1.04 KB
/
thread_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef TDBCLI_THREAD_UTIL
#define TDBCLI_THREAD_UTIL
#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#define DIE(msg, ...)\
do { fprintf(stderr, msg"\n", ##__VA_ARGS__); \
exit(EXIT_FAILURE); } while (0)
struct thread_job{
void *arg;
pthread_t thread;
int done;
int started;
int fresh;
};
typedef void *(*map_fun_t)(void*);
typedef void *(*reduce_fun_t)(struct thread_job *jobs,
uint32_t num_jobs,
void *reduce_ctx);
void execute_jobs(map_fun_t thread_fun,
struct thread_job *jobs,
uint32_t num_jobs,
uint32_t num_threads);
void *execute_jobs_with_reduce(map_fun_t map_fun,
reduce_fun_t reduce_fun,
struct thread_job *jobs,
void *reduce_ctx,
uint32_t num_jobs,
uint32_t num_threads);
#endif /* TDBCLI_THREAD_UTIL */