1
0
mirror of https://git.zx2c4.com/wireguard-go synced 2024-11-15 01:05:15 +01:00
wireguard-go/misc.go

49 lines
692 B
Go
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0
*
2018-09-05 23:54:31 +02:00
* Copyright (C) 2017-2018 WireGuard LLC. All Rights Reserved.
*/
package main
2017-07-01 23:29:22 +02:00
import (
"sync/atomic"
2017-07-01 23:29:22 +02:00
)
2017-12-01 23:37:26 +01:00
/* Atomic Boolean */
2017-07-08 23:51:26 +02:00
const (
AtomicFalse = int32(iota)
2017-07-08 23:51:26 +02:00
AtomicTrue
)
type AtomicBool struct {
flag int32
}
func (a *AtomicBool) Get() bool {
return atomic.LoadInt32(&a.flag) == AtomicTrue
}
func (a *AtomicBool) Swap(val bool) bool {
flag := AtomicFalse
if val {
flag = AtomicTrue
}
return atomic.SwapInt32(&a.flag, flag) == AtomicTrue
}
func (a *AtomicBool) Set(val bool) {
flag := AtomicFalse
if val {
flag = AtomicTrue
}
atomic.StoreInt32(&a.flag, flag)
}
2018-05-14 00:28:30 +02:00
func min(a, b uint) uint {
if a > b {
return b
}
return a
}