From owner-svn-src-head@FreeBSD.ORG Sat Apr 27 05:01:29 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id DC4B118C; Sat, 27 Apr 2013 05:01:29 +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 BE04F1E39; Sat, 27 Apr 2013 05:01:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r3R51Te4018925; Sat, 27 Apr 2013 05:01:29 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r3R51TMK018923; Sat, 27 Apr 2013 05:01:29 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201304270501.r3R51TMK018923@svn.freebsd.org> From: Ed Schouten Date: Sat, 27 Apr 2013 05:01:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r249969 - head/sbin/hastd X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Apr 2013 05:01:29 -0000 Author: ed Date: Sat Apr 27 05:01:29 2013 New Revision: 249969 URL: http://svnweb.freebsd.org/changeset/base/249969 Log: Use C11 instead of our non-standard . Reviewed by: pjd Modified: head/sbin/hastd/primary.c head/sbin/hastd/refcnt.h Modified: head/sbin/hastd/primary.c ============================================================================== --- head/sbin/hastd/primary.c Sat Apr 27 04:56:02 2013 (r249968) +++ head/sbin/hastd/primary.c Sat Apr 27 05:01:29 2013 (r249969) @@ -78,7 +78,7 @@ struct hio { * kernel. Each component has to decrease this counter by one * even on failure. */ - unsigned int hio_countdown; + refcnt_t hio_countdown; /* * Each component has a place to store its own error. * Once the request is handled by all components we can decide if the @@ -415,7 +415,7 @@ init_environment(struct hast_resource *r "Unable to allocate %zu bytes of memory for hio request.", sizeof(*hio)); } - hio->hio_countdown = 0; + refcnt_init(&hio->hio_countdown, 0); hio->hio_errors = malloc(sizeof(hio->hio_errors[0]) * ncomps); if (hio->hio_errors == NULL) { primary_exitx(EX_TEMPFAIL, @@ -1300,11 +1300,12 @@ ggate_recv_thread(void *arg) } pjdlog_debug(2, "ggate_recv: (%p) Moving request to the send queues.", hio); - hio->hio_countdown = ncomps; if (hio->hio_replication == HAST_REPLICATION_MEMSYNC && ggio->gctl_cmd == BIO_WRITE) { /* Each remote request needs two responses in memsync. */ - hio->hio_countdown++; + refcnt_init(&hio->hio_countdown, ncomps + 1); + } else { + refcnt_init(&hio->hio_countdown, ncomps); } for (ii = ncomp; ii < ncomps; ii++) QUEUE_INSERT1(hio, send, ii); @@ -2139,7 +2140,7 @@ sync_thread(void *arg __unused) ncomp = 1; } mtx_unlock(&metadata_lock); - hio->hio_countdown = 1; + refcnt_init(&hio->hio_countdown, 1); QUEUE_INSERT1(hio, send, ncomp); /* @@ -2189,7 +2190,7 @@ sync_thread(void *arg __unused) pjdlog_debug(2, "sync: (%p) Moving request to the send queue.", hio); - hio->hio_countdown = 1; + refcnt_init(&hio->hio_countdown, 1); QUEUE_INSERT1(hio, send, ncomp); /* Modified: head/sbin/hastd/refcnt.h ============================================================================== --- head/sbin/hastd/refcnt.h Sat Apr 27 04:56:02 2013 (r249968) +++ head/sbin/hastd/refcnt.h Sat Apr 27 05:01:29 2013 (r249969) @@ -32,24 +32,33 @@ #ifndef __REFCNT_H__ #define __REFCNT_H__ -#include +#include #include "pjdlog.h" +typedef atomic_uint refcnt_t; + +static __inline void +refcnt_init(refcnt_t *count, unsigned int v) +{ + + atomic_init(count, v); +} + static __inline void -refcnt_acquire(volatile unsigned int *count) +refcnt_acquire(refcnt_t *count) { - atomic_add_acq_int(count, 1); + atomic_fetch_add_explicit(count, 1, memory_order_acquire); } static __inline unsigned int -refcnt_release(volatile unsigned int *count) +refcnt_release(refcnt_t *count) { unsigned int old; /* XXX: Should this have a rel membar? */ - old = atomic_fetchadd_int(count, -1); + old = atomic_fetch_sub(count, 1); PJDLOG_ASSERT(old > 0); return (old - 1); }