forked from zlgopen/awtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync_call_test.cpp
52 lines (40 loc) · 961 Bytes
/
async_call_test.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "tkc/utils.h"
#include "tkc/thread.h"
#include "tkc/async.h"
#include "tkc/platform.h"
#include "tkc/action_thread_pool.h"
static uint32_t fibonacci(uint32_t n) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
static ret_t fibonacci_async_exec(void* ctx) {
uint32_t n = (uint32_t)tk_pointer_to_int(ctx);
fibonacci(n);
log_debug("thread id=%u n=%u\n", (uint32_t)tk_thread_self(), n);
return RET_OK;
}
static ret_t fibonacci_async(uint32_t n) {
return async_call(fibonacci_async_exec, NULL, tk_pointer_from_int(n));
}
#define NR 10000
void test() {
uint32_t i = 0;
for (i = 0; i < NR; i++) {
uint32_t n = i % 30 + 10;
log_debug("%u %u\n", i, n);
fibonacci_async(n);
}
}
#include "tkc/platform.h"
int main(int argc, char* argv[]) {
platform_prepare();
async_call_init_ex(10, 2);
test();
async_call_deinit();
return 0;
}