mesa/main: use p_atomic_inc_return instead of locking
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Fri, 10 Jul 2020 11:12:40 +0000 (13:12 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 16 Jul 2020 10:49:22 +0000 (10:49 +0000)
There's no good reason for using a mutex here, as we have a simpler
primitive; atomic integers. So let's use that instead, to simplify
things a bit.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5901>

src/mesa/main/debug_output.c

index 6d4c8e72ee3648e9e3b5ad20d8fc819dc3acd515..6527aea577182dbecf343160f8c93e2200ad59b0 100644 (file)
@@ -37,8 +37,7 @@
 #include "util/u_memory.h"
 
 
-static simple_mtx_t DynamicIDMutex = _SIMPLE_MTX_INITIALIZER_NP;
-static GLuint NextDynamicID = 1;
+static GLuint PrevDynamicID = 0;
 
 
 /**
@@ -194,10 +193,7 @@ void
 _mesa_debug_get_id(GLuint *id)
 {
    if (!(*id)) {
-      simple_mtx_lock(&DynamicIDMutex);
-      if (!(*id))
-         *id = NextDynamicID++;
-      simple_mtx_unlock(&DynamicIDMutex);
+      *id = p_atomic_inc_return(&PrevDynamicID);
    }
 }