summaryrefslogtreecommitdiffhomepage
path: root/src/misc.go
blob: 75561b2ff63db82b19710eb585d11408d5644bf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main

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
	}
	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
}