MCPcopy Create free account
hub / github.com/apache/trafficserver / main

Function main

src/tscore/test_atomic.cc:141–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139#endif // LONG_ATOMICLIST_TEST
140
141int
142main(int /* argc ATS_UNUSED */, const char * /* argv ATS_UNUSED */[])
143{
144#ifndef LONG_ATOMICLIST_TEST
145 int32_t m = 1, n = 100;
146 // int64 lm = 1LL, ln = 100LL;
147 const char *m2 = "hello";
148 char *n2;
149
150 printf("sizeof(int32_t)==%d sizeof(void *)==%d\n", static_cast<int>(sizeof(int32_t)), static_cast<int>(sizeof(void *)));
151
152 printf("CAS: %d == 1 then 2\n", m);
153 n = ink_atomic_cas(&m, 1, 2);
154 printf("changed to: %d, result=%s\n", m, n ? "true" : "false");
155
156 printf("CAS: %d == 1 then 3\n", m);
157 n = ink_atomic_cas(&m, 1, 3);
158 printf("changed to: %d, result=%s\n", m, n ? "true" : "false");
159
160 printf("CAS pointer: '%s' == 'hello' then 'new'\n", m2);
161 n = ink_atomic_cas(&m2, "hello", "new");
162 printf("changed to: %s, result=%s\n", m2, n ? (char *)"true" : (char *)"false");
163
164 printf("CAS pointer: '%s' == 'hello' then 'new2'\n", m2);
165 n = ink_atomic_cas(&m2, m2, "new2");
166 printf("changed to: %s, result=%s\n", m2, n ? "true" : "false");
167
168 n = 100;
169 printf("Atomic Inc of %d\n", n);
170 m = ink_atomic_increment(static_cast<int *>(&n), 1);
171 printf("changed to: %d, result=%d\n", n, m);
172
173 printf("Atomic Fetch-and-Add 2 to pointer to '%s'\n", m2);
174 n2 = static_cast<char *>(ink_atomic_increment((void **)&m2, (void *)2));
175 printf("changed to: %s, result=%s\n", m2, n2);
176
177 printf("Testing atomic lists\n");
178 {
179 int ali;
180 srand(time(nullptr));
181 printf("sizeof(al_test) = %d\n", static_cast<int>(sizeof(al_test)));
182 memset(&al_test[0][0], 0, sizeof(al_test));
183 for (ali = 0; ali < MAX_ALIST_TEST; ali++) {
184 ink_atomiclist_init(&al[ali], "foo", 0);
185 }
186 for (ali = 0; ali < MAX_ALIST_TEST; ali++) {
187 ink_thread tid;
188 pthread_attr_t attr;
189
190 pthread_attr_init(&attr);
191#if !defined(freebsd)
192 pthread_attr_setstacksize(&attr, 1024 * 1024);
193#endif
194 ink_assert(pthread_create(&tid, &attr, testalist, (void *)((intptr_t)ali)) == 0);
195 }
196 while (al_done != MAX_ALIST_TEST) {
197 sleep(1);
198 }

Callers

nothing calls this directly

Calls 5

ink_atomic_casFunction · 0.85
ink_atomic_incrementFunction · 0.85
memsetFunction · 0.85
ink_atomiclist_initFunction · 0.85
init_dataFunction · 0.85

Tested by

no test coverage detected