dec_and_lock.c 811 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * arch/alpha/lib/dec_and_lock.c
  3. *
  4. * ll/sc version of atomic_dec_and_lock()
  5. *
  6. */
  7. #include <linux/spinlock.h>
  8. #include <linux/atomic.h>
  9. asm (".text \n\
  10. .global _atomic_dec_and_lock \n\
  11. .ent _atomic_dec_and_lock \n\
  12. .align 4 \n\
  13. _atomic_dec_and_lock: \n\
  14. .prologue 0 \n\
  15. 1: ldl_l $1, 0($16) \n\
  16. subl $1, 1, $1 \n\
  17. beq $1, 2f \n\
  18. stl_c $1, 0($16) \n\
  19. beq $1, 4f \n\
  20. mb \n\
  21. clr $0 \n\
  22. ret \n\
  23. 2: br $29, 3f \n\
  24. 3: ldgp $29, 0($29) \n\
  25. br $atomic_dec_and_lock_1..ng \n\
  26. .subsection 2 \n\
  27. 4: br 1b \n\
  28. .previous \n\
  29. .end _atomic_dec_and_lock");
  30. static int __used atomic_dec_and_lock_1(atomic_t *atomic, spinlock_t *lock)
  31. {
  32. /* Slow path */
  33. spin_lock(lock);
  34. if (atomic_dec_and_test(atomic))
  35. return 1;
  36. spin_unlock(lock);
  37. return 0;
  38. }