Re: cvs commit: src/sys/kern kern_proc.c

From: Pawel Jakub Dawidek (pjd_at_FreeBSD.org)
Date: 06/09/04

  • Next message: Poul-Henning Kamp: "Re: reference counting.. continued.."
    Date: Wed, 9 Jun 2004 20:37:03 +0200
    To: Julian Elischer <julian@elischer.org>
    
    
    

    On Wed, Jun 09, 2004 at 11:23:48AM -0700, Julian Elischer wrote:
    +> I do actually agree that a general purpose reference counting
    +> API is very difficult to use in every situation and that there
    +> are situations where you just HAVE to roll your own..

    Maybe we can use macros to do this, something like:

    #define REFCNT_MTX(foo, prefix, type, mtx_field, refcnt_field, destroy_func) \
    foo void \
    prefix ## _hold(type *obj) \
    { \
                                                                            \
            mtx_lock(&obj->mtx_field); \
            obj->refcnt_field++; \
            mtx_unlock(&obj->mtx_field); \
    } \
                                                                            \
    foo void \
    prefix ## _free(type *obj) \
    { \
            int refcnt; \
                                                                            \
            mtx_lock(&obj->mtx_field); \
            refcnt = --obj->refcnt_field; \
            mtx_unlock(&obj->mtx_field); \
            if (refcnt == 0) \
                    destroy_func(obj); \
    }

    And the same for REFCNT_ATOMIC() and REFCNT_SPIN()?
    'foo' could be for example 'static' or 'static __inline'.

    -- 
    Pawel Jakub Dawidek                       http://www.FreeBSD.org
    pjd@FreeBSD.org                           http://garage.freebsd.pl
    FreeBSD committer                         Am I Evil? Yes, I Am!
    
    



  • Next message: Poul-Henning Kamp: "Re: reference counting.. continued.."