__sync_lock_test_and_set on ARM
Andrew Haley
aph-gcc@littlepinkcloud.COM
Thu Sep 13 12:05:00 GMT 2007
Segher Boessenkool writes:
> As an aside...
>
> > #define __KERNEL__
> > #include <asm/atomic.h>
>
> You don't want to do this, the stuff in the header files bracketed
> with __KERNEL__ is for internal use in the Linux kernel only; with
> newer kernel versions, that stuff isn't copied into the user headers
> anymore even.
How annoying.
> You can of course copy that code into your own code, or perhaps
> glibc has similar functionality somewhere?
Well, this stuff really should be done by the compiler. There is a
useful way to do compare and exchange that doesn't require knowledge
of hardware:
--------------------------------------------------------------------
typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
int n = 99;
int
main (void)
{
__kernel_cmpxchg (99, 33, &n);
return 0;
}
--------------------------------------------------------------------
This works on sufficiently recent ARM kernels, and on all ARM
hardware.
Andrew.
http://developer.osdl.org/dev/robustmutexes/REPOS/fusyn.hg/?cmd=file;filenode=3d1fa6de979c9ad079f9a103bf332d120dabe838;file=arch/arm/kernel/entry-armv.S
More information about the Gcc-help
mailing list