From 0f5a88d53ba02137b72a6fccfdaeaadd1f908d2f Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 3 Nov 2017 21:30:23 +0300 Subject: [PATCH] Fix double lock in a_set(f(a_get())) expression in gctest (fix commit 8f5746e) * tests/test.c [!AO_HAVE_store_release] (AO_store_release): Replace macro with a static function definition (so, new_val argument is evaluated before acquiring the lock). --- tests/test.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test.c b/tests/test.c index 3a208f89..453bfe73 100644 --- a/tests/test.c +++ b/tests/test.c @@ -187,8 +187,13 @@ } #endif #ifndef AO_HAVE_store_release -# define AO_store_release(p, v) \ - (void)(FINALIZER_LOCK(), *(p) = (v), FINALIZER_UNLOCK(), 0) + /* Not a macro as new_val argument should be evaluated before the lock. */ + static void AO_store_release(volatile AO_t *addr, AO_t new_val) + { + FINALIZER_LOCK(); + *addr = new_val; + FINALIZER_UNLOCK(); + } #endif #ifndef AO_HAVE_fetch_and_add1 # define AO_fetch_and_add1(p) ((*(p))++) -- 2.40.0