Commit 2a16d3d
authored
Use one allocation for the bespoke
We currently use two allocations to store the contents of our bespoke
Apple-only `Mutex` reimplementation: one for the `os_unfair_lock` and
the other for the stored value. We can instead use a single allocation
with a bit of careful pointer arithmetic to ensure there's enough
storage for both and that it's well-aligned.
This change has the effect of reducing the size of `Mutex` by a word. It
also reduces the amount of memory allocated by some vague amount because
on Darwin, the minimum allocation size is 16 but the size of
`os_unfair_lock` is 4. I place the lock _after_ the value because its
alignment will often be smaller, so fewer padding bytes will be needed
between the value and the lock than between the lock and the value.
At compile time in release mode, all specializations are known and the
extra math is optimized away.
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.Mutex's storage. (#1584)1 parent 5eb07e9 commit 2a16d3d
1 file changed
Lines changed: 23 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
43 | 52 | | |
44 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
45 | 56 | | |
46 | 57 | | |
47 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
48 | 68 | | |
49 | | - | |
50 | | - | |
51 | 69 | | |
52 | 70 | | |
53 | 71 | | |
54 | 72 | | |
55 | 73 | | |
56 | | - | |
57 | 74 | | |
58 | 75 | | |
59 | 76 | | |
60 | 77 | | |
61 | 78 | | |
62 | | - | |
63 | 79 | | |
64 | 80 | | |
65 | 81 | | |
66 | 82 | | |
67 | 83 | | |
68 | | - | |
| 84 | + | |
69 | 85 | | |
70 | 86 | | |
71 | 87 | | |
| |||
0 commit comments