From 35a15f02634a31c1517363d91aaef8f190e24687 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Thu, 3 Dec 2009 23:15:38 +0100 Subject: gallium: fix reference counting functions to be strict-aliasing compliant Historically, parts of mesa code are not strict-aliasing safe, hence -fno-strict-aliasing is needed to compile (this got forgotten for scons builds for gallium, which indeed not only caused compiler warnings but also unexplicable crashes in non-debug builds). However, we should try to eliminate code not complying with strict-aliasing code at least for gallium. Hence change pipe_reference functions to make them strict-aliasing compliant. This adds a bit more complexity (especially for derived classes) but is the right thing to do, and it does in fact fix a segfault. --- src/gallium/include/pipe/p_refcnt.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/gallium/include/pipe/p_refcnt.h') diff --git a/src/gallium/include/pipe/p_refcnt.h b/src/gallium/include/pipe/p_refcnt.h index 1f9088b3e9..f1875b6b82 100644 --- a/src/gallium/include/pipe/p_refcnt.h +++ b/src/gallium/include/pipe/p_refcnt.h @@ -59,30 +59,28 @@ 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. + * Update reference counting. + * The old thing pointed to, if any, will be unreferenced. + * Both 'ptr' and 'reference' may be NULL. */ static INLINE bool -pipe_reference(struct pipe_reference **ptr, struct pipe_reference *reference) +pipe_reference(struct pipe_reference *ptr, struct pipe_reference *reference) { bool destroy = FALSE; - if(*ptr != reference) { + 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)) { + if (ptr) { + assert(pipe_is_referenced(ptr)); + if (p_atomic_dec_zero(&ptr->count)) { destroy = TRUE; } } - - *ptr = reference; } return destroy; -- cgit v1.2.3 From fd7a9ec7f97d540d22f546d96c3d1c808f163bba Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Tue, 8 Dec 2009 17:42:49 +0100 Subject: gallium: use boolean instead of bool in p_refcnt.h all code in gallium should use boolean not bool --- src/gallium/include/pipe/p_refcnt.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gallium/include/pipe/p_refcnt.h') diff --git a/src/gallium/include/pipe/p_refcnt.h b/src/gallium/include/pipe/p_refcnt.h index f1875b6b82..e252f55900 100644 --- a/src/gallium/include/pipe/p_refcnt.h +++ b/src/gallium/include/pipe/p_refcnt.h @@ -51,7 +51,7 @@ pipe_reference_init(struct pipe_reference *reference, unsigned count) } -static INLINE bool +static INLINE boolean pipe_is_referenced(struct pipe_reference *reference) { return p_atomic_read(&reference->count) != 0; @@ -63,10 +63,10 @@ pipe_is_referenced(struct pipe_reference *reference) * The old thing pointed to, if any, will be unreferenced. * Both 'ptr' and 'reference' may be NULL. */ -static INLINE bool +static INLINE boolean pipe_reference(struct pipe_reference *ptr, struct pipe_reference *reference) { - bool destroy = FALSE; + boolean destroy = FALSE; if(ptr != reference) { /* bump the reference.count first */ -- cgit v1.2.3 From 4430a05a3a65c411996a923d1051bb7879204a53 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 11 Dec 2009 16:50:25 -0700 Subject: gallium: added comment for pipe_reference() return value --- src/gallium/include/pipe/p_refcnt.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium/include/pipe/p_refcnt.h') diff --git a/src/gallium/include/pipe/p_refcnt.h b/src/gallium/include/pipe/p_refcnt.h index e252f55900..c1c7415e02 100644 --- a/src/gallium/include/pipe/p_refcnt.h +++ b/src/gallium/include/pipe/p_refcnt.h @@ -62,6 +62,7 @@ pipe_is_referenced(struct pipe_reference *reference) * Update reference counting. * The old thing pointed to, if any, will be unreferenced. * Both 'ptr' and 'reference' may be NULL. + * \return TRUE if the object's refcount hits zero and should be destroyed. */ static INLINE boolean pipe_reference(struct pipe_reference *ptr, struct pipe_reference *reference) -- cgit v1.2.3