diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-07 22:27:03 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-10 16:08:03 +0200 |
commit | 233f079a9479279d2aab68f4accb139ee87ad664 (patch) | |
tree | 338dfb681ffafbb53b81d353aa5612866ff935f5 /event.go | |
parent | 375dcbd4aefc8054700dcb072a5e74a9ed7e9d39 (diff) | |
download | wireguard-go-233f079a9479279d2aab68f4accb139ee87ad664.tar.gz wireguard-go-233f079a9479279d2aab68f4accb139ee87ad664.zip |
Rewrite timers and related state machines
Diffstat (limited to 'event.go')
-rw-r--r-- | event.go | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/event.go b/event.go deleted file mode 100644 index 6235ba4..0000000 --- a/event.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "sync/atomic" - "time" -) - -type Event struct { - guard int32 - next time.Time - interval time.Duration - C chan struct{} -} - -func newEvent(interval time.Duration) *Event { - return &Event{ - guard: 0, - next: time.Now(), - interval: interval, - C: make(chan struct{}, 1), - } -} - -func (e *Event) Clear() { - select { - case <-e.C: - default: - } -} - -func (e *Event) Fire() { - if e == nil || atomic.SwapInt32(&e.guard, 1) != 0 { - return - } - if now := time.Now(); now.After(e.next) { - select { - case e.C <- struct{}{}: - default: - } - e.next = now.Add(e.interval) - } - atomic.StoreInt32(&e.guard, 0) -} |