BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #include <stddef.h>
2 #include <stdio.h>
3  
4 #include <misc/debug.h>
5 #include <base/BLog.h>
6 #include <base/DebugObject.h>
7 #include <threadwork/BThreadWork.h>
8  
9 BReactor reactor;
10 BThreadWorkDispatcher twd;
11 BThreadWork tw1;
12 BThreadWork tw2;
13 BThreadWork tw3;
14 int num_left;
15  
16 static void handler_done (void *user)
17 {
18 printf("work done\n");
19  
20 num_left--;
21  
22 if (num_left == 0) {
23 printf("all works done, quitting\n");
24 BReactor_Quit(&reactor, 0);
25 }
26 }
27  
28 static void work_func (void *user)
29 {
30 unsigned int x = 0;
31  
32 for (int i = 0; i < 10000; i++) {
33 for (int j = 0; j < 10000; j++) {
34 x++;
35 }
36 }
37 }
38  
39 static void dummy_works (int n)
40 {
41 for (int i = 0; i < n; i++) {
42 BThreadWork tw_tmp;
43 BThreadWork_Init(&tw_tmp, &twd, handler_done, NULL, work_func, NULL);
44 BThreadWork_Free(&tw_tmp);
45 }
46 }
47  
48 int main ()
49 {
50 BLog_InitStdout();
51 BLog_SetChannelLoglevel(BLOG_CHANNEL_BThreadWork, BLOG_DEBUG);
52  
53 if (!BReactor_Init(&reactor)) {
54 DEBUG("BReactor_Init failed");
55 goto fail1;
56 }
57  
58 if (!BThreadWorkDispatcher_Init(&twd, &reactor, 1)) {
59 DEBUG("BThreadWorkDispatcher_Init failed");
60 goto fail2;
61 }
62  
63 dummy_works(200);
64  
65 BThreadWork_Init(&tw1, &twd, handler_done, NULL, work_func, NULL);
66  
67 BThreadWork_Init(&tw2, &twd, handler_done, NULL, work_func, NULL);
68  
69 BThreadWork_Init(&tw3, &twd, handler_done, NULL, work_func, NULL);
70  
71 dummy_works(200);
72  
73 num_left = 3;
74  
75 BReactor_Exec(&reactor);
76  
77 BThreadWork_Free(&tw3);
78 BThreadWork_Free(&tw2);
79 BThreadWork_Free(&tw1);
80 BThreadWorkDispatcher_Free(&twd);
81 fail2:
82 BReactor_Free(&reactor);
83 fail1:
84 BLog_Free();
85 DebugObjectGlobal_Finish();
86 return 0;
87 }