aboutsummaryrefslogtreecommitdiffstats
path: root/src/signal.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-11-30 23:22:40 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-11-30 23:22:40 +0100
commit02ce67294cd28bde9d61924fe6d0365638cc924e (patch)
treea30445a4e15e6ab651525e9dd40ba6399e00d1d8 /src/signal.go
parentFixed typos (diff)
downloadwireguard-go-02ce67294cd28bde9d61924fe6d0365638cc924e.tar.xz
wireguard-go-02ce67294cd28bde9d61924fe6d0365638cc924e.zip
Refactor timers.go
Diffstat (limited to '')
-rw-r--r--src/signal.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/signal.go b/src/signal.go
new file mode 100644
index 0000000..96b21bb
--- /dev/null
+++ b/src/signal.go
@@ -0,0 +1,45 @@
+package main
+
+type Signal struct {
+ enabled AtomicBool
+ C chan struct{}
+}
+
+func NewSignal() (s Signal) {
+ s.C = make(chan struct{}, 1)
+ s.Enable()
+ return
+}
+
+func (s *Signal) Disable() {
+ s.enabled.Set(false)
+ s.Clear()
+}
+
+func (s *Signal) Enable() {
+ s.enabled.Set(true)
+}
+
+func (s *Signal) Send() {
+ if s.enabled.Get() {
+ select {
+ case s.C <- struct{}{}:
+ default:
+ }
+ }
+}
+
+func (s Signal) Clear() {
+ select {
+ case <-s.C:
+ default:
+ }
+}
+
+func (s Signal) Broadcast() {
+ close(s.C) // unblocks all selectors
+}
+
+func (s Signal) Wait() chan struct{} {
+ return s.C
+}