From 940cb7ce163664778f7055953392fb43d5fc31fc Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 15 Jun 2009 18:57:45 +0100 Subject: gallium: Ensure assert macro is defined before being used in p_thread.h --- src/gallium/include/pipe/p_thread.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium/include') diff --git a/src/gallium/include/pipe/p_thread.h b/src/gallium/include/pipe/p_thread.h index de55e99ed4..ce8d79549a 100644 --- a/src/gallium/include/pipe/p_thread.h +++ b/src/gallium/include/pipe/p_thread.h @@ -36,6 +36,7 @@ #include "pipe/p_compiler.h" +#include "util/u_debug.h" /* for assert */ #if defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD) || defined(PIPE_OS_SOLARIS) -- cgit v1.2.3 From 3463b1479d1c70e3b23189c72132e9ad5f710ff9 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 16 Jun 2009 13:05:25 +0100 Subject: gallium: Avoid atomic ops / locking when src is dst. --- src/gallium/include/pipe/p_refcnt.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/gallium/include') diff --git a/src/gallium/include/pipe/p_refcnt.h b/src/gallium/include/pipe/p_refcnt.h index 1f89453e09..1f9088b3e9 100644 --- a/src/gallium/include/pipe/p_refcnt.h +++ b/src/gallium/include/pipe/p_refcnt.h @@ -62,29 +62,29 @@ pipe_is_referenced(struct pipe_reference *reference) * Set 'ptr' to point to 'reference' and update reference counting. * The old thing pointed to, if any, will be unreferenced first. * 'reference' may be NULL. - * - * XXX: thread safety issues! */ static INLINE bool pipe_reference(struct pipe_reference **ptr, struct pipe_reference *reference) { bool destroy = FALSE; - /* bump the reference.count first */ - if (reference) { - assert(pipe_is_referenced(reference)); - p_atomic_inc(&reference->count); - } - - if (*ptr) { - assert(pipe_is_referenced(*ptr)); - if (p_atomic_dec_zero(&(*ptr)->count)) { - destroy = TRUE; + if(*ptr != reference) { + /* bump the reference.count first */ + if (reference) { + assert(pipe_is_referenced(reference)); + p_atomic_inc(&reference->count); } + + if (*ptr) { + assert(pipe_is_referenced(*ptr)); + if (p_atomic_dec_zero(&(*ptr)->count)) { + destroy = TRUE; + } + } + + *ptr = reference; } - *ptr = reference; - return destroy; } -- cgit v1.2.3