| 8 | |
| 9 | {{{ |
| 10 | |
| 11 | inline static int GC_test_and_set(volatile unsigned int *addr) { |
| 12 | int oldval; |
| 13 | int temp = 1; /* locked value */ |
| 14 | |
| 15 | __asm__ __volatile__( |
| 16 | "1:\tlwarx %0,0,%3\n" /* load and reserve */ |
| 17 | "\tcmpwi %0, 0\n" /* if load is */ |
| 18 | "\tbne 2f\n" /* non-zero, return already set */ |
| 19 | "\tstwcx. %2,0,%1\n" /* else store conditional */ |
| 20 | "\tbne- 1b\n" /* retry if lost reservation */ |
| 21 | "\tsync\n" /* import barrier */ |
| 22 | "2:\t\n" /* oldval is zero if we set */ |
| 23 | : "=&r"(oldval), "=p"(addr) |
| 24 | : "r"(temp), "1"(addr) |
| 25 | : "cr0","memory"); |
| 26 | return oldval; |
| 27 | } |
| 28 | }}} |