ainc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. .TH AINC 2
  2. .SH NAME
  3. ainc, adec, cas32, cas, casp, casl, cas64, mfence \- atomic operations
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .nf
  10. .B
  11. int ainc(long *p)
  12. .PP
  13. .B
  14. int adec(long *p)
  15. .PP
  16. .B
  17. int cas(uint *p, int ov, int nv)
  18. .PP
  19. .B
  20. int casp(void **p, void *ov, void *nv)
  21. .PP
  22. .B
  23. int casl(ulong *p, ulong ov, ulong nv)
  24. .PP
  25. .B
  26. int cas32(u32int *p, u32int ov, u32int nv)
  27. .PP
  28. .B
  29. int cas64(u64int *p, u64int ov, u64int nv)
  30. .PP
  31. .B
  32. void mfence(void)
  33. .SH DESCRIPTION
  34. These functions provide access to atomic operations, useful for
  35. synchronization.
  36. .PP
  37. .I Ainc
  38. and
  39. .I adec
  40. atomically
  41. increment and decrement (respectively) the integer pointed to by
  42. .IR p ,
  43. and return the resulting value after the operation.
  44. .PP
  45. .I Cas
  46. performs a compare and swap on the word pointed to by
  47. .IR p ,
  48. provided that the value is still
  49. .I ov
  50. (the old value), so that the new value is
  51. .IR nv .
  52. Functions
  53. .IR cas32 ,
  54. .IR cas64 ,
  55. .IR casp ,
  56. and
  57. .I casul
  58. do the same for 32-bit values, 64-bit values, pointers, and unsigned long
  59. integers.
  60. .PP
  61. .I Mfence
  62. sets a memory fence so that all outstanding memory operations are performed
  63. before returning from it.
  64. .SH SOURCE
  65. .B /sys/src/libc/386/atom.s
  66. .br
  67. .B /sys/src/libc/amd64/atom.s
  68. .SH SEE ALSO
  69. .IR incref (2).
  70. .SH BUGS
  71. Some of them may not be implemented for some architectures.