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

Function thread_main

lib_acl_cpp/samples/memcache_pool/main.cpp:65–121  ·  view source on GitHub ↗

�̴߳�������

Source from the content-addressed store, hash-verified

63
64// �̴߳�������
65static void thread_main(void* ctx)
66{
67 char* key = (char*) ctx;
68 bool (*action_fn)(memcache* conn, const char* key);
69 string keybuf;
70 char buf[256];
71
72 if (__action == "set")
73 {
74 action_fn = memcache_set;
75 memset(__data, 'X', sizeof(__data));
76 __data[sizeof(__data) - 1] = 0;
77 }
78 else
79 action_fn = memcache_get;
80
81 struct timeval begin;
82 gettimeofday(&begin, NULL);
83
84 int i = 0;
85 for (; i < __loop_count; i++)
86 {
87 // �����ӳ��л�ȡһ�� HTTP ����
88 memcache* conn = (memcache*) __conn_pool->peek();
89 if (conn == NULL)
90 {
91 printf("peek connect failed\r\n");
92 break;
93 }
94
95 keybuf.format("%s_%d", key, i);
96
97 // ��ʼ�µ� HTTP �������
98 if (action_fn(conn, keybuf.c_str()) == false)
99 {
100 printf("one request failed, close connection\r\n");
101 // ����������Ҫ�ر�
102 __conn_pool->put(conn, false);
103 break;
104 }
105 else
106 __conn_pool->put(conn, true);
107 if (i % 1000 == 0)
108 {
109 acl::safe_snprintf(buf, sizeof(buf), "key: %s, action(%s) ok",
110 keybuf.c_str(), __action.c_str());
111 ACL_METER_TIME(buf);
112 }
113 }
114
115 struct timeval end;
116 gettimeofday(&end, NULL);
117
118 double spent = util::stamp_sub(&end, &begin);
119 printf("total: %d, curr: %d, spent: %.2f, speed: %.2f\r\n",
120 __loop_count, i, spent, (i * 1000) / (spent > 1 ? spent : 1));
121}
122

Callers

nothing calls this directly

Calls 7

safe_snprintfFunction · 0.85
gettimeofdayFunction · 0.50
stamp_subFunction · 0.50
peekMethod · 0.45
formatMethod · 0.45
c_strMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…