reference counting.. continued..

From: Julian Elischer (julian_at_elischer.org)
Date: 06/09/04

  • Next message: Pawel Jakub Dawidek: "Re: cvs commit: src/sys/kern kern_proc.c"
    Date: Wed, 9 Jun 2004 11:35:40 -0700 (PDT)
    To: arch@freebsd.org
    
    

    There are several goals that need to be kept in mind.

     * Operations should be quick..
     * Atomic operations can be slow in some architectures.
     * the last free may need to occur at an inconvenient time.
       (in sched-lock or an interrupt routine).
     * There may need to be more than one kind of schedlock,
       for different cases, though I'd hope that they'd have the same
       methods..
        (A reference count scheme that doesn't have to ever consider the
        fact that the object may be freed in an interrupt handler
        might be considereably smaller/quicker than one that needs to
        take that possibility into account. )

    Here's an API I mentionned once before.. I'm only showing this as an
    example to start discussion...
    it doesn't cover everything we'd need..

    For example how would you do deferred free?

    ------------------quoted old email------------------

    I have seen and liked
    a refcount API which was (from memory something like):

    void * refcnt_add(offsetof(struct obj, refcnt), void ** object_p)

    which takes a pointer to the object pointer you are copying, and
    atomically increments it and returns the contents of the pointer.
    If the contents of the pointer are NULL, then it returns NULL
    and doesn't increment anything..

    The reference decrement atomically reduced the reference count and
    zapped the pointer, and retunred a copy of the pointer if
    the reference count had gone to 0 (or NULL if not).

    So usage was:
    struct xx *globalpointer; /* has its own owner somewhere */

            mypointer = refcnt_add(offsetof(xx, refcnt), globalptr)
            if (mypointer == NULL) {
                    printf("didn't find an object\n"
                    return (-1);

            }
            manipulate(mypointer)
            if ((tmppointer = refcnt_drop(&mypointer, &globalpointer))) {
                    free(tmppointer);
            }

    someone else who owns the globalpointer reference might might in
    the meanwhile do:

    if ((tmppointer = refcnt_drop(globalpointer->refcnt, &globalpointer))) {
            free(tmppointer);
    }

    and you were guaranteed to get a predictable result.

    _______________________________________________
    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: Pawel Jakub Dawidek: "Re: cvs commit: src/sys/kern kern_proc.c"

    Relevant Pages

    • Re: Question on LSP
      ... Sure, the developer must keep track of which type has been assigned to each pointer to manage complexity in creating the design, which is why the 'T' is in T*. ... Subtyping is a relation which does not ... Those object types are completely orthogonal to the semantics of being an object reference. ... aggregate references, is the aggregate of referenced objects or target ...
      (comp.object)
    • Re: Question on LSP
      ... Because construction paradigms have different goals. ... But that has nothing to do with what a pointer type ... But that does not mean that the semantics of an object reference is ... aggregate references, is the aggregate of referenced objects or target ...
      (comp.object)
    • Re: Question on LSP
      ... equivalent addresses in the same context. ... Note that the language allows us to use a name like 'T' on the reference as a mnemonic so that the developer can keep track of what is happening with the indirection. ... Modern languages have proper pointer types. ...
      (comp.object)
    • Re: Nothing Keyword Destories Objects rather than just resetting the variable to an empty variable
      ... there is no difference between using ByVal or ByRef. ... as the C1 pointer was the sole reference to the class object. ... Yes, an object variable is a pointer to an object, but that is the only ... the keyword "NOTHING" should only destroy the ...
      (microsoft.public.excel.programming)
    • Re: How java passes object references?
      ... to think of them as being a specific location in a larger block of memory ... Whether a language passes by reference or by value, ... is a pointer pointing at the memory block. ... So when allocating local memory for o, it would simply allocate a ...
      (comp.lang.java.programmer)