i965: Use atomic ops in get_new_program_id().
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 21 Sep 2017 20:45:27 +0000 (13:45 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 25 Sep 2017 22:15:09 +0000 (15:15 -0700)
We have a nice utility function for this, which eliminates the need for
locking stuff.  This isn't really performance critical, but it's less
code to use the atomic.

p_atomic_inc_return does pre-increment rather than post-increment, so we
change screen->program_id to be initialized to 0 instead of 1.  At which
point, we can just delete the initialization because intel_screen is
rzalloc'd.

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
src/mesa/drivers/dri/i965/brw_program.c
src/mesa/drivers/dri/i965/intel_screen.c

index 9303dc85b9e5fea4f75c9784fc669922daad581b..fa0ce838fa06943ed6ff8ddbda3e8f91b2bdcd58 100644 (file)
@@ -127,11 +127,7 @@ brw_create_nir(struct brw_context *brw,
 static unsigned
 get_new_program_id(struct intel_screen *screen)
 {
-   static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
-   pthread_mutex_lock(&m);
-   unsigned id = screen->program_id++;
-   pthread_mutex_unlock(&m);
-   return id;
+   return p_atomic_inc_return(&screen->program_id);
 }
 
 static struct gl_program *brwNewProgram(struct gl_context *ctx, GLenum target,
index bc2bba00b6a52e5ae3d9e62238ab79dcf99ce037..bd1365f232b9d6353be6ee39aa697abce68228ef 100644 (file)
@@ -2510,7 +2510,6 @@ __DRIconfig **intelInitScreen2(__DRIscreen *dri_screen)
    screen->compiler->shader_debug_log = shader_debug_log_mesa;
    screen->compiler->shader_perf_log = shader_perf_log_mesa;
    screen->compiler->constant_buffer_0_is_relative = devinfo->gen < 8;
-   screen->program_id = 1;
 
    screen->has_exec_fence =
      intel_get_boolean(screen, I915_PARAM_HAS_EXEC_FENCE);