[ported from trunk r15949, adjusted to apply to linux-atomic.c in config/m68k/ ] Subject: [PATCH] ARM: fix __sync_lock_release for linux From: Richard Earnshaw Date: Thu, 03 Dec 2009 14:28:43 +0000 List-Archive: List-Post: When releasing a lock the key memory barrier is there to protect the writes that occur earlier from being seen after the release of the lock itself. In order to do that the dmb instruction needs to appear before the unlock write not after it. gcc/ 2009-12-03 Richard Earnshaw * arm/linux-atomic.c (SYNC_LOCK_RELEASE): Place memory barrier before the lock release. --- gcc-4.6.3/gcc/config/m68k/linux-atomic.c.~1~ 2012-06-18 22:05:40.000000000 +0200 +++ gcc-4.6.3/gcc/config/m68k/linux-atomic.c 2012-06-18 22:08:45.000000000 +0200 @@ -271,8 +271,10 @@ SUBWORD_TEST_AND_SET (char, 1) void HIDDEN \ __sync_lock_release_##WIDTH (TYPE *ptr) \ { \ - *ptr = 0; \ + /* All writes before this point must be seen before we release \ + the lock itself. */ \ __kernel_dmb (); \ + *ptr = 0; \ } SYNC_LOCK_RELEASE (int, 4)