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.
26 lines
604 B
26 lines
604 B
package syncx |
|
|
|
import ( |
|
"sync/atomic" |
|
"time" |
|
) |
|
|
|
type AtomicDuration int64 |
|
|
|
func NewAtomicDuration() *AtomicDuration { |
|
return new(AtomicDuration) |
|
} |
|
func ForAtomicDuration(val time.Duration) *AtomicDuration { |
|
d := NewAtomicDuration() |
|
d.Set(val) |
|
return d |
|
} |
|
func (d *AtomicDuration) CompareAndSwap(old, val time.Duration) bool { |
|
return atomic.CompareAndSwapInt64((*int64)(d), int64(old), int64(val)) |
|
} |
|
func (d *AtomicDuration) Load() time.Duration { |
|
return time.Duration(atomic.LoadInt64((*int64)(d))) |
|
} |
|
func (d *AtomicDuration) Set(val time.Duration) { |
|
atomic.StoreInt64((*int64)(d), int64(val)) |
|
}
|
|
|