git: abb1a1340e3f - main - linuxkpi: refcount: Use atomic_t directly
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 16 May 2024 07:41:26 UTC
The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=abb1a1340e3f0dcdbb81b5c42ad304f02c812e20 commit abb1a1340e3f0dcdbb81b5c42ad304f02c812e20 Author: Emmanuel Vadot <manu@FreeBSD.org> AuthorDate: 2024-05-15 09:50:51 +0000 Commit: Emmanuel Vadot <manu@FreeBSD.org> CommitDate: 2024-05-16 07:40:46 +0000 linuxkpi: refcount: Use atomic_t directly Simply use a typedef for refcount_t on atomic_t, this allow us to use a nativ type and also changing struct kref to directly use a refcount_t like Linux. Reviewed by: bz Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D45207 --- sys/compat/linuxkpi/common/include/linux/kref.h | 3 +-- .../linuxkpi/common/include/linux/refcount.h | 23 ++++++++-------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/kref.h b/sys/compat/linuxkpi/common/include/linux/kref.h index 47d61c9ee316..b2fba468f7df 100644 --- a/sys/compat/linuxkpi/common/include/linux/kref.h +++ b/sys/compat/linuxkpi/common/include/linux/kref.h @@ -41,8 +41,7 @@ #include <asm/atomic.h> struct kref { - /* XXX In Linux this is a refcount_t */ - atomic_t refcount; + refcount_t refcount; }; static inline void diff --git a/sys/compat/linuxkpi/common/include/linux/refcount.h b/sys/compat/linuxkpi/common/include/linux/refcount.h index 61947485945d..02a7eda3f4a9 100644 --- a/sys/compat/linuxkpi/common/include/linux/refcount.h +++ b/sys/compat/linuxkpi/common/include/linux/refcount.h @@ -31,58 +31,51 @@ #include <linux/atomic.h> -struct refcount_linux { - atomic_t value; -}; -typedef struct refcount_linux refcount_t; +typedef atomic_t refcount_t; static inline void refcount_set(refcount_t *ref, unsigned int i) { - atomic_set(&ref->value, i); + atomic_set(ref, i); } static inline void refcount_inc(refcount_t *ref) { - atomic_inc(&ref->value); + atomic_inc(ref); } static inline bool refcount_inc_not_zero(refcount_t *ref) { - return (atomic_inc_not_zero(&ref->value)); + return (atomic_inc_not_zero(ref)); } static inline void refcount_dec(refcount_t *ref) { - atomic_dec(&ref->value); + atomic_dec(ref); } static inline unsigned int refcount_read(refcount_t *ref) { - return atomic_read(&ref->value); + return atomic_read(ref); } static inline bool refcount_dec_and_lock_irqsave(refcount_t *ref, spinlock_t *lock, unsigned long *flags) { - if (atomic_dec_and_test(&ref->value) == true) { + if (atomic_dec_and_test(ref) == true) { spin_lock_irqsave(lock, flags); return (true); } return (false); } -/* - * struct kref uses atomic_t and not refcount_t so - * we differ from Linux here. - */ static inline bool -refcount_dec_and_test(atomic_t *r) +refcount_dec_and_test(refcount_t *r) { return (atomic_dec_and_test(r));