From cd8b04c9068052db9f656e4cedf5d2b00b1cf455 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Sun, 30 Jun 2013 08:59:33 +0000 Subject: Convert this piece of code to use C11 atomics. As mentioned before, we should at least aim to have one piece of code in both user space and kernel space that uses C11 atomics, to get some coverage. This piece of code can be migrated trivially, so it's a good candidate. --- lib/librt/sigev_thread.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/librt/sigev_thread.c b/lib/librt/sigev_thread.c index 0246c0c339cb9..2677a8e50589a 100644 --- a/lib/librt/sigev_thread.c +++ b/lib/librt/sigev_thread.c @@ -28,13 +28,13 @@ */ #include -#include #include "namespace.h" #include #include #include #include +#include #include #include #include @@ -51,7 +51,7 @@ LIST_HEAD(sigev_list_head, sigev_node); static struct sigev_list_head sigev_hash[HASH_QUEUES]; static struct sigev_list_head sigev_all; static LIST_HEAD(,sigev_thread) sigev_threads; -static unsigned int sigev_generation; +static atomic_int sigev_generation; static pthread_mutex_t *sigev_list_mtx; static pthread_once_t sigev_once = PTHREAD_ONCE_INIT; static pthread_once_t sigev_once_default = PTHREAD_ONCE_INIT; @@ -196,7 +196,8 @@ __sigev_alloc(int type, const struct sigevent *evp, struct sigev_node *prev, if (sn != NULL) { sn->sn_value = evp->sigev_value; sn->sn_func = evp->sigev_notify_function; - sn->sn_gen = atomic_fetchadd_int(&sigev_generation, 1); + sn->sn_gen = atomic_fetch_add_explicit(&sigev_generation, 1, + memory_order_relaxed); sn->sn_type = type; _pthread_attr_init(&sn->sn_attr); _pthread_attr_setdetachstate(&sn->sn_attr, PTHREAD_CREATE_DETACHED); -- cgit v1.2.3