atomic reference counting primatives.

From: Julian Elischer (julian_at_elischer.org)
Date: 05/20/04

  • Next message: Andre Oppermann: "Re: Network Stack Locking"
    Date: Thu, 20 May 2004 13:56:36 -0700 (PDT)
    To: arch@freebsd.org
    
    

    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?

    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"


  • Next message: Andre Oppermann: "Re: Network Stack Locking"

    Relevant Pages