Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Mar 2002 12:10:36 -0800 (PST)
From:      Julian Elischer <julian@elischer.org>
To:        arch@freebsd.org
Cc:        smp@freeBSD.org
Subject:   SMP safe reference counting
Message-ID:  <Pine.BSF.4.21.0203271150430.47944-100000@InterJet.elischer.org>

next in thread | raw e-mail | index | archive | help

[please remove -smp from your reply]

Once again on the SMP list a lock is being used to make a reference count 
safe. I'd like to re-raise the issue of a safe reference counting 
fascility.

what would be the semantics?

typedef	volatile u_int ref_cnt;
typedef void ref_free(void *);

reference_add(ref_cnt *);
reference_drop(ref_cnt *, ref_free *, void *);





__inline void
reference_add(ref_cnt *cnt) {
	atomic_inc(cnt);
}

/* Note I use the non-existing "atomic_inc()". I think
we should have this as its SO COMMONLY used. */

__inline void
reference_drop(ref_cnt *cnt, ref_free *fn. void * arg) {
        int newcount;
	int oldcount;

	do {
	        newcount = (oldcount = *cnt) - 1;
	} while (atomic_cmp_and_set(cnt, oldcount, newcount) == ACS_FAILED);
}
/* I can't remember off the top of my head the cmp-and-set command */



 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-smp" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0203271150430.47944-100000>