[Mesa-dev] [PATCH 1/4] mesa: remove fallback RefCount == 0 pattern

Timothy Arceri tarceri at itsqueeze.com
Fri Apr 21 05:20:52 UTC 2017


We should never get here if this is 0 unless there is a
bug. Replace the check with an assert.
---
 src/mesa/main/arrayobj.c          | 14 ++++----------
 src/mesa/main/bufferobj.c         | 14 ++++----------
 src/mesa/main/pipelineobj.c       | 14 ++++----------
 src/mesa/main/samplerobj.c        | 14 ++++----------
 src/mesa/main/texobj.c            | 14 ++++----------
 src/mesa/main/transformfeedback.c | 14 +++++---------
 6 files changed, 25 insertions(+), 59 deletions(-)

diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index ab1b834..fdb3caa 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -201,30 +201,24 @@ _mesa_reference_vao_(struct gl_context *ctx,
       if (deleteFlag)
          _mesa_delete_vao(ctx, oldObj);
 
       *ptr = NULL;
    }
    assert(!*ptr);
 
    if (vao) {
       /* reference new array object */
       mtx_lock(&vao->Mutex);
-      if (vao->RefCount == 0) {
-         /* this array's being deleted (look just above) */
-         /* Not sure this can every really happen.  Warn if it does. */
-         _mesa_problem(NULL, "referencing deleted array object");
-         *ptr = NULL;
-      }
-      else {
-         vao->RefCount++;
-         *ptr = vao;
-      }
+      assert(vao->RefCount > 0);
+
+      vao->RefCount++;
+      *ptr = vao;
       mtx_unlock(&vao->Mutex);
    }
 }
 
 
 /**
  * Initialize attribtes of a vertex array within a vertex array object.
  * \param vao  the container vertex array object
  * \param index  which array in the VAO to initialize
  * \param size  number of components (1, 2, 3 or 4) per attribute
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index 922c7d8..961871c 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -504,30 +504,24 @@ _mesa_reference_buffer_object_(struct gl_context *ctx,
          ctx->Driver.DeleteBuffer(ctx, oldObj);
       }
 
       *ptr = NULL;
    }
    assert(!*ptr);
 
    if (bufObj) {
       /* reference new buffer */
       mtx_lock(&bufObj->Mutex);
-      if (bufObj->RefCount == 0) {
-         /* this buffer's being deleted (look just above) */
-         /* Not sure this can every really happen.  Warn if it does. */
-         _mesa_problem(NULL, "referencing deleted buffer object");
-         *ptr = NULL;
-      }
-      else {
-         bufObj->RefCount++;
-         *ptr = bufObj;
-      }
+      assert(bufObj->RefCount > 0);
+
+      bufObj->RefCount++;
+      *ptr = bufObj;
       mtx_unlock(&bufObj->Mutex);
    }
 }
 
 
 /**
  * Get the value of MESA_NO_MINMAX_CACHE.
  */
 static bool
 get_no_minmax_cache()
