Hi, Make sure we do not run into the classic ABA problem on buffer object bind, reusing this name and may be never rebind since we get an new name that was just deleted and never rebound in between. The explicit rebinding to the debault object in the current context prevents the above in the current context, but an other context sharing the same objects might suffer from this problem.
Please review. Thanks Mathias
From 7ea3cd2c3ddb4c2d04902d70a4e923f302cb7b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Fr=C3=B6hlich?= <[email protected]> Date: Sat, 22 Oct 2011 11:55:36 +0200 Subject: [PATCH 1/2] mesa: Avoid ABA problem on buffer object bind. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure we do not run into the classic ABA problem on buffer object bind, reusing this name and may be never rebind since we get an new name that was just deleted and never rebound in between. The explicit rebinding to the debault object in the current context prevents the above in the current context, but an other context sharing the same objects might suffer from this problem. Signed-off-by: Mathias Fröhlich <[email protected]> --- src/mesa/main/bufferobj.c | 12 +++++++++++- src/mesa/main/mtypes.h | 1 + 2 files changed, 12 insertions(+), 1 deletions(-) diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 431eafd..437adb5 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -571,7 +571,7 @@ bind_buffer_object(struct gl_context *ctx, GLenum target, GLuint buffer) /* Get pointer to old buffer object (to be unbound) */ oldBufObj = *bindTarget; - if (oldBufObj && oldBufObj->Name == buffer) + if (oldBufObj && oldBufObj->Name == buffer && !oldBufObj->Deleted) return; /* rebinding the same buffer object- no change */ /* @@ -773,6 +773,16 @@ _mesa_DeleteBuffersARB(GLsizei n, const GLuint *ids) /* The ID is immediately freed for re-use */ _mesa_HashRemove(ctx->Shared->BufferObjects, ids[i]); + /* Make sure we do not run into the classic ABA problem on bind, + reusing this name and may be never rebind since we get an new name + that was just deleted and never rebound in between. + The explicit rebinding to the debault object in the current context + prevents the above in the current context, but an other context + sharing the same objects might suffer from this problem. + The alternative would be to do the hash lookup in any case on bind + which would introduce more runtime overhead than this. + */ + bufObj->Deleted = GL_TRUE; _mesa_reference_buffer_object(ctx, &bufObj, NULL); } } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 17c645a..d15d660 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1535,6 +1535,7 @@ struct gl_buffer_object GLintptr Offset; /**< Mapped offset */ GLsizeiptr Length; /**< Mapped length */ /*@}*/ + GLboolean Deleted; /**< true if buffer object is removed from the hash */ GLboolean Written; /**< Ever written to? (for debugging) */ GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */ }; -- 1.7.4.4
_______________________________________________ mesa-dev mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/mesa-dev
