ClearRelaxedTimeout removes relaxed timeouts, returning to normal timeout behavior. Uses atomic operations for lock-free access.
()
| 480 | // ClearRelaxedTimeout removes relaxed timeouts, returning to normal timeout behavior. |
| 481 | // Uses atomic operations for lock-free access. |
| 482 | func (cn *Conn) ClearRelaxedTimeout() { |
| 483 | // Atomically decrement counter and check if we should clear |
| 484 | newCount := cn.relaxedCounter.Add(-1) |
| 485 | deadlineNs := cn.relaxedDeadlineNs.Load() |
| 486 | if newCount <= 0 && (deadlineNs == 0 || time.Now().UnixNano() >= deadlineNs) { |
| 487 | // Use atomic load to get current value for CAS to avoid stale value race |
| 488 | current := cn.relaxedCounter.Load() |
| 489 | if current <= 0 && cn.relaxedCounter.CompareAndSwap(current, 0) { |
| 490 | cn.clearRelaxedTimeout() |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | func (cn *Conn) clearRelaxedTimeout() { |
| 496 | cn.relaxedReadTimeoutNs.Store(0) |