(latch: *const Latch, error: bool)
| 139 | /// establishes a happens-after relationship. Stores on this thread made |
| 140 | /// before this call will be visible to the owning thread after `check` |
| 141 | /// returns a status other than `Pending`. |
| 142 | /// |
| 143 | /// # Safety |
| 144 | /// |
| 145 | /// The caller must ensure that: |
| 146 | /// |
| 147 | /// * `latch` is a non-null, aligned pointer to an initialized `Latch`. |
| 148 | /// |
| 149 | /// * Additionally, one of the following condition variants must be met: |
| 150 | /// |
| 151 | /// 1. The latch will not be dropped or moved for the duration of `set`. |
| 152 | /// |
| 153 | /// 2. The latch has not been `set` since it was created or last `reset`, |
| 154 | /// calls to `set` do not race, and the latch will not be dropped or |
| 155 | /// moved until after `check` returns a status other than `Pending`. |
| 156 | #[inline(always)] |
| 157 | pub unsafe fn set(latch: *const Latch, error: bool) { |
| 158 | // First we store a reference to the semaphore (which is 'static) so |
| 159 | // that we can access it even if the latch pointer becomes dangling. |
| 160 | // |
| 161 | // SAFETY: The caller guarantees the latch pointer is aligned and |
| 162 | // non-null. |
| 163 | // |
| 164 | // If Variant 1 is met, the latch cannot be dangling. |
| 165 | // |
| 166 | // If Variant 2 is met, the latch cannot become dangling so long as the |
| 167 | // state is `LOCKED` (because `check` will return `Pending`). Since |
| 168 | // there can have been no previous call to `set` since construction or |
| 169 | // the last `reset`, and there can be no racing calls to `set`, the |
| 170 | // state must be `LOCKED`. Therefore the latch cannot be dangling. |
| 171 | // |
| 172 | // Since this pointer is aligned, non-null, is not dangling, and the |
| 173 | // latch is never accessed mutably, it is valid to access immutably. |
| 174 | let semaphore = unsafe { (*latch).semaphore }; |
| 175 | // Determine the next state for the latch. |
| 176 | let state = if error { ERROR } else { SIGNAL }; |
| 177 | // Next we update the state. |
| 178 | // |
| 179 | // In the event of a race with `wait`, this may cause `wait` to return. |
| 180 | // Otherwise the other thread will sleep within `wait`. |
no test coverage detected