aboutsummaryrefslogtreecommitdiffstats
path: root/src/misc.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-07-08 23:51:26 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-07-08 23:51:26 +0200
commit4ad62aaa6aa269f08c0fdc9c139e6d5417e21746 (patch)
tree2105f65bc61b0fb842ac44c11a81150a8bb9a909 /src/misc.go
parentAdded source verification (diff)
downloadwireguard-go-4ad62aaa6aa269f08c0fdc9c139e6d5417e21746.tar.xz
wireguard-go-4ad62aaa6aa269f08c0fdc9c139e6d5417e21746.zip
Improved timer state machine
Diffstat (limited to 'src/misc.go')
-rw-r--r--src/misc.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/misc.go b/src/misc.go
index dd4fa63..75561b2 100644
--- a/src/misc.go
+++ b/src/misc.go
@@ -4,6 +4,14 @@ import (
"time"
)
+/* We use int32 as atomic bools
+ * (since booleans are not natively supported by sync/atomic)
+ */
+const (
+ AtomicFalse = iota
+ AtomicTrue
+)
+
func min(a uint, b uint) uint {
if a > b {
return b
@@ -11,14 +19,21 @@ func min(a uint, b uint) uint {
return a
}
-func sendSignal(c chan struct{}) {
+func signalSend(c chan struct{}) {
select {
case c <- struct{}{}:
default:
}
}
-func stopTimer(timer *time.Timer) {
+func signalClear(c chan struct{}) {
+ select {
+ case <-c:
+ default:
+ }
+}
+
+func timerStop(timer *time.Timer) {
if !timer.Stop() {
select {
case <-timer.C:
@@ -27,8 +42,8 @@ func stopTimer(timer *time.Timer) {
}
}
-func stoppedTimer() *time.Timer {
+func NewStoppedTimer() *time.Timer {
timer := time.NewTimer(time.Hour)
- stopTimer(timer)
+ timerStop(timer)
return timer
}