Skip to content

Commit 3de4fe2

Browse files
authored
More documentation (#30)
1 parent 523ae27 commit 3de4fe2

File tree

3 files changed

+77
-13
lines changed

3 files changed

+77
-13
lines changed

docs/src/index.md

-11
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,3 @@ Atomix.@atomic
66
Atomix.@atomicswap
77
Atomix.@atomicreplace
88
```
9-
10-
## Customizations
11-
12-
```@docs
13-
Atomix.IndexableRef
14-
Atomix.get
15-
Atomix.set!
16-
Atomix.modify!
17-
Atomix.replace!
18-
Atomix.swap!
19-
```

docs/src/interface.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Low-level interfaces for customizations
2+
3+
```@docs
4+
Atomix.IndexableRef
5+
Atomix.get
6+
Atomix.set!
7+
Atomix.modify!
8+
Atomix.replace!
9+
Atomix.swap!
10+
```

src/generic.jl

+67-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
77
Atomically load the value `x` stored in `ref` with ordering `order`. The default ordering
88
`Atomix.sequentially_consistent` is used when not specified.
9+
10+
# Examples
11+
```jldoctest
12+
julia> using Atomix
13+
14+
julia> a = [111, 222, 333];
15+
16+
julia> ref = Atomix.IndexableRef(a, (1,));
17+
18+
julia> Atomix.get(ref)
19+
111
20+
```
921
"""
1022
Atomix.get
1123

@@ -15,6 +27,20 @@ Atomix.get
1527
1628
Atomically store the value `x` in `ref` with ordering `order`. The default ordering
1729
`Atomix.sequentially_consistent` is used when not specified.
30+
31+
# Examples
32+
```jldoctest
33+
julia> using Atomix
34+
35+
julia> a = [111, 222, 333];
36+
37+
julia> ref = Atomix.IndexableRef(a, (1,));
38+
39+
julia> Atomix.set!(ref, 123);
40+
41+
julia> a[1]
42+
123
43+
```
1844
"""
1945
Atomix.set!
2046

@@ -24,18 +50,45 @@ Atomix.set!
2450
2551
Atomically update `ref` from stored value `old` to `new = op(old, x)` with ordering `order`
2652
(default: `Atomix.sequentially_consistent`). Return a pair `old => new`.
53+
54+
# Examples
55+
```jldoctest
56+
julia> using Atomix
57+
58+
julia> a = [111, 222, 333];
59+
60+
julia> ref = Atomix.IndexableRef(a, (1,));
61+
62+
julia> Atomix.modify!(ref, +, 123)
63+
111 => 234
64+
```
2765
"""
2866
Atomix.modify!
2967

3068
"""
3169
Atomix.swap!(ref, new, order) -> old
3270
Atomix.swap!(ref, new) -> old
3371
34-
Swap the `new` value with the `old` stored in `ref` with ordering `order` (default:
35-
`Atomix.sequentially_consistent`).
72+
Swap the `old` stored in `ref` with the `new` value and establish the memory ordering
73+
`order` (default: `Atomix.sequentially_consistent`).
3674
3775
Notes for implementers: `Atomix.swap!(ref, new, order)` is defined as `Atomix.modify!(ref,
3876
Atomix.right, x, order)`. Thus, only `Atomix.modify!` has to be defined.
77+
78+
# Examples
79+
```jldoctest
80+
julia> using Atomix
81+
82+
julia> a = [111, 222, 333];
83+
84+
julia> ref = Atomix.IndexableRef(a, (1,));
85+
86+
julia> Atomix.swap!(ref, 123)
87+
111
88+
89+
julia> a[1]
90+
123
91+
```
3992
"""
4093
Atomix.swap!
4194

@@ -46,6 +99,18 @@ Atomix.swap!
4699
47100
Atomically replace the value stored in `ref` to `desired` if `expected` is stored. A named
48101
tuple `(; old::eltype(ref), success::Bool)` is returned.
102+
103+
# Examples
104+
```jldoctest
105+
julia> using Atomix
106+
107+
julia> a = [111, 222, 333];
108+
109+
julia> ref = Atomix.IndexableRef(a, (1,));
110+
111+
julia> Atomix.replace!(ref, 111, 123)
112+
(old = 111, success = true)
113+
```
49114
"""
50115
Atomix.replace!
51116

0 commit comments

Comments
 (0)