mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
369 B
30 lines
369 B
package signal
|
|
|
|
import (
|
|
"sync"
|
|
"sync/atomic"
|
|
)
|
|
|
|
type Once struct {
|
|
m sync.Mutex
|
|
done uint32
|
|
}
|
|
|
|
func (o *Once) Do(f func()) {
|
|
if atomic.LoadUint32(&o.done) == 1 {
|
|
return
|
|
}
|
|
o.m.Lock()
|
|
defer o.m.Unlock()
|
|
if o.done == 0 {
|
|
atomic.StoreUint32(&o.done, 1)
|
|
f()
|
|
}
|
|
}
|
|
|
|
func (o *Once) Reset() {
|
|
o.m.Lock()
|
|
defer o.m.Unlock()
|
|
atomic.StoreUint32(&o.done, 0)
|
|
}
|