util: Add helgrind support for simple_mtx

Annoyingly mtypes.h pulls in simple_mtx, which means we end up needing
to sprinkle a lot of idep_mesautil around.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3773
Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7644>
This commit is contained in:
Rob Clark
2020-11-17 11:29:52 -08:00
committed by Marge Bot
parent 7f223a2329
commit 53f7d539cd
44 changed files with 81 additions and 35 deletions
+3 -1
View File
@@ -53,7 +53,9 @@ libmesa_format = static_library(
'mesa_format',
[files_mesa_format, u_format_table_c, u_format_pack_h],
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
dependencies : dep_m,
# NOTE dep_valgrind used here instead of idep_mesautil due to chicken/egg
# dependencies between util and util/format
dependencies : [dep_m, dep_valgrind],
c_args : [c_msvc_compat_args],
gnu_symbol_visibility : 'hidden',
build_by_default : false
+1 -1
View File
@@ -196,7 +196,7 @@ _libmesa_util = static_library(
idep_mesautil = declare_dependency(
link_with : _libmesa_util,
include_directories : inc_util,
dependencies : [dep_zlib, dep_clock, dep_thread, dep_atomic, dep_m],
dependencies : [dep_zlib, dep_clock, dep_thread, dep_atomic, dep_m, dep_valgrind],
)
xmlconfig_deps = []
+15
View File
@@ -31,6 +31,14 @@
#if UTIL_FUTEX_SUPPORTED
#if defined(HAVE_VALGRIND) && !defined(NDEBUG)
# include <valgrind.h>
# include <helgrind.h>
# define HG(x) x
#else
# define HG(x)
#endif
/* mtx_t - Fast, simple mutex
*
* While modern pthread mutexes are very fast (implemented using futex), they
@@ -69,11 +77,14 @@ simple_mtx_init(simple_mtx_t *mtx, ASSERTED int type)
assert(type == mtx_plain);
mtx->val = 0;
HG(ANNOTATE_RWLOCK_CREATE(mtx));
}
static inline void
simple_mtx_destroy(ASSERTED simple_mtx_t *mtx)
{
HG(ANNOTATE_RWLOCK_DESTROY(mtx));
#ifndef NDEBUG
mtx->val = _SIMPLE_MTX_INVALID_VALUE;
#endif
@@ -96,6 +107,8 @@ simple_mtx_lock(simple_mtx_t *mtx)
c = __sync_lock_test_and_set(&mtx->val, 2);
}
}
HG(ANNOTATE_RWLOCK_ACQUIRED(mtx, 1));
}
static inline void
@@ -103,6 +116,8 @@ simple_mtx_unlock(simple_mtx_t *mtx)
{
uint32_t c;
HG(ANNOTATE_RWLOCK_RELEASED(mtx, 1));
c = __sync_fetch_and_sub(&mtx->val, 1);
assert(c != _SIMPLE_MTX_INVALID_VALUE);