atomicbool.go 512 B

12345678910111213141516171819202122232425262728293031
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package webrtc
  4. import "sync/atomic"
  5. type atomicBool struct {
  6. val int32
  7. }
  8. func (b *atomicBool) set(value bool) { // nolint: unparam
  9. var i int32
  10. if value {
  11. i = 1
  12. }
  13. atomic.StoreInt32(&(b.val), i)
  14. }
  15. func (b *atomicBool) get() bool {
  16. return atomic.LoadInt32(&(b.val)) != 0
  17. }
  18. func (b *atomicBool) swap(value bool) bool {
  19. var i int32
  20. if value {
  21. i = 1
  22. }
  23. return atomic.SwapInt32(&(b.val), i) != 0
  24. }