From owner-svn-src-all@FreeBSD.ORG Sun Jun 30 08:59:34 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 568E3125; Sun, 30 Jun 2013 08:59:34 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 48ED81843; Sun, 30 Jun 2013 08:59:34 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5U8xYkC019327; Sun, 30 Jun 2013 08:59:34 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r5U8xYUf019326; Sun, 30 Jun 2013 08:59:34 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201306300859.r5U8xYUf019326@svn.freebsd.org> From: Ed Schouten Date: Sun, 30 Jun 2013 08:59:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r252412 - head/lib/librt X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Jun 2013 08:59:34 -0000 Author: ed Date: Sun Jun 30 08:59:33 2013 New Revision: 252412 URL: http://svnweb.freebsd.org/changeset/base/252412 Log: 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. Modified: head/lib/librt/sigev_thread.c Modified: head/lib/librt/sigev_thread.c ============================================================================== --- head/lib/librt/sigev_thread.c Sun Jun 30 08:54:41 2013 (r252411) +++ head/lib/librt/sigev_thread.c Sun Jun 30 08:59:33 2013 (r252412) @@ -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 sig 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);