Optimistic concurrency control approach to snapshot the value of another thread's TLS, even though that thread might be changing it. Called by the watchdog thread to see if a target thread is currently in the middle of a watched section.
| 234 | // Called by the watchdog thread to see if a target thread is currently in the |
| 235 | // middle of a watched section. |
| 236 | void KernelStackWatchdog::TLS::Data::SnapshotCopy(Data* copy) const { |
| 237 | while (true) { |
| 238 | Atomic32 v_0 = base::subtle::Acquire_Load(&seq_lock_); |
| 239 | if (v_0 & 1) { |
| 240 | // If the value is odd, then the thread is in the middle of modifying |
| 241 | // its TLS, and we have to spin. |
| 242 | base::subtle::PauseCPU(); |
| 243 | continue; |
| 244 | } |
| 245 | ANNOTATE_IGNORE_READS_BEGIN(); |
| 246 | memcpy(copy, this, sizeof(*copy)); |
| 247 | ANNOTATE_IGNORE_READS_END(); |
| 248 | Atomic32 v_1 = base::subtle::Release_Load(&seq_lock_); |
| 249 | |
| 250 | // If the value hasn't changed since we started the copy, then |
| 251 | // we know that the copy was a consistent snapshot. |
| 252 | if (v_1 == v_0) break; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | } // namespace kudu |
no test coverage detected