From nobody Thu Oct 28 02:00:28 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 28AE91828F88; Thu, 28 Oct 2021 02:00:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Hfpg10jDjz3MyF; Thu, 28 Oct 2021 02:00:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EC9B41B09F; Thu, 28 Oct 2021 02:00:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19S20Swe032149; Thu, 28 Oct 2021 02:00:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19S20S1h032148; Thu, 28 Oct 2021 02:00:28 GMT (envelope-from git) Date: Thu, 28 Oct 2021 02:00:28 GMT Message-Id: <202110280200.19S20S1h032148@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 840680e601f1 - main - Wrap mutex(9), rwlock(9) and sx(9) macros into __extension__ ({}) instead of do {} while (0). List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 840680e601f15b25abed3fad31399a9ce838f13a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=840680e601f15b25abed3fad31399a9ce838f13a commit 840680e601f15b25abed3fad31399a9ce838f13a Author: Gleb Smirnoff AuthorDate: 2021-10-27 17:33:01 +0000 Commit: Gleb Smirnoff CommitDate: 2021-10-28 01:58:36 +0000 Wrap mutex(9), rwlock(9) and sx(9) macros into __extension__ ({}) instead of do {} while (0). This makes them real void expressions, and they can be used anywhere where a void function call can be used, for example in a conditional operator. Reviewed by: kib, mjg Differential revision: https://reviews.freebsd.org/D32696 --- sys/sys/mutex.h | 28 ++++++++++++++++------------ sys/sys/rwlock.h | 15 +++++++++------ sys/sys/sx.h | 5 +++-- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h index f35cdd7413a6..04e2c823541a 100644 --- a/sys/sys/mutex.h +++ b/sys/sys/mutex.h @@ -236,14 +236,15 @@ void _thread_lock(struct thread *); */ /* Lock a normal mutex. */ -#define __mtx_lock(mp, tid, opts, file, line) do { \ +#define __mtx_lock(mp, tid, opts, file, line) __extension__ ({ \ uintptr_t _tid = (uintptr_t)(tid); \ uintptr_t _v = MTX_UNOWNED; \ \ if (__predict_false(LOCKSTAT_PROFILE_ENABLED(adaptive__acquire) ||\ !_mtx_obtain_lock_fetch((mp), &_v, _tid))) \ _mtx_lock_sleep((mp), _v, (opts), (file), (line)); \ -} while (0) + (void)0; /* ensure void type for expression */ \ +}) /* * Lock a spin mutex. For spinlocks, we handle recursion inline (it @@ -252,7 +253,7 @@ void _thread_lock(struct thread *); * inlining this code is not too big a deal. */ #ifdef SMP -#define __mtx_lock_spin(mp, tid, opts, file, line) do { \ +#define __mtx_lock_spin(mp, tid, opts, file, line) __extension__ ({ \ uintptr_t _tid = (uintptr_t)(tid); \ uintptr_t _v = MTX_UNOWNED; \ \ @@ -260,7 +261,8 @@ void _thread_lock(struct thread *); if (__predict_false(LOCKSTAT_PROFILE_ENABLED(spin__acquire) || \ !_mtx_obtain_lock_fetch((mp), &_v, _tid))) \ _mtx_lock_spin((mp), _v, (opts), (file), (line)); \ -} while (0) + (void)0; /* ensure void type for expression */ \ +}) #define __mtx_trylock_spin(mp, tid, opts, file, line) __extension__ ({ \ uintptr_t _tid = (uintptr_t)(tid); \ int _ret; \ @@ -277,7 +279,7 @@ void _thread_lock(struct thread *); _ret; \ }) #else /* SMP */ -#define __mtx_lock_spin(mp, tid, opts, file, line) do { \ +#define __mtx_lock_spin(mp, tid, opts, file, line) __extension__ ({ \ uintptr_t _tid = (uintptr_t)(tid); \ \ spinlock_enter(); \ @@ -287,7 +289,8 @@ void _thread_lock(struct thread *); KASSERT((mp)->mtx_lock == MTX_UNOWNED, ("corrupt spinlock")); \ (mp)->mtx_lock = _tid; \ } \ -} while (0) + (void)0; /* ensure void type for expression */ \ +}) #define __mtx_trylock_spin(mp, tid, opts, file, line) __extension__ ({ \ uintptr_t _tid = (uintptr_t)(tid); \ int _ret; \ @@ -305,13 +308,14 @@ void _thread_lock(struct thread *); #endif /* SMP */ /* Unlock a normal mutex. */ -#define __mtx_unlock(mp, tid, opts, file, line) do { \ +#define __mtx_unlock(mp, tid, opts, file, line) __extension__ ({ \ uintptr_t _v = (uintptr_t)(tid); \ \ if (__predict_false(LOCKSTAT_PROFILE_ENABLED(adaptive__release) ||\ !_mtx_release_lock_fetch((mp), &_v))) \ _mtx_unlock_sleep((mp), _v, (opts), (file), (line)); \ -} while (0) + (void)0; /* ensure void type for expression */ \ +}) /* * Unlock a spin mutex. For spinlocks, we can handle everything @@ -324,7 +328,7 @@ void _thread_lock(struct thread *); * releasing a spin lock. This includes the recursion cases. */ #ifdef SMP -#define __mtx_unlock_spin(mp) do { \ +#define __mtx_unlock_spin(mp) __extension__ ({ \ if (mtx_recursed((mp))) \ (mp)->mtx_recurse--; \ else { \ @@ -332,9 +336,9 @@ void _thread_lock(struct thread *); _mtx_release_lock_quick((mp)); \ } \ spinlock_exit(); \ -} while (0) +}) #else /* SMP */ -#define __mtx_unlock_spin(mp) do { \ +#define __mtx_unlock_spin(mp) __extension__ ({ \ if (mtx_recursed((mp))) \ (mp)->mtx_recurse--; \ else { \ @@ -342,7 +346,7 @@ void _thread_lock(struct thread *); (mp)->mtx_lock = MTX_UNOWNED; \ } \ spinlock_exit(); \ -} while (0) +}) #endif /* SMP */ /* diff --git a/sys/sys/rwlock.h b/sys/sys/rwlock.h index 4e7768595737..99e885e07aaf 100644 --- a/sys/sys/rwlock.h +++ b/sys/sys/rwlock.h @@ -103,23 +103,25 @@ */ /* Acquire a write lock. */ -#define __rw_wlock(rw, tid, file, line) do { \ +#define __rw_wlock(rw, tid, file, line) __extension__ ({ \ uintptr_t _tid = (uintptr_t)(tid); \ uintptr_t _v = RW_UNLOCKED; \ \ if (__predict_false(LOCKSTAT_PROFILE_ENABLED(rw__acquire) || \ !_rw_write_lock_fetch((rw), &_v, _tid))) \ _rw_wlock_hard((rw), _v, (file), (line)); \ -} while (0) + (void)0; /* ensure void type for expression */ \ +}) /* Release a write lock. */ -#define __rw_wunlock(rw, tid, file, line) do { \ +#define __rw_wunlock(rw, tid, file, line) __extension__ ({ \ uintptr_t _v = (uintptr_t)(tid); \ \ if (__predict_false(LOCKSTAT_PROFILE_ENABLED(rw__release) || \ !_rw_write_unlock_fetch((rw), &_v))) \ _rw_wunlock_hard((rw), _v, (file), (line)); \ -} while (0) + (void)0; /* ensure void type for expression */ \ +}) /* * Function prototypes. Routines that start with _ are not part of the @@ -231,12 +233,13 @@ void __rw_assert(const volatile uintptr_t *c, int what, const char *file, #define rw_try_upgrade(rw) _rw_try_upgrade((rw), LOCK_FILE, LOCK_LINE) #define rw_try_wlock(rw) _rw_try_wlock((rw), LOCK_FILE, LOCK_LINE) #define rw_downgrade(rw) _rw_downgrade((rw), LOCK_FILE, LOCK_LINE) -#define rw_unlock(rw) do { \ +#define rw_unlock(rw) __extension__ ({ \ if (rw_wowned(rw)) \ rw_wunlock(rw); \ else \ rw_runlock(rw); \ -} while (0) + (void)0; /* ensure void type for expression */ \ +}) #define rw_sleep(chan, rw, pri, wmesg, timo) \ _sleep((chan), &(rw)->lock_object, (pri), (wmesg), \ tick_sbt * (timo), 0, C_HARDCLOCK) diff --git a/sys/sys/sx.h b/sys/sys/sx.h index 1e6b9f3f8a46..bd164a96558b 100644 --- a/sys/sys/sx.h +++ b/sys/sys/sx.h @@ -253,12 +253,13 @@ __sx_xunlock(struct sx *sx, struct thread *td, const char *file, int line) (((sx)->sx_lock & ~(SX_LOCK_FLAGMASK & ~SX_LOCK_SHARED)) == \ (uintptr_t)curthread) -#define sx_unlock_(sx, file, line) do { \ +#define sx_unlock_(sx, file, line) __extension__ ({ \ if (sx_xlocked(sx)) \ sx_xunlock_(sx, file, line); \ else \ sx_sunlock_(sx, file, line); \ -} while (0) + (void)0; /* ensure void type for expression */ \ +}) #define sx_unlock(sx) sx_unlock_((sx), LOCK_FILE, LOCK_LINE)