atom 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. .TH ATOM 2
  2. .SH NAME
  3. ainc, adec, cas, cas32, cas64, casp, casl, loadlink, storecond, tas \- atomic RMW operations
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .B
  10. long ainc(long *addr);
  11. .PP
  12. .B
  13. long adec(long *addr);
  14. .PP
  15. .B
  16. int cas32(u32int *addr, u32int ov, u32int nv);
  17. .PP
  18. .B
  19. int cas64(u64int *addr, u64int ov, u64int nv);
  20. .PP
  21. .B
  22. int cas(int *addr, int ov, int nv);
  23. .PP
  24. .B
  25. int casp(void **addr, void *ov, void *nv);
  26. .PP
  27. .B
  28. int casl(ulong *addr, ulong ov, ulong nv);
  29. .PP
  30. .B
  31. int tas(ulong *addr);
  32. .PP
  33. .B
  34. ulong loadlink(ulong*);
  35. .PP
  36. .B
  37. int storecond(ulong*, ulong);
  38. .SH DESCRIPTION
  39. .I Ainc
  40. atomically increments the value pointed to by
  41. .I addr
  42. and returns the new value.
  43. .PP
  44. .I Adec
  45. atomically decrements the value pointed to by
  46. .I addr
  47. and returns the new value.
  48. .PP
  49. .IR Cas ,
  50. .IR cas32 ,
  51. .IR cas64 ,
  52. .IR casp ,
  53. and
  54. .I casl
  55. implement
  56. .I Compare-and-Swap
  57. on, respectively,
  58. .IR int ,
  59. .IR u32int ,
  60. .IR u64int ,
  61. .IR void* ,
  62. and
  63. .IR ulong
  64. values. The availability of these functions depends on the
  65. \s-2CPU\s0 architecture: Pentium III and later, as well as AMD64
  66. have 64-bit CAS instructions. Other architectures don't.
  67. ARM-5 processors and earlier do not have CAS (nor have they
  68. .I Load-Linked
  69. or
  70. .I Store-Conditional ).
  71. These instructions are, however, emulated by the Plan 9 kernel.
  72. All other architectures have 32-bit CAS.
  73. .PP
  74. .I Tas
  75. implements
  76. .IR Test-and-Set ,
  77. which is available on all architectures and used for the implementation
  78. of kernel locks
  79. (see
  80. .IR lock (2)
  81. and
  82. .IR thread (2)).
  83. .PP
  84. .I Loadlink
  85. and
  86. .I Storecond
  87. access the
  88. .I load-linked
  89. and
  90. .I store-conditional
  91. instructions present on MIPS (LL/SC), ARM (Strex/Ldrex), PowerPC (LWAR/STWCCC), Alpha (MOVLL, MOVLC).
  92. These are not present on Pentium or AMD64.
  93. .PP
  94. On the architectures that have
  95. .I load-linked
  96. and
  97. .IR store-conditional ,
  98. these are used to implement
  99. .IR compare-and-swap .
  100. .SH SOURCE
  101. .B /sys/src/libc/*/atom.s
  102. .br
  103. .B /sys/src/libc/*/tas.s
  104. .SH SEE ALSO
  105. .IR semacquire (2),
  106. .IR lock (2),
  107. .IR thread (2)
  108. .SH DIAGNOSTICS
  109. The CAS functions,
  110. .IR tas ,
  111. and
  112. .I storecond
  113. return 0 for failure and 1 for success.