From eaca1ee1f79422a501394415fd4ae8f227a134af Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Fri, 1 Dec 2017 23:37:26 +0100 Subject: More consistent use of signal struct --- src/misc.go | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) (limited to 'src/misc.go') diff --git a/src/misc.go b/src/misc.go index b43e97e..80e33f6 100644 --- a/src/misc.go +++ b/src/misc.go @@ -2,12 +2,10 @@ package main import ( "sync/atomic" - "time" ) -/* We use int32 as atomic bools - * (since booleans are not natively supported by sync/atomic) - */ +/* Atomic Boolean */ + const ( AtomicFalse = int32(iota) AtomicTrue @@ -37,6 +35,8 @@ func (a *AtomicBool) Set(val bool) { atomic.StoreInt32(&a.flag, flag) } +/* Integer manipulation */ + func toInt32(n uint32) int32 { mask := uint32(1 << 31) return int32(-(n & mask) + (n & ^mask)) @@ -55,32 +55,3 @@ func minUint64(a uint64, b uint64) uint64 { } return a } - -func signalSend(c chan struct{}) { - select { - case c <- struct{}{}: - default: - } -} - -func signalClear(c chan struct{}) { - select { - case <-c: - default: - } -} - -func timerStop(timer *time.Timer) { - if !timer.Stop() { - select { - case <-timer.C: - default: - } - } -} - -func NewStoppedTimer() *time.Timer { - timer := time.NewTimer(time.Hour) - timerStop(timer) - return timer -} -- cgit v1.2.3