]>
Commit | Line | Data |
---|---|---|
7d490872 RB |
1 | #include "clar_libgit2.h" |
2 | #include "thread_helpers.h" | |
3 | ||
4 | void run_in_parallel( | |
5 | int repeats, | |
6 | int threads, | |
7 | void *(*func)(void *), | |
8 | void (*before_test)(void), | |
9 | void (*after_test)(void)) | |
10 | { | |
11 | int r, t, *id = git__calloc(threads, sizeof(int)); | |
12 | #ifdef GIT_THREADS | |
13 | git_thread *th = git__calloc(threads, sizeof(git_thread)); | |
14 | cl_assert(th != NULL); | |
15 | #else | |
16 | void *th = NULL; | |
17 | #endif | |
18 | ||
19 | cl_assert(id != NULL); | |
20 | ||
21 | for (r = 0; r < repeats; ++r) { | |
22 | if (before_test) before_test(); | |
23 | ||
24 | for (t = 0; t < threads; ++t) { | |
25 | id[t] = t; | |
26 | #ifdef GIT_THREADS | |
fc2b97dd | 27 | cl_git_pass(git_thread_create(&th[t], func, &id[t])); |
7d490872 RB |
28 | #else |
29 | cl_assert(func(&id[t]) == &id[t]); | |
30 | #endif | |
31 | } | |
32 | ||
33 | #ifdef GIT_THREADS | |
34 | for (t = 0; t < threads; ++t) | |
fb591767 | 35 | cl_git_pass(git_thread_join(&th[t], NULL)); |
7d490872 RB |
36 | memset(th, 0, threads * sizeof(git_thread)); |
37 | #endif | |
38 | ||
39 | if (after_test) after_test(); | |
40 | } | |
41 | ||
42 | git__free(id); | |
43 | git__free(th); | |
44 | } |