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

Function test_once_thread

lib_acl/samples/thread/thread1/main.c:228–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226
227static acl_pthread_once_t once_control = ACL_PTHREAD_ONCE_INIT;
228static void *test_once_thread(void *arg acl_unused)
229{
230 ACL_VSTRING *buf;
231 static acl_pthread_key_t buf_key = -1;
232 static __thread ACL_VSTRING *__vbuf = NULL;
233
234 acl_pthread_once(&once_control, init_once);
235
236 if (__vbuf == NULL) {
237 __vbuf = acl_vstring_alloc(256);
238 acl_pthread_atexit_add(__vbuf, free_vbuf);
239 }
240
241 buf = (ACL_VSTRING*) acl_pthread_tls_get(&buf_key);
242 if (buf == NULL) {
243 buf = acl_vstring_alloc(256);
244 acl_pthread_tls_set(buf_key, buf, free_buf);
245 }
246
247 buf = (ACL_VSTRING*) acl_pthread_tls_get(&buf_key);
248 if (buf == NULL)
249 printf(">>>%s(tid=%d) buf null\n", __FUNCTION__, (int) acl_pthread_self());
250 else
251 printf(">>>%s(tid=%d) buf not null\n", __FUNCTION__, (int) acl_pthread_self());
252
253 printf(">>>%s: in thread %d, last error: %s\n",
254 __FUNCTION__, (int) acl_pthread_self(), acl_last_serror());
255
256 return (NULL);
257}
258
259static void test_pthread_once(void)
260{

Callers

nothing calls this directly

Calls 7

acl_pthread_onceFunction · 0.85
acl_vstring_allocFunction · 0.85
acl_pthread_atexit_addFunction · 0.85
acl_pthread_tls_getFunction · 0.85
acl_pthread_tls_setFunction · 0.85
acl_pthread_selfFunction · 0.85
acl_last_serrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…