MCPcopy Create free account
hub / github.com/acl-dev/acl / run

Method run

lib_acl_cpp/samples/thread_queue/main.cpp:39–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37
38protected:
39 void* run()
40 {
41 long long int n = 0;
42
43 struct timeval begin;
44 gettimeofday(&begin, NULL);
45
46 while (true)
47 {
48 queue_item* item = (queue_item*) queue_.pop();
49 if (item == NULL)
50 break;
51
52 n++;
53
54 msg_t type = item->get_type();
55 delete item;
56
57 if (type == MSG_STOP)
58 {
59 printf("stop now, max: %lld\r\n", n);
60 break;
61 }
62
63 switch (type)
64 {
65 case MSG_ECHO:
66 if (n <= 10)
67 printf("hello\r\n");
68 if (n % 100000 == 0)
69 {
70 char tmp[256];
71 acl::safe_snprintf(tmp, sizeof(tmp),
72 "n: %lld", n);
73 acl::meter_time(__FILE__, __LINE__, tmp);
74 }
75 break;
76 default:
77 printf("unknown msg type\r\n");
78 break;
79 }
80 }
81
82 struct timeval end;
83 gettimeofday(&end, NULL);
84 double spent = util::stamp_sub(&end, &begin);
85
86 printf("queue item over, max: %lld\r\n", n);
87 printf("max: %lld, spent: %.2f, speed: %.2f\r\n",
88 n, spent, n * 1000 / (spent > 0 ? spent : 1));
89
90 return NULL;
91 }
92
93private:
94 acl::thread_queue& queue_;

Callers

nothing calls this directly

Calls 6

safe_snprintfFunction · 0.85
meter_timeFunction · 0.85
gettimeofdayFunction · 0.50
stamp_subFunction · 0.50
popMethod · 0.45
get_typeMethod · 0.45

Tested by

no test coverage detected