diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2022-03-16 14:13:02 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2022-03-16 14:13:02 +0000 |
commit | 4defa17785a08f6a628a5a171283148594c5ff0f (patch) | |
tree | f70a173813c596bd32bed13f53b1e6622b7290c2 /sys/kern | |
parent | a854baef1d2ef3a7acb26f7475302c84bc02b5fd (diff) |
Add refcnt_shared() and refcnt_read()
refcnt_shared() checks whether the object has multiple references.
When refcnt_shared() returns zero, the caller is the only reference
holder.
refcnt_read() returns a snapshot of the counter value.
refcnt_shared() suggested by dlg@.
OK dlg@ mvs@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_synch.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 27e36501ae9..e877acff824 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_synch.c,v 1.183 2022/03/10 15:21:08 bluhm Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.184 2022/03/16 14:13:01 visa Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /* @@ -852,6 +852,18 @@ refcnt_finalize(struct refcnt *r, const char *wmesg) } } +int +refcnt_shared(struct refcnt *r) +{ + return (atomic_load_int(&r->r_refs) > 1); +} + +unsigned int +refcnt_read(struct refcnt *r) +{ + return (atomic_load_int(&r->r_refs)); +} + void cond_init(struct cond *c) { |