atomicbool.go 410 B

12345678910111213141516171819202122232425262728
  1. package webrtc
  2. import "sync/atomic"
  3. type atomicBool struct {
  4. val int32
  5. }
  6. func (b *atomicBool) set(value bool) { // nolint: unparam
  7. var i int32
  8. if value {
  9. i = 1
  10. }
  11. atomic.StoreInt32(&(b.val), i)
  12. }
  13. func (b *atomicBool) get() bool {
  14. return atomic.LoadInt32(&(b.val)) != 0
  15. }
  16. func (b *atomicBool) swap(value bool) bool {
  17. var i int32
  18. if value {
  19. i = 1
  20. }
  21. return atomic.SwapInt32(&(b.val), i) != 0
  22. }