X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Fcommon%2Fapi.h;fp=tests%2Fcommon%2Fapi.h;h=ec3ce1ef7486251ec0321d0c65d18aa761816af4;hp=3008716606b73182438b4a6bcaac120beafeab50;hb=c8c32a5208d6e624f9ae9466196e355269c611d5;hpb=2ea38794876c907639971035ed29c4e59964fd7f diff --git a/tests/common/api.h b/tests/common/api.h index 3008716..ec3ce1e 100644 --- a/tests/common/api.h +++ b/tests/common/api.h @@ -14,6 +14,7 @@ #include #include +#include /* * Machine parameters. @@ -102,7 +103,7 @@ static int __smp_thread_id(void) thread_id_t tid = pthread_self(); for (i = 0; i < NR_THREADS; i++) { - if (__thread_id_map[i] == tid) { + if (uatomic_read(&__thread_id_map[i]) == tid) { long v = i + 1; /* must be non-NULL. */ if (pthread_setspecific(thread_id_key, (void *)v) != 0) { @@ -151,12 +152,13 @@ static thread_id_t create_thread(void *(*func)(void *), void *arg) exit(-1); } __thread_id_map[i] = __THREAD_ID_MAP_WAITING; - spin_unlock(&__thread_id_map_mutex); + if (pthread_create(&tid, NULL, func, arg) != 0) { perror("create_thread:pthread_create"); exit(-1); } - __thread_id_map[i] = tid; + uatomic_set(&__thread_id_map[i], tid); + spin_unlock(&__thread_id_map_mutex); return tid; } @@ -166,7 +168,7 @@ static void *wait_thread(thread_id_t tid) void *vp; for (i = 0; i < NR_THREADS; i++) { - if (__thread_id_map[i] == tid) + if (uatomic_read(&__thread_id_map[i]) == tid) break; } if (i >= NR_THREADS){ @@ -178,7 +180,7 @@ static void *wait_thread(thread_id_t tid) perror("wait_thread:pthread_join"); exit(-1); } - __thread_id_map[i] = __THREAD_ID_MAP_EMPTY; + uatomic_set(&__thread_id_map[i], __THREAD_ID_MAP_EMPTY); return vp; }