dec_and_lock.c 874 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #include <linux/export.h>
  10. asm (".text \n\
  11. .global _atomic_dec_and_lock \n\
  12. .ent _atomic_dec_and_lock \n\
  13. .align 4 \n\
  14. _atomic_dec_and_lock: \n\
  15. .prologue 0 \n\
  16. 1: ldl_l $1, 0($16) \n\
  17. subl $1, 1, $1 \n\
  18. beq $1, 2f \n\
  19. stl_c $1, 0($16) \n\
  20. beq $1, 4f \n\
  21. mb \n\
  22. clr $0 \n\
  23. ret \n\
  24. 2: br $29, 3f \n\
  25. 3: ldgp $29, 0($29) \n\
  26. br $atomic_dec_and_lock_1..ng \n\
  27. .subsection 2 \n\
  28. 4: br 1b \n\
  29. .previous \n\
  30. .end _atomic_dec_and_lock");
  31. static int __used atomic_dec_and_lock_1(atomic_t *atomic, spinlock_t *lock)
  32. {
  33. /* Slow path */
  34. spin_lock(lock);
  35. if (atomic_dec_and_test(atomic))
  36. return 1;
  37. spin_unlock(lock);
  38. return 0;
  39. }
  40. EXPORT_SYMBOL(_atomic_dec_and_lock);