[COMMITTED] PowerPC: Fix build due missing lll_robust_trylock
Commit Message
On 10-07-2014 18:54, Adhemerval Zanella wrote:
> Commit 887865f remove the lll_robust_trylock definition on all
> architectures, however for powerpc both __lll_trylock and
> __lll_cond_trylock were based on lll_robust_trylock definition.
> It breaks powerpc build with a missing lll_robust_trylock due:
>
> --
>
> In file included from ../include/errno.h:27:0,
> from ../sysdeps/pthread/ftrylockfile.c:19:
> ../sysdeps/pthread/ftrylockfile.c: In function ‘__ftrylockfile’:
> ../sysdeps/powerpc/nptl/tls.h:93:45: warning: implicit declaration of function ‘__lll_robust_trylock’ [-Wimplicit-function-declaration]
> # define TLS_TCB_ALIGN __alignof__ (struct pthread)
> ^
> ../sysdeps/powerpc/nptl/tls.h:98:52: note: in expansion of macro ‘TLS_TCB_ALIGN’
> + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
> ^
> ../sysdeps/powerpc/nptl/tls.h:146:24: note: in expansion of macro ‘TLS_PRE_TCB_SIZE’
> - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
> ^
> ../sysdeps/nptl/bits/stdio-lock.h:53:20: note: in expansion of macro ‘THREAD_SELF’
> void *__self = THREAD_SELF; \
> ^
> ../sysdeps/pthread/ftrylockfile.c:29:10: note: in expansion of macro ‘_IO_lock_trylock’
> return _IO_lock_trylock (*stream->_lock);
>
> --
>
> This patch restore it with a different name.
>
> Checked on powerpc64be and powerpc64le. I would advise architecture maintainers
> to check build on other arches as well.
>
>
And I forgot to add the contents...
--
* sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (__lll_base_trylock):
New define.
(__lll_trylock): Use __lll_base_trylock.
(__lll_cond_trylock): Likewise.
---
Comments
Sorry about that! I should have caught the other use of the macro.
@@ -190,13 +190,28 @@
# endif
#endif
+/* Set *futex to ID if it is 0, atomically. Returns the old value */
+#define __lll_base_trylock(futex, id) \
+ ({ int __val; \
+ __asm __volatile ("1: lwarx %0,0,%2" MUTEX_HINT_ACQ "\n" \
+ " cmpwi 0,%0,0\n" \
+ " bne 2f\n" \
+ " stwcx. %3,0,%2\n" \
+ " bne- 1b\n" \
+ "2: " __lll_acq_instr \
+ : "=&r" (__val), "=m" (*futex) \
+ : "r" (futex), "r" (id), "m" (*futex) \
+ : "cr0", "memory"); \
+ __val; \
+ })
+
/* Set *futex to 1 if it is 0, atomically. Returns the old value */
-#define __lll_trylock(futex) __lll_robust_trylock (futex, 1)
+#define __lll_trylock(futex) __lll_base_trylock (futex, 1)
#define lll_trylock(lock) __lll_trylock (&(lock))
/* Set *futex to 2 if it is 0, atomically. Returns the old value */
-#define __lll_cond_trylock(futex) __lll_robust_trylock (futex, 2)
+#define __lll_cond_trylock(futex) __lll_base_trylock (futex, 2)
#define lll_cond_trylock(lock) __lll_cond_trylock (&(lock))