---
 src/mesa/main/mtypes.h |  1 -
 src/mesa/main/texobj.c | 19 ++++---------------
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 5a1be17a92..a1eabc8bf1 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -995,7 +995,6 @@ struct gl_sampler_object
  */
 struct gl_texture_object
 {
-   mtx_t Mutex;      /**< for thread safety */
    GLint RefCount;             /**< reference count */
    GLuint Name;                /**< the user-visible texture object ID */
    GLchar *Label;               /**< GL_KHR_debug */
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index ad644ca1ca..4afa7d8fb2 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -43,6 +43,7 @@
 #include "texstate.h"
 #include "mtypes.h"
 #include "program/prog_instruction.h"
+#include "util/u_atomic.h"
 
 
 
@@ -270,7 +271,6 @@ _mesa_initialize_texture_object( struct gl_context *ctx,
 
    memset(obj, 0, sizeof(*obj));
    /* init the non-zero fields */
-   mtx_init(&obj->Mutex, mtx_plain);
    obj->RefCount = 1;
    obj->Name = name;
    obj->Target = target;
@@ -399,9 +399,6 @@ _mesa_delete_texture_object(struct gl_context *ctx,
 
    _mesa_reference_buffer_object(ctx, &texObj->BufferObject, NULL);
 
-   /* destroy the mutex -- it may have allocated memory (eg on bsd) */
-   mtx_destroy(&texObj->Mutex);
-
    free(texObj->Label);
 
    /* free this object */
@@ -534,20 +531,14 @@ _mesa_reference_texobj_(struct gl_texture_object **ptr,
 
    if (*ptr) {
       /* Unreference the old texture */
-      GLboolean deleteFlag = GL_FALSE;
       struct gl_texture_object *oldTex = *ptr;
 
       assert(valid_texture_object(oldTex));
       (void) valid_texture_object; /* silence warning in release builds */
 
-      mtx_lock(&oldTex->Mutex);
       assert(oldTex->RefCount > 0);
-      oldTex->RefCount--;
-
-      deleteFlag = (oldTex->RefCount == 0);
-      mtx_unlock(&oldTex->Mutex);
 
-      if (deleteFlag) {
+      if (p_atomic_dec_zero(&oldTex->RefCount)) {
          /* Passing in the context drastically changes the driver code for
           * framebuffer deletion.
           */
@@ -565,18 +556,16 @@ _mesa_reference_texobj_(struct gl_texture_object **ptr,
    if (tex) {
       /* reference new texture */
       assert(valid_texture_object(tex));
-      mtx_lock(&tex->Mutex);
-      if (tex->RefCount == 0) {
+      if (p_atomic_read(&tex->RefCount) == 0) {
          /* this texture's being deleted (look just above) */
          /* Not sure this can every really happen.  Warn if it does. */
          _mesa_problem(NULL, "referencing deleted texture object");
          *ptr = NULL;
       }
       else {
-         tex->RefCount++;
+         p_atomic_inc(&tex->RefCount);
          *ptr = tex;
       }
-      mtx_unlock(&tex->Mutex);
    }
 }
 
-- 
2.12.2

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to