diff --git a/src/mesa/main/pipelineobj.c b/src/mesa/main/pipelineobj.c
index c1dd8d7..2988c97 100644
--- a/src/mesa/main/pipelineobj.c
+++ b/src/mesa/main/pipelineobj.c
@@ -199,30 +199,24 @@ _mesa_reference_pipeline_object_(struct gl_context *ctx,
          _mesa_delete_pipeline_object(ctx, oldObj);
       }
 
       *ptr = NULL;
    }
    assert(!*ptr);
 
    if (obj) {
       /* reference new pipeline object */
       mtx_lock(&obj->Mutex);
-      if (obj->RefCount == 0) {
-         /* this pipeline's being deleted (look just above) */
-         /* Not sure this can ever really happen.  Warn if it does. */
-         _mesa_problem(NULL, "referencing deleted pipeline object");
-         *ptr = NULL;
-      }
-      else {
-         obj->RefCount++;
-         *ptr = obj;
-      }
+      assert(obj->RefCount > 0);
+
+      obj->RefCount++;
+      *ptr = obj;
       mtx_unlock(&obj->Mutex);
    }
 }
 
 static void
 use_program_stage(struct gl_context *ctx, GLenum type,
                   struct gl_shader_program *shProg,
                   struct gl_pipeline_object *pipe) {
    gl_shader_stage stage = _mesa_shader_enum_to_shader_stage(type);
    struct gl_program *prog = NULL;
diff --git a/src/mesa/main/samplerobj.c b/src/mesa/main/samplerobj.c
index 183f1d2..63beaf1 100644
--- a/src/mesa/main/samplerobj.c
+++ b/src/mesa/main/samplerobj.c
@@ -90,30 +90,24 @@ _mesa_reference_sampler_object_(struct gl_context *ctx,
       if (deleteFlag)
          delete_sampler_object(ctx, oldSamp);
 
       *ptr = NULL;
    }
    assert(!*ptr);
 
    if (samp) {
       /* reference new sampler */
       mtx_lock(&samp->Mutex);
-      if (samp->RefCount == 0) {
-         /* this sampler's being deleted (look just above) */
-         /* Not sure this can every really happen.  Warn if it does. */
-         _mesa_problem(NULL, "referencing deleted sampler object");
-         *ptr = NULL;
-      }
-      else {
-         samp->RefCount++;
-         *ptr = samp;
-      }
+      assert(samp->RefCount > 0);
+
+      samp->RefCount++;
+      *ptr = samp;
       mtx_unlock(&samp->Mutex);
    }
 }
 
 
 /**
  * Initialize the fields of the given sampler object.
  */
 static void
 _mesa_init_sampler_object(struct gl_sampler_object *sampObj, GLuint name)
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 00feb97..af9baa9 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -559,30 +559,24 @@ _mesa_reference_texobj_(struct gl_texture_object **ptr,
       }
 
       *ptr = NULL;
    }
    assert(!*ptr);
 
    if (tex) {
       /* reference new texture */
       assert(valid_texture_object(tex));
       mtx_lock(&tex->Mutex);
-      if (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++;
-         *ptr = tex;
-      }
+      assert(tex->RefCount > 0);
+
+      tex->RefCount++;
+      *ptr = tex;
       mtx_unlock(&tex->Mutex);
    }
 }
 
 
 enum base_mipmap { BASE, MIPMAP };
 
 
 /**
  * Mark a texture object as incomplete.  There are actually three kinds of
diff --git a/src/mesa/main/transformfeedback.c b/src/mesa/main/transformfeedback.c
index 96f3df1..131014f 100644
--- a/src/mesa/main/transformfeedback.c
+++ b/src/mesa/main/transformfeedback.c
@@ -103,30 +103,26 @@ reference_transform_feedback_object(struct gl_transform_feedback_object **ptr,
          GET_CURRENT_CONTEXT(ctx);
          if (ctx)
             ctx->Driver.DeleteTransformFeedback(ctx, oldObj);
       }
 
       *ptr = NULL;
    }
    assert(!*ptr);
 
    if (obj) {
+      assert(obj->RefCount > 0);
+
       /* reference new object */
-      if (obj->RefCount == 0) {
-         _mesa_problem(NULL, "referencing deleted transform feedback object");
-         *ptr = NULL;
-      }
-      else {
-         obj->RefCount++;
-         obj->EverBound = GL_TRUE;
-         *ptr = obj;
-      }
+      obj->RefCount++;
+      obj->EverBound = GL_TRUE;
+      *ptr = obj;
    }
 }
 
 
 /**
  * Check that all the buffer objects currently bound for transform
  * feedback actually exist.  Raise a GL_INVALID_OPERATION error if
  * any buffers are missing.
  * \return GL_TRUE for success, GL_FALSE if error
  */
-- 
2.9.3



More information about the mesa-dev mailing list