atomic reference counting primatives.
Julian Elischer
julian at elischer.org
Thu May 20 13:56:39 PDT 2004
This has been raised before but I've come across uses for it again and
again so I'm raising it again.
JHB once posted some atomic referenc counting primatives. (Do you still
have them John?)
Alfred once said he had soem somewhere too, and other s have commentted
on this before, but we still don't seem to have any.
every object is reference counted with its own code and
sometimes it's done poorly.
Some peiople indicated that there are cases where a generic refcounter
can not be used and usd this as a reason to not have one at all.
So, here are some possibilities..
my first "write it down without too much thinking" effort..
typedef {mumble} refcnt_t
refcnt_add(refcnt_t *)
Increments the reference count.. no magic except to be atomic.
int refcnt_drop(refcnt *, struct mutex *)
Decrements the refcount. If it goes to 0 it returns 0 and locks the
mutex (if the mutex is supplied)..
refcnt_init(refcnt_t *)
would simply set the counter to 0 if refcnt_t is defined as a simple
type, but could do more if a more complex refcount is used (say for
debugging)
debugging versions of the above might store all sorts of stuff in the
refcount.. (e.g. pid, __LINE__ __FUNCTION__ etc.)
vm->vm_exitingcnt)
If these were in place it would be a first step in
tightennign up some of the reference counting we see in the kernel
and there are several places I've seen over the last few years where
locks are used purely to allow reference counts to be manipulated.
thoughts....?
better ideas?
More information about the freebsd-arch
mailing list