rtt.go 548 B

123456789101112131415161718192021222324252627282930
  1. package h2mux
  2. import (
  3. "sync/atomic"
  4. )
  5. // PingTimestamp is an atomic interface around ping timestamping and signalling.
  6. type PingTimestamp struct {
  7. ts int64
  8. signal Signal
  9. }
  10. func NewPingTimestamp() *PingTimestamp {
  11. return &PingTimestamp{signal: NewSignal()}
  12. }
  13. func (pt *PingTimestamp) Set(v int64) {
  14. if atomic.SwapInt64(&pt.ts, v) != 0 {
  15. pt.signal.Signal()
  16. }
  17. }
  18. func (pt *PingTimestamp) Get() int64 {
  19. return atomic.SwapInt64(&pt.ts, 0)
  20. }
  21. func (pt *PingTimestamp) GetUpdateChan() <-chan struct{} {
  22. return pt.signal.WaitChannel()
  23. }